From ceebddbff4f3b46a3c9b1b4c35dd55a57c5e54e7 Mon Sep 17 00:00:00 2001 From: crims0n Date: Tue, 23 Nov 2021 20:22:27 +0300 Subject: [PATCH] update --- linux-live/bootfiles-grub/boot/grub/grub.cfg | 6 +- .../bootfiles-grub/boot/grub/grub.cfg.2 | 2 +- .../bootfiles/boot/EFI/Boot/syslinux.cfg | 6 +- linux-live/bootfiles/boot/syslinux.cfg | 6 +- linux-live/buildconfig | 2 +- linux-live/initramfs/static/cmdline_parser | 260 +++++++++++++----- linux-live/livekitlib | 9 +- linux-live/minioslib | 6 +- 8 files changed, 206 insertions(+), 91 deletions(-) diff --git a/linux-live/bootfiles-grub/boot/grub/grub.cfg b/linux-live/bootfiles-grub/boot/grub/grub.cfg index 421042a..3de5159 100644 --- a/linux-live/bootfiles-grub/boot/grub/grub.cfg +++ b/linux-live/bootfiles-grub/boot/grub/grub.cfg @@ -25,18 +25,18 @@ set message="Loading kernel and ramdisk..." menuentry "Run MiniOS (Persistent changes)"{ echo $message search --set -f $linux_64 - linux $linux_64 $default_settings $perch_settings + linux $linux_64 $default_settings $perch_settings ssh initrd $initrd_img } menuentry "Run MiniOS (Fresh start)"{ echo $message search --set -f $linux_64 - linux $linux_64 $default_settings $live_settings + linux $linux_64 $default_settings $live_settings ssh initrd $initrd_img } menuentry "Run MiniOS (Copy to RAM)"{ echo $message search --set -f $linux_64 - linux $linux_64 $default_settings $ram_settings + linux $linux_64 $default_settings $ram_settings ssh initrd $initrd_img } \ No newline at end of file diff --git a/linux-live/bootfiles-grub/boot/grub/grub.cfg.2 b/linux-live/bootfiles-grub/boot/grub/grub.cfg.2 index 6182b4c..9e4fb4a 100644 --- a/linux-live/bootfiles-grub/boot/grub/grub.cfg.2 +++ b/linux-live/bootfiles-grub/boot/grub/grub.cfg.2 @@ -26,6 +26,6 @@ set message="Loading kernel and ramdisk..." menuentry "MiniOS (Copy to RAM)"{ echo $message search --set -f $linux_64 - linux $linux_64 $default_settings $ram_settings $http_settings $console_settings + linux $linux_64 $default_settings $ram_settings $http_settings $console_settings ssh initrd $initrd_img } \ No newline at end of file diff --git a/linux-live/bootfiles/boot/EFI/Boot/syslinux.cfg b/linux-live/bootfiles/boot/EFI/Boot/syslinux.cfg index 07d442c..506107b 100644 --- a/linux-live/bootfiles/boot/EFI/Boot/syslinux.cfg +++ b/linux-live/bootfiles/boot/EFI/Boot/syslinux.cfg @@ -29,14 +29,14 @@ MENU TABMSG [F1] help [Ta LABEL default MENU LABEL Run MiniOS (Persistent changes) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=perch,automount net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=perch,automount net.ifnames=0 biosdevname=0 ssh quiet LABEL live MENU LABEL Run MiniOS (Fresh start) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=automount net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=automount net.ifnames=0 biosdevname=0 ssh quiet LABEL toram MENU LABEL Run MiniOS (Copy to RAM) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=toram net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 slax.flags=toram net.ifnames=0 biosdevname=0 ssh quiet diff --git a/linux-live/bootfiles/boot/syslinux.cfg b/linux-live/bootfiles/boot/syslinux.cfg index 70b0f5e..ba2341a 100644 --- a/linux-live/bootfiles/boot/syslinux.cfg +++ b/linux-live/bootfiles/boot/syslinux.cfg @@ -29,14 +29,14 @@ MENU TABMSG [F1] help [Ta LABEL default MENU LABEL Run MiniOS (Persistent changes) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=perch net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=perch net.ifnames=0 biosdevname=0 ssh quiet LABEL live MENU LABEL Run MiniOS (Fresh start) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags= net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags= net.ifnames=0 biosdevname=0 ssh quiet LABEL toram MENU LABEL Run MiniOS (Copy to RAM) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=toram net.ifnames=0 biosdevname=0 quiet +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=toram net.ifnames=0 biosdevname=0 ssh quiet diff --git a/linux-live/buildconfig b/linux-live/buildconfig index dfecf99..4419c4a 100644 --- a/linux-live/buildconfig +++ b/linux-live/buildconfig @@ -14,7 +14,7 @@ DISTRIBUTION="bullseye" # для заметки: stretch работает только с amd64 DISTRIBUTION_ARCH="amd64" -COMP_TYPE="zstd" +COMP_TYPE="xz" # bootstrap variant (used to build Ubuntu) # вариант bootstrap (используется для сборки Ubuntu) diff --git a/linux-live/initramfs/static/cmdline_parser b/linux-live/initramfs/static/cmdline_parser index 091ed57..abd6327 100755 --- a/linux-live/initramfs/static/cmdline_parser +++ b/linux-live/initramfs/static/cmdline_parser @@ -4,89 +4,179 @@ # Author: crims0n. # -for i in $(cat /cmdline); do - case $i in - user_name=*) - USER_NAME="${i#*=}" - shift # past argument=value - ;; - user_password=*) - USER_PASSWORD="${i#*=}" - shift # past argument=value - ;; - root_password=*) - ROOT_PASSWORD="${i#*=}" - shift # past argument=value - ;; - host_name=*) - HOST_NAME="${i#*=}" - shift # past argument=value - ;; - default_target=*) - DEFAULT_TARGET="${i#*=}" - shift # past argument=value - ;; - ssh) - SSH=true - shift # past argument with no value - ;; - cloud) - CLOUD=true - shift # past argument with no value - ;; - *) - # unknown option - ;; - esac -done - -if [ -z "$ROOT_PASSWORD" ]; then - ROOT_PASSWORD="toor" +function read_cmdline() { + for i in $(cat /cmdline); do + case $i in + user_name=*) + USER_NAME="${i#*=}" + shift # past argument=value + ;; + user_password=*) + USER_PASSWORD="${i#*=}" + shift # past argument=value + ;; + root_password=*) + ROOT_PASSWORD="${i#*=}" + shift # past argument=value + ;; + host_name=*) + HOST_NAME="${i#*=}" + shift # past argument=value + ;; + default_target=*) + DEFAULT_TARGET="${i#*=}" + shift # past argument=value + ;; + ssh) + SSH=true + shift # past argument with no value + ;; + cloud) + CLOUD=true + shift # past argument with no value + ;; + *) + # unknown option + ;; + esac + done +} + +function read_config() { # read_config file.cfg var_name1 var_name2 + # ref: https://stackoverflow.com/a/20815951 + + shopt -s extglob # needed the "one of these"-match below + local configfile="${1?No configuration file given}" + local keylist="${@:2}" # positional parameters 2 and following + + if [[ ! -f "$configfile" ]]; then + echo >&2 "\"$configfile\" is not a file!" + exit 1 + fi + if [[ ! -r "$configfile" ]]; then + echo >&2 "\"$configfile\" is not readable!" + exit 1 + fi + + keylist="${keylist// /|}" # this will generate a regex 'one of these' + + # lhs : "left hand side" : Everything left of the '=' + # rhs : "right hand side": Everything right of the '=' + # + # "lhs" will hold the name of the key you want to read. + # The value of "rhs" will be assigned to that key. + while IFS='= ' read -r lhs rhs; do + # IF lhs in keylist + # AND rhs not empty + if [[ "$lhs" =~ ^($keylist)$ ]] && [[ -n $rhs ]]; then + rhs="${rhs%\"*}" # Del opening string quotes + rhs="${rhs#\"*}" # Del closing string quotes + rhs="${rhs%\'*}" # Del opening string quotes + rhs="${rhs#\'*}" # Del closing string quotes + eval $lhs=\"$rhs\" # The magic happens here + fi + # tr used as a safeguard against dos line endings + done <<<$(tr -d '\r' <$configfile) + + shopt -u extglob # Switching it back off after use +} + +$CMDLINE=$(cat /cmdline) +read_cmdline $CMDLINE + +if [ -f /run/initramfs/memory/data/minios/minios.conf ]; then + cp /run/initramfs/memory/data/minios/minios.conf /etc/minios.conf +elif [ -f /etc/minios.conf ]; then + cp /etc/minios.conf /run/initramfs/memory/data/minios/minios.conf +fi + +if [ -z "$ROOT_PASSWORD" ] || [ "$ROOT_PASSWORD" = "" ]; then + if [ -f /etc/minios.conf ]; then + read_config /etc/minios.conf ROOT_PASSWORD + else + ROOT_PASSWORD="toor" + fi fi + #echo "Set up password for user 'root'" echo root:$ROOT_PASSWORD | chpasswd +if [ -f /etc/minios.conf ]; then + sed -i -e "/ROOT_PASSWORD=/s/=.*/=$ROOT_PASSWORD/" /etc/minios.conf +fi -if [ "$CLOUD" != "true" ]; then - - if [ -z "$USER_NAME" ]; then - USER_NAME="live" +if [ -z "$CLOUD" ] || [ "$CLOUD" = "" ]; then + if [ -f /etc/minios.conf ]; then + read_config /etc/minios.conf CLOUD + else + CLOUD="false" fi - if [ "$USER_NAME" != "root" ]; then - #echo "Set up user '$USER_NAME'" - adduser --uid 1000 --gecos '' $USER_NAME --disabled-password - - if [ -z "$USER_PASSWORD" ]; then - USER_PASSWORD="evil" +fi +sed -i -e "/CLOUD=/s/=.*/=$CLOUD/" /etc/minios.conf +if [ "$CLOUD" != "true" ]; then + if [ ! -f /etc/minios.conf ]; then + if [ -z "$USER_NAME" ] || [ "$USER_NAME" = "" ]; then + USER_NAME="live" + fi + if [ "$USER_NAME" != "root" ]; then + #echo "Set up user '$USER_NAME'" + adduser --uid 1000 --gecos '' $USER_NAME --disabled-password + usermod -a -G sudo $USER_NAME + + if [ -z "$USER_PASSWORD" ] || [ "$USER_PASSWORD" = "" ]; then + USER_PASSWORD="evil" + fi + #echo "Set up password for user '$USER_NAME'" + echo $USER_NAME:$USER_PASSWORD | chpasswd + fi + else + if [ -z "$USER_NAME" ] || [ "$USER_NAME" = "" ]; then + read_config /etc/minios.conf USER_NAME + fi + if [ -z "$USER_PASSWORD" ] || [ "$USER_PASSWORD" = "" ]; then + read_config /etc/minios.conf USER_PASSWORD fi - #echo "Set up password for user '$USER_NAME'" echo $USER_NAME:$USER_PASSWORD | chpasswd - usermod -a -G sudo $USER_NAME + sed -i -e "/USER_PASSWORD=/s/=.*/=$USER_PASSWORD/" /etc/minios.conf fi - sed -i 's,#PermitRootLogin prohibit-password,PermitRootLogin yes,g' /etc/ssh/sshd_config - sed -i 's,#PasswordAuthentication yes,PasswordAuthentication yes,g' /etc/ssh/sshd_config else - rm -rf /home/live + USER_NAME="root" + SSH="true" fi -if [ "$USER_NAME" != "live" ] && [ "$USER_NAME" != "root" ]; then - rm -rf /home/live - # create user directories - for dir in Desktop Documents Downloads Music Pictures Public Templates Videos; do - mkdir -p /home/$USER_NAME/$dir - done - chown 1000:1000 /home/$USER_NAME - chown -R 1000:1000 /home/$USER_NAME -elif [ "$USER_NAME" = "root" ]; then - rm -rf /home/live +if [ ! -f /etc/minios.conf ]; then + if [ "$USER_NAME" != "live" ] || [ "$USER_NAME" != "root" ]; then + if [ -d /home/live ]; then + rm -rf /home/live + fi + # create user directories + if [ -d /home/$USER_NAME/$dir ]; then + for dir in Desktop Documents Downloads Music Pictures Public Templates Videos; do + mkdir -p /home/$USER_NAME/$dir + done + chown 1000:1000 /home/$USER_NAME + chown -R 1000:1000 /home/$USER_NAME + fi + fi fi +if [ -z "$SSH" ] || [ "$SSH" = "" ]; then + if [ -f /etc/minios.conf ]; then + read_config /etc/minios.conf SSH + else + SSH="false" + fi +fi if [ "$SSH" = "true" ]; then systemctl enable ssh-keygen systemctl enable ssh + sed -i 's,#PermitRootLogin prohibit-password,PermitRootLogin yes,g' /etc/ssh/sshd_config + sed -i 's,#PasswordAuthentication yes,PasswordAuthentication yes,g' /etc/ssh/sshd_config else systemctl disable ssh-keygen systemctl disable ssh + SSH="false" fi +sed -i -e "/SSH=/s/=.*/=$SSH/" /etc/minios.conf if [ "$USER_NAME" != "root" ]; then cat </etc/sudoers.d/90-minios @@ -216,20 +306,40 @@ if [ -f /etc/slim.conf ]; then sed -i "s/default_user live/default_user $USER_NAME/g" /etc/slim.conf fi -if [ -z "$HOST_NAME" ]; then - HOST_NAME="minios" +if [ "$CLOUD" != "true" ]; then + if [ -z "$HOST_NAME" ] || [ "$HOST_NAME" = "" ]; then + if [ -f /etc/minios.conf ]; then + read_config /etc/minios.conf HOST_NAME + else + HOST_NAME="minios" + fi + fi + echo $HOST_NAME >/etc/hostname + if [ -f /etc/minios.conf ]; then + sed -i -e "/HOST_NAME=/s/=.*/=$HOST_NAME/" /etc/minios.conf + fi fi -echo $HOST_NAME >/etc/hostname -if [ -z "$DEFAULT_TARGET" ]; then - $DEFAULT_TARGET="graphical" +if [ -z "$DEFAULT_TARGET" ] || [ "$DEFAULT_TARGET" = "" ]; then + if [ -f /etc/minios.conf ]; then + read_config /etc/minios.conf DEFAULT_TARGET + else + $DEFAULT_TARGET="graphical" + fi fi systemctl set-default $DEFAULT_TARGET +if [ -f /etc/minios.conf ]; then + sed -i -e "/DEFAULT_TARGET=/s/=.*/=$DEFAULT_TARGET/" /etc/minios.conf +fi -echo "USER_NAME=$USER_NAME" -echo "USER_PASSWORD=$USER_PASSWORD" -echo "ROOT_PASSWORD=$ROOT_PASSWORD" -echo "HOSTNAME=$HOSTNAME" -echo "DEFAULT_TARGET=$DEFAULT_TARGET" -echo "SSH=$SSH" -echo "CLOUD=$CLOUD" +#if [ "$CLOUD" != "true" ]; then +if [ ! -f /etc/minios.conf ]; then + echo "USER_NAME=$USER_NAME" >/etc/minios.conf + echo "USER_PASSWORD=$USER_PASSWORD" >>/etc/minios.conf + echo "ROOT_PASSWORD=$ROOT_PASSWORD" >>/etc/minios.conf + echo "HOST_NAME=$HOST_NAME" >>/etc/minios.conf + echo "DEFAULT_TARGET=$DEFAULT_TARGET" >>/etc/minios.conf + echo "SSH=$SSH" >>/etc/minios.conf + echo "CLOUD=$CLOUD" >>/etc/minios.conf +fi +#fi diff --git a/linux-live/livekitlib b/linux-live/livekitlib index 1a6b8df..95c05bd 100644 --- a/linux-live/livekitlib +++ b/linux-live/livekitlib @@ -619,7 +619,12 @@ persistent_changes() { EXISTS="" fi - @mount.dynfilefs "$CHANGES/changes.dat" 4000 "$2" + PERCH_SIZE=$(cmdline_value perch_size) + if [ ! "$PERCH_SIZE" ]; then + @mount.dynfilefs "$CHANGES/changes.dat" 4000 "$2" + else + @mount.dynfilefs "$CHANGES/changes.dat" $PERCH_SIZE "$2" + fi if [ ! "$EXISTS" ]; then mke2fs -F "$2/loop.fs" >/dev/null 2>&1 fi @@ -782,7 +787,7 @@ minios_configure() { cp /bin/cmdline_parser $1/ cat /proc/cmdline >$1/cmdline - chroot $1 /bin/bash -c "/cmdline_parser" > /dev/null 2>&1 + chroot $1 /bin/bash -c "/cmdline_parser" >/dev/null 2>&1 rm -f $1/cmdline rm -f $1/cmdline_parser diff --git a/linux-live/minioslib b/linux-live/minioslib index c34518c..91436de 100644 --- a/linux-live/minioslib +++ b/linux-live/minioslib @@ -1058,7 +1058,7 @@ MENU TABMSG [F1] help [Ta LABEL default MENU LABEL Run MiniOS (Copy to RAM) KERNEL /minios/boot/vmlinuz -APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=toram net.ifnames=0 biosdevname=0 +APPEND vga=normal initrd=/minios/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 selinux=0 minios.flags=toram net.ifnames=0 biosdevname=0 ssh EOF cat <<'EOF' >$BUILD_DIR/image/boot/grub/grub.cfg @@ -1075,12 +1075,12 @@ set color_highlight=black/white loadfont /boot/grub/unicode.pf2 #background_image /boot/grub/bootlogo.png -set default_settings="load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 net.ifnames=0 biosdevname=0" +set default_settings="load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 consoleblank=0 apparmor=0 net.ifnames=0 biosdevname=0 ssh" set perch_settings="minios.flags=perch" set live_settings="minios.flags= " set ram_settings="minios.flags=toram" set console_settings="console=tty0 console=ttyS0,115200" -set debug_settings="load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 apparmor=0 debug net.ifnames=0 biosdevname=0" +set debug_settings="load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 apparmor=0 debug net.ifnames=0 biosdevname=0 ssh" set linux_64="/minios/boot/vmlinuz" set initrd_img="/minios/boot/initrfs.img" set default=0