From: Zoltán Felleg Date: Wed, 2 Apr 2025 18:09:05 +0000 (+0200) Subject: Updated scripts/c3.sh (added lxc file system type determination). X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=4a70bc28c2af9ca46b2803b46b0cc9e267479bf0;p=user-lxc.git Updated scripts/c3.sh (added lxc file system type determination). --- diff --git a/scripts/c3.sh b/scripts/c3.sh index 5ef378b..1c1e694 100755 --- a/scripts/c3.sh +++ b/scripts/c3.sh @@ -29,17 +29,16 @@ backup_old_container() if [ -d $OLD_CONTAINER_BACKUP_PATH ] then + echo " Removing the oldest container backup." rm -Rf ${OLD_CONTAINER_BACKUP_PATH}.old mv $OLD_CONTAINER_BACKUP_PATH ${OLD_CONTAINER_BACKUP_PATH}.old fi - OLD_CONTAINER_STATE=$(lxc-info --name=$OLD_CONTAINER_NAME --state 2>/dev/null \ - | cut -f 2 -d ':' | tr -d ' ') case "$OLD_CONTAINER_STATE" in "RUNNING") - echo "Stopping (the old) container $OLD_CONTAINER_NAME" + echo " Stopping (the old) container $OLD_CONTAINER_NAME" lxc-stop --name=$OLD_CONTAINER_NAME - echo "Stopped (the old) container $OLD_CONTAINER_NAME" + echo " Stopped (the old) container $OLD_CONTAINER_NAME" ;; "STOPPED") ;; @@ -58,7 +57,8 @@ copy_and_install() { echo "Copying base container files." - if [ "$1" = "btrfs" ] + FSTYPE=$(findmnt --noheadings --output FSTYPE --target $LXC_PATH) + if [ "$FSTYPE" = "btrfs" ] then # each container modifies its own version cp --archive $BASE_CONTAINER_PATH/rootfs/* $CONTAINER_BUILDROOT @@ -214,6 +214,7 @@ create_environment_file() echo "OLD_CONTAINER_NAME=$OLD_CONTAINER_NAME" >>$ENV_FILE echo "OLD_CONTAINER_PATH=$OLD_CONTAINER_PATH" >>$ENV_FILE echo "OLD_CONTAINER_BACKUP_PATH=$OLD_CONTAINER_BACKUP_PATH" >>$ENV_FILE + echo "OLD_CONTAINER_STATE=$OLD_CONTAINER_STATE" >>$ENV_FILE echo "Environment file created." } @@ -391,6 +392,8 @@ set_variables() OLD_CONTAINER_NAME=$(lxc-ls -1 | grep -w "^$CONTAINER_BASENAME") OLD_CONTAINER_PATH=$LXC_PATH/$OLD_CONTAINER_NAME OLD_CONTAINER_BACKUP_PATH=$BACKUPS_PATH/$OLD_CONTAINER_NAME + OLD_CONTAINER_STATE=$(lxc-info --name=$OLD_CONTAINER_NAME --state 2>/dev/null \ + | cut -f 2 -d ':' | tr -d ' ') echo "All variables set." } @@ -434,8 +437,9 @@ postinstall() do TGT_HOST=$(echo "$LINE" | cut -f 1 -d ' ') TGT_USER=$(echo "$LINE" | cut -f 2 -d ' ') - TGT_EXECUTABLE=$(echo "$LINE" | cut -f 3 -d ' ') - ssh -i $SSH_KEYS_PATH/scripts -l $TGT_USER $TGT_HOST $TGT_EXECUTABLE + TGT_EXECUTABLE=$(echo "$LINE" | cut -f 3- -d ' ') + ssh -i $SSH_KEYS_PATH/scripts \ + -l $TGT_USER $TGT_HOST $TGT_EXECUTABLE done fi COPY_PATH=$POSTINSTALL_PATH/scp @@ -492,7 +496,12 @@ unprivilege() PRIV_UID_COUNT=$(find $CONTAINER_BUILDROOT -uid $PRIV_UID | wc -l) if [ $PRIV_UID_COUNT -gt 0 ] then - echo "root user files: $PRIV_UID_COUNT" + if [ $PRIV_UID_COUNT -lt 10 ] + then + find $CONTAINER_PATH/rootfs -uid $PRIV_UID -print0 | xargs -0 ls --directory -l + else + echo "root user files: $PRIV_UID_COUNT" + fi UNPRIV_UID=$(( $PRIV_UID + 100000 )) find $CONTAINER_BUILDROOT -uid $PRIV_UID -print0 | xargs -0 chown --no-dereference $UNPRIV_UID fi @@ -501,7 +510,12 @@ unprivilege() PRIV_GID_COUNT=$(find $CONTAINER_BUILDROOT -gid $PRIV_GID | wc -l) if [ $PRIV_GID_COUNT -gt 0 ] then - echo "root group files: $PRIV_GID_COUNT" + if [ $PRIV_GID_COUNT -lt 10 ] + then + find $CONTAINER_PATH/rootfs -gid $PRIV_GID -print0 | xargs -0 ls --directory -l + else + echo "root group files: $PRIV_GID_COUNT" + fi UNPRIV_GID=$(( $PRIV_GID + 100000 )) find $CONTAINER_BUILDROOT -gid $PRIV_GID -print0 | xargs -0 chgrp --no-dereference $UNPRIV_GID fi @@ -556,6 +570,11 @@ firstboot() shopt -u nullglob fi + if [ "$OLD_CONTAINER_STATE" = "STOPPED" ] + then + lxc-attach --name=$CONTAINER_NAME -- poweroff + fi + echo "Finished firstboot phase." } @@ -579,7 +598,7 @@ populate_c3d preinstall -copy_and_install ext4 +copy_and_install set_c3d_ownership