diff --git a/__frzr b/__frzr index a899563..f900666 100644 --- a/__frzr +++ b/__frzr @@ -4,39 +4,39 @@ source "${BASH_SOURCE%/*}/__frzr-envars" frzr_status() { - # Output frzr status tracker using the JSON format - cat < /dev/null; then + while (("$#")); do + case $1 in + #--check) + # FRZR_CHECK_UPDATE=1 + # shift + # ;; + #--steam-progress) + # FRZR_STEAM_PROGRESS=1 + # shift + # ;; + -* | --*) + TASK_ERROR=1 + TASK_ERROR_MSG="Unknown argument $1" + STATE="FAIL" + ;; + *) # preserve positional arguments + FRZR_PARAMS="${FRZR_PARAMS}$1 " # Use trailing space for the match below + shift + ;; + esac + done + + # keep only the first param as source + if "${BASH_SOURCE%/*}/frzr-release" > /dev/null; then CURRENT=$("${BASH_SOURCE%/*}/frzr-release") fi - - STATE="BEGIN" - ;; - "BEGIN") - FRZR_VERSION=$("${BASH_SOURCE%/*}/frzr-version") - if echo "${FRZR_VERSION}" | grep -Fq "ERROR"; then - TASK_ERROR=1 - TASK_ERROR_MSG="Could not fetch frzr version: ${FRZR_VERSION}" - STATE="FAIL" - send_data - continue - fi - - # Make sure the frzr_root is mounted during the deployment procedure - # this code is based on the fact that when a btrfs filesystem is created - # the default subvolid that is created contextually has the ID set to 256 - # also as a matter of fact in btrfs is impossible to change subvolumes IDs - if ! mountpoint -q "${MOUNT_PATH}" && ls -1 /dev/disk/by-label | grep frzr_root > /dev/null; then - MOUNT_PATH="/tmp/frzr_root" - #TASK_MSG="Preparing '${MOUNT_PATH}' to be used as the main subvolume mount path" - mkdir -p ${MOUNT_PATH} - if mount -L frzr_root -t btrfs -o subvolid=5,rw "${MOUNT_PATH}"; then - MOUNTED_MOUNT_PATH="yes" - fi - sleep 5 - fi - - if mountpoint -q "${MOUNT_PATH}" && ls -1 /dev/disk/by-label | grep frzr_root > /dev/null; then - STATE="RELEASE_CHECK" - else - echo "frzr-unlock failed: could not mount frzr_root" - STATE="FAIL" - continue - fi - ;; - "RELEASE_CHECK") - # If this is user-specified we should unlock that deployment in particular - NAME="${FRZR_SOURCE}" - if [ -z "${NAME}" ]; then - NAME="${CURRENT}" - else - DEPLOY_PATH="${MOUNT_PATH}/deployments" - SUBVOL="${DEPLOY_PATH}/${NAME}" - - # Make sure DEPLOY_PATH exists - mkdir -p "${DEPLOY_PATH}" - if [ ! -d "${DEPLOY_PATH}" ]; then - TASK_ERROR=1 - TASK_ERROR_MSG="Could not create ${DEPLOY_PATH} to to store deployments" - STATE="FAIL" - continue - fi - - # Make sure SUBVOL exists - if [ ! -d "${SUBVOL}" ]; then - TASK_ERROR=1 - TASK_ERROR_MSG="Could not find deployment '${NAME}', '${SUBVOL}' was searched" - STATE="FAIL" - continue - fi - fi - - STATE="UNLOCK" - ;; - "UNLOCK") - if [ -d "${SUBVOL}/usr/lib/frzr.d" ]; then - # set rootfs btrfs subvolume to read-write mode - UNLOCK_RESULT=$(execute_unlock "${NAME}" "${SUBVOL}" "${MOUNT_PATH}" "${FRZR_VERSION}") - if echo "${UNLOCK_RESULT}" | grep -Fq 'ERROR'; then - echo "frzr deployment ${NAME} unlock failed: ${UNLOCK_RESULT}" - STATE="FAIL" - continue - fi - - systemctl daemon-reload - - STATE="SUCCESS" - else - TASK_ERROR=1 - TASK_ERROR_MSG="Could not find unlock migrations for deployment '${NAME}', '${SUBVOL}/usr/lib/frzr.d' does not exists" - STATE="FAIL" - continue - fi - ;; - "SUCCESS") - # This state should only be used if the unlock completed without errors - #TASK_STATE="SUCCESS" - - echo "frzr deployment ${NAME} unlock succeeded, please reboot to use the unlocked deployment" - - RUNNING=false - ;; - "FAIL") - # This state should only be used if the unlock failed - - #TASK_STATE="FAIL" - - echo "frzr-unlock failed for deployment ${NAME}: ${UNLOCK_RESULT}" - - RUNNING=false - ;; - *) - TASK_STATE="UNKNOWN_ERROR" - echo "ERROR: Something went terribly wrong" - RUNNING=false - ;; - esac - done - - # umount the frzr_root subvolume (if it was mounted by this tool and not externally) - if [ "${MOUNTED_MOUNT_PATH}" = "yes" ]; then - if mountpoint -q "${MOUNT_PATH}"; then - umount -l "${MOUNT_PATH}" - fi - fi + + STATE="BEGIN" + ;; + "BEGIN") + FRZR_VERSION=$("${BASH_SOURCE%/*}/frzr-version") + if echo "${FRZR_VERSION}" | grep -Fq "ERROR"; then + TASK_ERROR=1 + TASK_ERROR_MSG="Could not fetch frzr version: ${FRZR_VERSION}" + STATE="FAIL" + send_data + continue + fi + + # Make sure the frzr_root is mounted during the deployment procedure + # this code is based on the fact that when a btrfs filesystem is created + # the default subvolid that is created contextually has the ID set to 256 + # also as a matter of fact in btrfs is impossible to change subvolumes IDs + if ! mountpoint -q "${MOUNT_PATH}" && ls -1 /dev/disk/by-label | grep frzr_root > /dev/null; then + MOUNT_PATH="/tmp/frzr_root" + #TASK_MSG="Preparing '${MOUNT_PATH}' to be used as the main subvolume mount path" + mkdir -p ${MOUNT_PATH} + if mount -L frzr_root -t btrfs -o subvolid=5,rw "${MOUNT_PATH}"; then + MOUNTED_MOUNT_PATH="yes" + fi + sleep 5 + fi + + if mountpoint -q "${MOUNT_PATH}" && ls -1 /dev/disk/by-label | grep frzr_root > /dev/null; then + STATE="RELEASE_CHECK" + else + echo "frzr-unlock failed: could not mount frzr_root" + STATE="FAIL" + continue + fi + ;; + "RELEASE_CHECK") + # If this is user-specified we should unlock that deployment in particular + NAME="${FRZR_SOURCE}" + if [ -z "${NAME}" ]; then + NAME="${CURRENT}" + else + DEPLOY_PATH="${MOUNT_PATH}/deployments" + SUBVOL="${DEPLOY_PATH}/${NAME}" + + # Make sure DEPLOY_PATH exists + mkdir -p "${DEPLOY_PATH}" + if [ ! -d "${DEPLOY_PATH}" ]; then + TASK_ERROR=1 + TASK_ERROR_MSG="Could not create ${DEPLOY_PATH} to to store deployments" + STATE="FAIL" + continue + fi + + # Make sure SUBVOL exists + if [ ! -d "${SUBVOL}" ]; then + TASK_ERROR=1 + TASK_ERROR_MSG="Could not find deployment '${NAME}', '${SUBVOL}' was searched" + STATE="FAIL" + continue + fi + fi + + STATE="UNLOCK" + ;; + "UNLOCK") + if [ -d "${SUBVOL}/usr/lib/frzr.d" ]; then + # set rootfs btrfs subvolume to read-write mode + UNLOCK_RESULT=$(execute_unlock "${NAME}" "${SUBVOL}" "${MOUNT_PATH}" "${FRZR_VERSION}") + if echo "${UNLOCK_RESULT}" | grep -Fq 'ERROR'; then + echo "frzr deployment ${NAME} unlock failed: ${UNLOCK_RESULT}" + STATE="FAIL" + continue + fi + + systemctl daemon-reload + + STATE="SUCCESS" + else + TASK_ERROR=1 + TASK_ERROR_MSG="Could not find unlock migrations for deployment '${NAME}', '${SUBVOL}/usr/lib/frzr.d' does not exists" + STATE="FAIL" + continue + fi + ;; + "SUCCESS") + # This state should only be used if the unlock completed without errors + #TASK_STATE="SUCCESS" + + echo "frzr deployment ${NAME} unlock succeeded, please reboot to use the unlocked deployment" + + RUNNING=false + ;; + "FAIL") + # This state should only be used if the unlock failed + + #TASK_STATE="FAIL" + + echo "frzr-unlock failed for deployment ${NAME}: ${UNLOCK_RESULT}" + + RUNNING=false + ;; + *) + TASK_STATE="UNKNOWN_ERROR" + echo "ERROR: Something went terribly wrong" + RUNNING=false + ;; + esac + done + + # umount the frzr_root subvolume (if it was mounted by this tool and not externally) + if [ "${MOUNTED_MOUNT_PATH}" = "yes" ]; then + if mountpoint -q "${MOUNT_PATH}"; then + umount -l "${MOUNT_PATH}" + fi + fi } \ No newline at end of file diff --git a/__frzr-version b/__frzr-version index 492ba46..251fad1 100644 --- a/__frzr-version +++ b/__frzr-version @@ -6,5 +6,5 @@ set -e #source "${BASH_SOURCE%/*}/__frzr" "$@" frzr_version() { - echo "1.0.0" + echo "1.0.0" } \ No newline at end of file diff --git a/frzr b/frzr index b1b7830..888f60b 100755 --- a/frzr +++ b/frzr @@ -3,12 +3,12 @@ set -Ee if ! groups | grep -Fq "frzr"; then - if [ "$EUID" -ne 0 ]; then - echo "Current user is not in the frzr group" - exit 1 - else - echo "Running frzr as root, but root is not a member of frzr group" - fi + if [ "$EUID" -ne 0 ]; then + echo "Current user is not in the frzr group" + exit 1 + else + echo "Running frzr as root, but root is not a member of frzr group" + fi fi # Import methods @@ -18,7 +18,7 @@ source "${BASH_SOURCE%/*}/__frzr" "$@" write_tracker_file usage(){ - echo "[Usage] + echo "[Usage] frzr deploy [Check for system updates and update the system if available] frzr bootloader [Install the bootloader and create entries for every deployed image] frzr unlock (deployment) [Unlock the specified deployment, or the running one if deployment is not specified] @@ -33,25 +33,25 @@ frzr bootstrap [Format and configure a drive to be used with FRZR]" # Catch unexpected errors and give feedback handle_error() { - local function_name="$1" - local line_number="$2" - local command="$3" + local function_name="$1" + local line_number="$2" + local command="$3" - echo "Error occurred in function '${function_name}' on line ${line_number}. Command: '${command}'" + echo "Error occurred in function '${function_name}' on line ${line_number}. Command: '${command}'" - frzr_status + frzr_status - if [ -f /tmp/frzr.lock ]; then - rm /tmp/frzr.lock - fi + if [ -f /tmp/frzr.lock ]; then + rm /tmp/frzr.lock + fi } # Set up trap to catch errors and call handle_error function trap 'handle_error "${FUNCNAME[0]}" "$LINENO" "$BASH_COMMAND"' ERR if [ $# -eq 0 ]; then - usage - exit 1 + usage + exit 1 fi function=$1 @@ -60,95 +60,95 @@ arg2=$3 arg3=$4 if [ $function == "-h" ] || [ $function == "help" ]; then - usage + usage elif [ $function == "bootstrap" ]; then - source "${BASH_SOURCE%/*}/frzr-bootstrap" "${arg1}" "${arg2}" "${arg3}" # username, disk, clean/repair install - RESULT=$? - exit $RESULT + source "${BASH_SOURCE%/*}/frzr-bootstrap" "${arg1}" "${arg2}" "${arg3}" # username, disk, clean/repair install + RESULT=$? + exit $RESULT elif [ $function == "deploy" ]; then - frzr_check_bootenv - # We don't want to pass the function parameter to __frzr-deploy - shift - #flock -E 255 -n /tmp/frzr.lock "frzr-deploy" "$@" - source "${BASH_SOURCE%/*}/frzr-deploy" "$@" - RESULT=$TASK_ERROR - #if [ $RESULT == 255 ]; then - # echo "ERROR: $(basename $0) is already running" - #fi - exit $RESULT + frzr_check_bootenv + # We don't want to pass the function parameter to __frzr-deploy + shift + #flock -E 255 -n /tmp/frzr.lock "frzr-deploy" "$@" + source "${BASH_SOURCE%/*}/frzr-deploy" "$@" + RESULT=$TASK_ERROR + #if [ $RESULT == 255 ]; then + # echo "ERROR: $(basename $0) is already running" + #fi + exit $RESULT elif [ $function == "unlock" ]; then - frzr_check_bootenv - # We don't want to pass the function parameter to __frzr-unlock - shift - #flock -E 255 -n /tmp/frzr.lock "frzr-depunlockloy" "$@" - source "${BASH_SOURCE%/*}/frzr-unlock" "$@" - RESULT=$TASK_ERROR - #if [ $RESULT == 255 ]; then - # echo "ERROR: $(basename $0) is already running" - #fi - exit $RESULT + frzr_check_bootenv + # We don't want to pass the function parameter to __frzr-unlock + shift + #flock -E 255 -n /tmp/frzr.lock "frzr-depunlockloy" "$@" + source "${BASH_SOURCE%/*}/frzr-unlock" "$@" + RESULT=$TASK_ERROR + #if [ $RESULT == 255 ]; then + # echo "ERROR: $(basename $0) is already running" + #fi + exit $RESULT elif [ $function == "bootloader" ]; then - frzr_check_bootenv - # We don't want to pass the function parameter to __frzr-bootloader - shift + frzr_check_bootenv + # We don't want to pass the function parameter to __frzr-bootloader + shift - #flock -E 255 -n /tmp/frzr.lock "frzr-bootloader" "$@" - source "${BASH_SOURCE%/*}/frzr-bootloader" "$@" - RESULT=$? + #flock -E 255 -n /tmp/frzr.lock "frzr-bootloader" "$@" + source "${BASH_SOURCE%/*}/frzr-bootloader" "$@" + RESULT=$? - #if [ $RESULT == 255 ]; then - # echo "ERROR: $(basename $0) is already running" - #fi + #if [ $RESULT == 255 ]; then + # echo "ERROR: $(basename $0) is already running" + #fi - exit $RESULT + exit $RESULT elif [ $function == "kernel" ]; then - frzr_check_bootenv - # We don't want to pass the function parameter to __frzr-kernel - shift - source "${BASH_SOURCE%/*}/frzr-kernel" "$@" - RESULT=$? + frzr_check_bootenv + # We don't want to pass the function parameter to __frzr-kernel + shift + source "${BASH_SOURCE%/*}/frzr-kernel" "$@" + RESULT=$? - #if [ $RESULT == 255 ]; then - # echo "ERROR: $(basename $0) is already running" - #fi + #if [ $RESULT == 255 ]; then + # echo "ERROR: $(basename $0) is already running" + #fi - exit $RESULT + exit $RESULT elif [ $function == "release" ]; then - source "${BASH_SOURCE%/*}/frzr-release" "$@" + source "${BASH_SOURCE%/*}/frzr-release" "$@" elif [ $function == "version" ]; then - frzr_check_bootenv - # We don't want to pass the function parameter to __frzr-version - shift + frzr_check_bootenv + # We don't want to pass the function parameter to __frzr-version + shift - #flock -E 255 -n /tmp/frzr.lock "frzr-version" "$@" - source "${BASH_SOURCE%/*}/frzr-version" "$@" - RESULT=$? + #flock -E 255 -n /tmp/frzr.lock "frzr-version" "$@" + source "${BASH_SOURCE%/*}/frzr-version" "$@" + RESULT=$? - #if [ $RESULT == 255 ]; then - # echo "ERROR: $(basename $0) is already running" - #fi + #if [ $RESULT == 255 ]; then + # echo "ERROR: $(basename $0) is already running" + #fi - exit $RESULT + exit $RESULT elif [ $function == "set-channel" ]; then - echo "set channel" - #TODO create frzr-channel to set target channel - #frzr-channel $arg1 + echo "set channel" + #TODO create frzr-channel to set target channel + #frzr-channel $arg1 elif [ $function == "get-channel" ]; then - echo "get-channel" - #TODO create frzr-channel to get target channel - #echo ${FRZR_ROOT}/source + echo "get-channel" + #TODO create frzr-channel to get target channel + #echo ${FRZR_ROOT}/source elif [ $function == "build-initramfs" ]; then - source frzr-initramfs + source frzr-initramfs elif [ $function == "configure-tweaks" ]; then - source frzr-tweaks + source frzr-tweaks elif [ $function == "package-options" ]; then - #User selected packages to be added to the install - source frzr-extras + #User selected packages to be added to the install + source frzr-extras else - echo "invalid argument" + echo "invalid argument" fi # print out the latest error in stderr (this is meant for debugging) if [ ! -z "${TASK_ERROR_MSG}" ]; then - echo "${TASK_ERROR_MSG}" 1>&2 + echo "${TASK_ERROR_MSG}" 1>&2 fi diff --git a/test/test-deploy.sh b/test/test-deploy.sh index 1393cba..3e53edc 100755 --- a/test/test-deploy.sh +++ b/test/test-deploy.sh @@ -52,54 +52,54 @@ btrfs property set -fts $MOUNT_POINT/archlinux ro true # Create the deployment file if btrfs send $MOUNT_POINT/archlinux | xz -e -9 --memory=95% -T0 > $TARGET_FILENAME; then - # Unmount the img file - umount $MOUNT_POINT + # Unmount the img file + umount $MOUNT_POINT - rm -rf $IMG_FILE + rm -rf $IMG_FILE - # Perform the deployment + # Perform the deployment - export FILENAME=install_deploy.img - export BUILD_DIR="/workdir/output" - export BUILD_IMG="$BUILD_DIR/$FILENAME" + export FILENAME=install_deploy.img + export BUILD_DIR="/workdir/output" + export BUILD_IMG="$BUILD_DIR/$FILENAME" - mkdir -p "$BUILD_DIR" - dd if=/dev/zero of=$BUILD_IMG bs=1M count=8192 + mkdir -p "$BUILD_DIR" + dd if=/dev/zero of=$BUILD_IMG bs=1M count=8192 - # Associate the image file with a loop device - losetup -fP "$BUILD_IMG" + # Associate the image file with a loop device + losetup -fP "$BUILD_IMG" - # Find the loop device associated with the image file - MOUNTED_DEVICE=$(losetup -a | grep "$FILENAME" | cut -d ' ' -f 1 | sed 's/://') + # Find the loop device associated with the image file + MOUNTED_DEVICE=$(losetup -a | grep "$FILENAME" | cut -d ' ' -f 1 | sed 's/://') - export DISK="$MOUNTED_DEVICE" - export SWAP_GIB=0 - bash /workdir/frzr bootstrap + export DISK="$MOUNTED_DEVICE" + export SWAP_GIB=0 + bash /workdir/frzr bootstrap - export SKIP_UEFI_CHECK="yes" - export MOUNT_PATH="/tmp/frzr_root" - export EFI_MOUNT_PATH="/tmp/frzr_root/efi" - export FRZR_SKIP_CHECK="yes" - export SYSTEMD_RELAX_ESP_CHECKS=1 + export SKIP_UEFI_CHECK="yes" + export MOUNT_PATH="/tmp/frzr_root" + export EFI_MOUNT_PATH="/tmp/frzr_root/efi" + export FRZR_SKIP_CHECK="yes" + export SYSTEMD_RELAX_ESP_CHECKS=1 - # deploy archlinux - bash /workdir/frzr deploy $TARGET_FILENAME + # deploy archlinux + bash /workdir/frzr deploy $TARGET_FILENAME - # old releases used an older frzr - INSTALLED_RELEASE=$(cat "$MOUNT_PATH/deployments/archlinux/build_info" | head -n 1) + # old releases used an older frzr + INSTALLED_RELEASE=$(cat "$MOUNT_PATH/deployments/archlinux/build_info" | head -n 1) - # Umount the loopback device - losetup -d "$MOUNTED_DEVICE" + # Umount the loopback device + losetup -d "$MOUNTED_DEVICE" - # Remove the file - rm -f $BUILD_IMG - rm -f $TARGET_FILENAME + # Remove the file + rm -f $BUILD_IMG + rm -f $TARGET_FILENAME - if [ "$INSTALLED_RELEASE" = "archlinux-frzr" ]; then - echo "VERIFIED" - else - exit 1 - fi + if [ "$INSTALLED_RELEASE" = "archlinux-frzr" ]; then + echo "VERIFIED" + else + exit 1 + fi else - exit 1 + exit 1 fi \ No newline at end of file diff --git a/test/test-install.sh b/test/test-install.sh index c839d1c..ab61e39 100755 --- a/test/test-install.sh +++ b/test/test-install.sh @@ -52,5 +52,5 @@ losetup -d "$MOUNTED_DEVICE" rm -f $BUILD_IMG if ! echo "$INSTALLED_RELEASE" | grep -Fq "chimeraos-45"; then - exit 1 + exit 1 fi \ No newline at end of file diff --git a/test/test-removal.sh b/test/test-removal.sh index 86448f2..34bd4dd 100755 --- a/test/test-removal.sh +++ b/test/test-removal.sh @@ -43,14 +43,14 @@ export SYSTEMD_RELAX_ESP_CHECKS=1 bash /workdir/frzr deploy chimeraos/chimeraos:43 if [ ! -d "$MOUNT_PATH/deployments/chimeraos-43_6978095" ]; then - exit 1 + exit 1 fi # deploy chimeraos-44_c3670dd bash /workdir/frzr deploy chimeraos/chimeraos:44 if [ ! -d "$MOUNT_PATH/deployments/chimeraos-43_6978095" ] || [ ! -d "$MOUNT_PATH/deployments/chimeraos-44_c3670dd" ]; then - exit 1 + exit 1 fi ls -lah "$MOUNT_PATH/deployments" @@ -59,7 +59,7 @@ ls -lah "$MOUNT_PATH/deployments" bash /workdir/frzr deploy chimeraos/chimeraos:45 if [ -d "$MOUNT_PATH/deployments/chimeraos-43_6978095" ] || [ ! -d "$MOUNT_PATH/deployments/chimeraos-44_c3670dd" ] || [ ! -d "$MOUNT_PATH/deployments/chimeraos-45_1e44050" ]; then - exit 1 + exit 1 fi ls -lah "$MOUNT_PATH/deployments" @@ -68,7 +68,7 @@ ls -lah "$MOUNT_PATH/deployments" bash /workdir/frzr deploy chimeraos/chimeraos:45-1 if [ -d "$MOUNT_PATH/deployments/chimeraos-44_c3670dd" ] || [ ! -d "$MOUNT_PATH/deployments/chimeraos-45_1e44050" ] || [ ! -d "$MOUNT_PATH/deployments/chimeraos-45-1_9a95912" ]; then - exit 1 + exit 1 fi # Umount the loopback device