Merge pull request 'updated mkinitramfs.img' (#1) from update-mkinitramfs into main
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/mkinitramfs/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
||||
mkinitramfs.pkg
|
||||
mkinitramfs.pkg.gz
|
||||
mkinitramfs.pkg.gz
|
||||
initramfs.img
|
||||
+91
-4
@@ -2,23 +2,110 @@
|
||||
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||
initdir=$(pwd)/initramfs
|
||||
INITIN="/usr/share/mkinitramfs/init.in"
|
||||
CONFIG="/etc/mkinitramfs.conf"
|
||||
|
||||
create_dirs() {
|
||||
mkdir -pv $initdir/{bin,dev,mnt,proc,root,sys,run}
|
||||
}
|
||||
|
||||
print_version() {
|
||||
echo "mkinitramfs - 0.0.1"
|
||||
}
|
||||
|
||||
usage() {
|
||||
print_version
|
||||
cat << EOF
|
||||
Usage: $(basename $0) [options] [arguments]
|
||||
|
||||
Options:
|
||||
-c, --config <config> use custom config (default: $CONFIG)
|
||||
-i, --init <init> - custom init file (default: $INITIN)
|
||||
-C, --compression <compression (gzip|xz|zstd|lz4|none|cat defaults to $INITRAMFSCOMP)>
|
||||
-v, --version - print mkinitramfs version
|
||||
-h, --help - print this help message
|
||||
EOF
|
||||
}
|
||||
|
||||
needarg() {
|
||||
if [ ! "$1" ]; then
|
||||
echo "ERROR: argument is needed for this option!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_compression() {
|
||||
complevel_gzip="${complevel_gzip:--9}"
|
||||
complevel_xz="${complevel_xz:--9}"
|
||||
complevel_zstd="${complevel_zstd:--19}"
|
||||
complevel_lz4="${complevel_lz4:--12}"
|
||||
|
||||
case "$INITRAMFSCOMP" in
|
||||
gzip) comp="$(command -v gzip 2>/dev/null || echo gzip) $complevel_gzip" ;;
|
||||
xz) cmd_exists xz; comp="xz -C crc32 -T0 $complevel_xz" ;;
|
||||
zstd) cmd_exists zstd; comp="zstd -T0 $complevel_zstd" ;;
|
||||
lz4) cmd_exists lz4; comp="lz4 --favor-decSpeed -lz $complevel_lz4" ;;
|
||||
none|cat) comp="cat";;
|
||||
*) comp="gzip" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
parse_opt() {
|
||||
while [ $1 ]; do
|
||||
case $1 in
|
||||
-c|--config) needarg $2
|
||||
CONFIG=$2
|
||||
shift 1;;
|
||||
-i|--init) needarg $2
|
||||
INITIN=$2
|
||||
shift 1;;
|
||||
-C|--compression) needarg $2
|
||||
INITRAMFSCOMP=$2
|
||||
shift 1;;
|
||||
-v|--version) print_version; exit 0;;
|
||||
-h|--help) usage; exit 0;;
|
||||
*) echo "ERROR: invalid option '$1'"
|
||||
exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
msgerr() {
|
||||
[ $QUIET ] && return
|
||||
echo "ERROR: $*"
|
||||
}
|
||||
|
||||
main() {
|
||||
CPIO=$(command -v cpio)
|
||||
parse_opt "$@"
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
msgerr "need root access!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CPIO=$(command -v bsdcpio) || CPIO=$(command -v cpio)
|
||||
if [ ! "$CPIO" ]; then
|
||||
msgerr "neither 'bsdcpio' or 'cpio' found, exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$CONFIG" ]; then
|
||||
. "$CONFIG"
|
||||
else
|
||||
msgerr "config file '$CONFIG' not exist."
|
||||
exit 1
|
||||
fi
|
||||
create_dirs
|
||||
cp -v /usr/share/mkinitramfs/init.in $initdir/init
|
||||
cp -v $INITIN $initdir/init
|
||||
chmod 755 $initdir/init
|
||||
cp -v /usr/share/mkinitramfs/busybox $initdir/bin/busybox
|
||||
cd $initdir/bin
|
||||
for i in $(cat /usr/share/mkinitramfs/busybox_list);do ln -sv busybox $i;done
|
||||
cd $initdir
|
||||
find . | $CPIO -H newc -o | gzip > ../initramfs.img
|
||||
add_compression
|
||||
find . | $CPIO -H newc -o | $comp > ../initramfs.img
|
||||
cd ..
|
||||
rm -rv $initdir
|
||||
}
|
||||
|
||||
main
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user