diff --git a/arkdep b/arkdep index 13d4e44..60aff34 100755 --- a/arkdep +++ b/arkdep @@ -48,7 +48,7 @@ fi ## Set common variables # -declare -r arkdep_dir="$(readlink -m $ARKDEP_ROOT/arkdep/)" +declare -r arkdep_dir="$(readlink -m $ARKDEP_ROOT/arkdep)" # Override arkdep_boot if set, if not assume located inside of root if [[ -n $ARKDEP_BOOT ]]; then @@ -68,7 +68,7 @@ fi ## Load config file, unless we are running init # if [[ ! $1 == 'init' ]]; then - source $(readlink -m $arkdep_dir/config) + source $arkdep_dir/config # Set default variables if config variables are undefined [[ -z ${enable_overlay+x} ]] && enable_overlay=1 && printf '\e[1;33m\e[0m\e[1m enable_overlay not defined in config, using default\e[0m\n' @@ -103,14 +103,14 @@ cleanup_and_quit () { # Remove the subvolume we were working on # TODO: Make this a generic function and share with the removal of old images? if [[ -n ${data[0]} ]]; then - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/etc) ro false - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs) ro false - btrfs subvolume delete $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/etc) - btrfs subvolume delete $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs) - rm -rfv $(readlink -m $arkdep_dir/deployments/${data[0]}) \ - $(readlink -m $arkdep_boot/arkdep/${data[0]}) - rm -v $(readlink -m $arkdep_dir/cache/${data[0]}-*.img) \ - $(readlink -m $arkdep_boot/loader/entries/${data[0]}.conf) + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]}/rootfs/etc ro false + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]}/rootfs ro false + btrfs subvolume delete $arkdep_dir/deployments/${data[0]}/rootfs/etc + btrfs subvolume delete $arkdep_dir/deployments/${data[0]}/rootfs + rm -rfv $arkdep_dir/deployments/${data[0]} \ + $arkdep_boot/arkdep/${data[0]} + rm -v $arkdep_dir/cache/${data[0]}-*.img \ + $arkdep_boot/loader/entries/${data[0]}.conf fi exit 1 @@ -163,7 +163,7 @@ healthcheck () { # Warn if gpg check is enabled but no keys are installed if [[ ! $gpg_signature_check -eq 0 ]] && [[ ! -s $arkdep_dir/keys/trusted-keys ]]; then - printf "\e[1;33m\e[0m\e[1m gpg_signature_check is enabled but $(readlink -m $arkdep_dir/keys/trusted-keys) does not exist or is empty\n\e[0m" + printf "\e[1;33m\e[0m\e[1m gpg_signature_check is enabled but $arkdep_dir/keys/trusted-keys does not exist or is empty\n\e[0m" fi # If $1 is healthcheck it was manually called by the user @@ -203,9 +203,9 @@ done # Ensure minimum required storage is available, only run if new deployment will be made if [[ $1 == 'deploy' ]]; then - declare boot_storage_available=($(df --output=avail $(readlink -m $arkdep_boot))) + declare boot_storage_available=($(df --output=avail $arkdep_boot)) boot_storage_available=${boot_storage_available[1]} - declare root_storage_available=($(df --output=avail $(readlink -m $ARKDEP_ROOT/))) + declare root_storage_available=($(df --output=avail $ARKDEP_ROOT/)) root_storage_available=${root_storage_available[1]} # Check amount of available boot storage, do not run if set to 0 @@ -244,22 +244,22 @@ init () { # Create directory structure printf '\e[1;34m-->\e[0m\e[1m Creating directory structure\e[0m\n' - mkdir -pv $(readlink -m $arkdep_dir/deployments) \ - $(readlink -m $arkdep_dir/deployments) \ - $(readlink -m $arkdep_dir/cache) \ - $(readlink -m $arkdep_dir/templates) \ - $(readlink -m $arkdep_dir/overlay) \ - $(readlink -m $arkdep_dir/keys) \ - $(readlink -m $arkdep_dir/shared) || + mkdir -pv $arkdep_dir/deployments \ + $arkdep_dir/deployments \ + $arkdep_dir/cache \ + $arkdep_dir/templates \ + $arkdep_dir/overlay \ + $arkdep_dir/keys \ + $arkdep_dir/shared || cleanup_and_quit "Failed to create $arkdep_dir and related directories" # Create empty database files - touch $(readlink -m $arkdep_dir/tracker) - touch $(readlink -m $arkdep_dir/keys/trusted-keys) + touch $arkdep_dir/tracker + touch $arkdep_dir/keys/trusted-keys # Add home shared subvolume and make writable - btrfs subvolume create $(readlink -m $arkdep_dir/shared/home) || cleanup_and_quit "Failed to create home subvolume" - btrfs property set -f -ts $(readlink -m $arkdep_dir/shared/home) ro false + btrfs subvolume create $arkdep_dir/shared/home || cleanup_and_quit "Failed to create home subvolume" + btrfs property set -f -ts $arkdep_dir/shared/home ro false # Write default config file printf '\e[1;34m-->\e[0m\e[1m Adding default config file\e[0m\n' @@ -341,10 +341,10 @@ teardown () { fi # Remove all bootloader entries - rm -v $(grep -ril arkdep $(readlink -m $arkdep_boot/loader/entries)) + rm -v $(grep -ril arkdep $arkdep_boot/loader/entries) # Remove kernels and initramfs deployed by Arkdep - rm -rfv $(readlink -m $arkdep_boot/arkdep) + rm -rfv $arkdep_boot/arkdep # Ensure all nested volumes in arkdep are writable and remove for volume in $(btrfs subvolume list / | grep -oE '[^ ]+$' | grep "^$arkdep_dir" | tac); do @@ -396,14 +396,14 @@ remove_deployment () { declare -r target="${hits[0]}" # Ensure deployment is not currently active - if grep -q "$(readlink -m $arkdep_dir/deployments/$target/rootfs)" /proc/cmdline; then + if grep -q "$arkdep_dir/deployments/$target/rootfs" /proc/cmdline; then printf 'Target is currently active deployment\n' exit 1 fi # Remove bootloader entry - rm -rfv $(readlink -m $arkdep_boot/loader/entries/$target.conf) - rm -rfv $(readlink -m $arkdep_boot/arkdep/$target) + rm -rfv $arkdep_boot/loader/entries/$target.conf + rm -rfv $arkdep_boot/arkdep/$target # Ensure the deployment and all sub-volumes are writable for volume in $(btrfs subvolume list / | grep -oE '[^ ]+$' | grep $target); do @@ -411,7 +411,7 @@ remove_deployment () { done # Remove the deployment - rm -rf $(readlink -m $arkdep_dir/deployments/$target) + rm -rf $arkdep_dir/deployments/$target # Remove from tracker grep -v $1 $arkdep_dir/tracker > $arkdep_dir/tracker_tmp @@ -432,7 +432,7 @@ remove_deployment () { if [[ $clean_cache_on_remove -eq 1 ]]; then # Only attempt remove if file exists if ls $arkdep_dir/cache/ | grep $1; then - rm -v $(readlink -m $arkdep_dir/cache/$1.tar.*) + rm -v $arkdep_dir/cache/$1.tar.* fi fi @@ -492,7 +492,7 @@ deploy () { else # Find full name in cache, exclude sig files, if no hit quit with error - declare cache_hits=($(ls $(readlink -m $arkdep_dir/cache) | grep -E "^$deploy_version" | grep -v '.sig$')) + declare cache_hits=($(ls $arkdep_dir/cache | grep -E "^$deploy_version" | grep -v '.sig$')) # Temporary var to store the delimited file found in cache declare data_inter=() @@ -548,7 +548,7 @@ deploy () { printf "\e[1;34m-->\e[0m\e[1m Downloading disk image\e[0m\n" # Download the tarball if not yet downloaded if [[ ! -e $arkdep_dir/cache/${data[0]}.tar.${data[1]} ]]; then - wget -q --show-progress -P $(readlink -m $arkdep_dir/cache/) "$repo_url/$deploy_target/${data[0]}.tar.${data[1]}" || + wget -q --show-progress -P $arkdep_dir/cache/ "$repo_url/$deploy_target/${data[0]}.tar.${data[1]}" || cleanup_and_quit 'Failed to download tarball' # Download GPG signature, only perform check if not disabled by user and keychain exists @@ -556,7 +556,7 @@ deploy () { # Download gpg signature if not yet in cache if [[ ! -s $arkdep_dir/cache/${data[0]}.tar.${data[1]}.sig ]]; then - wget -q --show-progress -P $(readlink -m $arkdep_dir/cache/) "$repo_url/$deploy_target/${data[0]}.tar.${data[1]}.sig" + wget -q --show-progress -P $arkdep_dir/cache/ "$repo_url/$deploy_target/${data[0]}.tar.${data[1]}.sig" sig_exitcode=$? fi @@ -590,7 +590,7 @@ deploy () { elif [[ ${data[2]} != '-' ]]; then # If GPG check not triggered instead check hash, unless defined as - printf '\e[1;34m-->\e[0m\e[1m Validating integrity\e[0m\n' - sha1sum "$(readlink -m $arkdep_dir/cache/${data[0]}.tar.${data[1]})" | + sha1sum $arkdep_dir/cache/${data[0]}.tar.${data[1]} | grep "${data[2]}" || cleanup_and_quit "Checksum does not match the one defined in database\e[0m\n" fi @@ -599,48 +599,48 @@ deploy () { printf '\e[1;34m-->\e[0m\e[1m Writing root\e[0m\n' # Create directory using unique deployment name - mkdir -pv $(readlink -m $arkdep_dir/deployments/${data[0]}) || cleanup_and_quit 'Failed to create deployment directory' + mkdir -pv $arkdep_dir/deployments/${data[0]} || cleanup_and_quit 'Failed to create deployment directory' if [[ ! -e $arkdep_dir/cache/${data[0]}-rootfs.img ]]; then - tar -xf $(readlink -m $arkdep_dir/cache/${data[0]}.tar.${data[1]}) -C $(readlink -m $arkdep_dir/cache/) "./${data[0]}-rootfs.img" || + tar -xf $arkdep_dir/cache/${data[0]}.tar.${data[1]} -C $arkdep_dir/cache/ "./${data[0]}-rootfs.img" || cleanup_and_quit 'Failed to extract root' fi # Write the root image - btrfs receive -f $(readlink -m $arkdep_dir/cache/${data[0]}-rootfs.img) $(readlink -m $arkdep_dir/deployments/${data[0]}) || + btrfs receive -f $arkdep_dir/cache/${data[0]}-rootfs.img $arkdep_dir/deployments/${data[0]} || cleanup_and_quit 'Failed to receive root' # Cleanup root image - rm $(readlink -m $arkdep_dir/cache/${data[0]}-rootfs.img) + rm $arkdep_dir/cache/${data[0]}-rootfs.img # Extract the etc image if not yet extracted printf '\e[1;34m-->\e[0m\e[1m Writing etc\e[0m\n' if [[ ! -e $arkdep_dir/cache/${data[0]}-etc.img ]]; then - tar -xf $(readlink -m $arkdep_dir/cache/${data[0]}.tar.${data[1]}) -C $(readlink -m $arkdep_dir/cache/) "./${data[0]}-etc.img" || + tar -xf $arkdep_dir/cache/${data[0]}.tar.${data[1]} -C $arkdep_dir/cache/ "./${data[0]}-etc.img" || cleanup_and_quit 'failed to extract etc' fi # Write the etc image and create var directory, we have to unlock rootfs temporarily to do this - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs) ro false || + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]}/rootfs ro false || cleanup_and_quit 'Failed to unlock root to write etc' - btrfs receive -f $(readlink -m $arkdep_dir/cache/${data[0]}-etc.img) $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/) || + btrfs receive -f $arkdep_dir/cache/${data[0]}-etc.img $arkdep_dir/deployments/${data[0]}/rootfs/ || cleanup_and_quit 'Failed to receive etc' printf '\e[1;34m-->\e[0m\e[1m Ensure var, root and arkdep mountpoints exist\e[0m\n' - mkdir -pv $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/var) - mkdir -pv $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/arkdep) + mkdir -pv $arkdep_dir/deployments/${data[0]}/rootfs/var + mkdir -pv $arkdep_dir/deployments/${data[0]}/rootfs/arkdep # Lock the root volume again - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs) ro true || + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]}/rootfs ro true || cleanup_and_quit 'Failed to lock root' # Unlock the etc deployment - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/etc) ro false || + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]}/rootfs/etc ro false || cleanup_and_quit 'Failed to unlock root to write etc' # Cleanup etc image - rm $(readlink -m $arkdep_dir/cache/${data[0]}-etc.img) + rm $arkdep_dir/cache/${data[0]}-etc.img # Write the var image if [[ ! -e $arkdep_dir/shared/var ]]; then @@ -648,11 +648,11 @@ deploy () { # Extract the var image if not yet extracted if [[ ! -e $arkdep_dir/cache/${data[0]}-var.img ]]; then - tar -xf $(readlink -m $arkdep_dir/cache/${data[0]}.tar.${data[1]}) -C $(readlink -m $arkdep_dir/cache/) "./${data[0]}-var.img" || + tar -xf $arkdep_dir/cache/${data[0]}.tar.${data[1]} -C $arkdep_dir/cache/ "./${data[0]}-var.img" || cleanup_and_quit 'failed to extract var' fi - btrfs receive -f $(readlink -m $arkdep_dir/cache/${data[0]}-var.img) $(readlink -m $arkdep_dir/shared/) || + btrfs receive -f $arkdep_dir/cache/${data[0]}-var.img $arkdep_dir/shared/ || cleanup_and_quit 'Failed to receive var' else # Notify if var is not deployed @@ -660,11 +660,11 @@ deploy () { fi # Make var writable - btrfs property set -f -ts $(readlink -m $arkdep_dir/shared/var) ro false || + btrfs property set -f -ts $arkdep_dir/shared/var ro false || cleanup_and_quit 'Failed to unlock var' # Cleanup var image - rm $(readlink -m $arkdep_dir/cache/${data[0]}-var.img) + rm $arkdep_dir/cache/${data[0]}-var.img # Add overlay if enabled if [[ $enable_overlay -eq 1 ]]; then @@ -698,23 +698,23 @@ deploy () { # Unlock root if required if [[ $overlay_unlock_root -eq 1 ]]; then - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}) ro false + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]} ro false fi - cp -rv $(readlink -m $arkdep_dir/overlay/*) $(readlink -m /$arkdep_dir/deployments/${data[0]}/rootfs/) + cp -rv $arkdep_dir/overlay/* $arkdep_dir/deployments/${data[0]}/rootfs/ # Lock root again if required if [[ $overlay_unlock_root -eq 1 ]]; then - btrfs property set -f -ts $(readlink -m $arkdep_dir/deployments/${data[0]}) ro true + btrfs property set -f -ts $arkdep_dir/deployments/${data[0]} ro true fi fi printf '\e[1;34m-->\e[0m\e[1m Copying kernel image\e[0m\n' # Get list of all available kernels kernels_installed=($(ls $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/modules/)) - mkdir -pv $(readlink -m $arkdep_boot/arkdep/${data[0]}) + mkdir -pv $arkdep_boot/arkdep/${data[0]} # Deploy kernel to /boot, deploy first hit of kernels_installed - cp -v $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/modules/${kernels_installed[0]}/vmlinuz) $(readlink -m $arkdep_boot/arkdep/${data[0]}/) || + cp -v $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/modules/${kernels_installed[0]}/vmlinuz) $arkdep_boot/arkdep/${data[0]}/ || cleanup_and_quit 'Failed to copy kernel image' # Deploy CPU firmware to boot @@ -723,8 +723,8 @@ deploy () { for ucode in $(ls $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/ | grep ucode); do # If CPU firmware present in both image and install - if ! cmp --silent $(readlink -m $arkdep_boot/$ucode) $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/$ucode; then - cp -v $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/$ucode) $(readlink -m $arkdep_boot/$ucode) || + if ! cmp --silent $arkdep_boot/$ucode $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/$ucode; then + cp -v $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/$ucode $arkdep_boot/$ucode || cleanup_and_quit 'Failed to copy microcode' fi done @@ -733,11 +733,11 @@ deploy () { # Install kernel and generate initramfs printf '\e[1;34m-->\e[0m\e[1m Generating initramfs\e[0m\n' - dracut -q -k $(readlink -m $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/modules/${kernels_installed[0]}) \ - --kernel-image $(readlink -m $arkdep_boot/arkdep/${data[0]}/vmlinuz) \ + dracut -q -k $arkdep_dir/deployments/${data[0]}/rootfs/usr/lib/modules/${kernels_installed[0]} \ + --kernel-image $arkdep_boot/arkdep/${data[0]}/vmlinuz \ --kver ${kernels_installed[0]} \ --force \ - $(readlink -m $arkdep_boot/arkdep/${data[0]}/initramfs-linux.img) || cleanup_and_quit 'Failed to generate initramfs' + $arkdep_boot/arkdep/${data[0]}/initramfs-linux.img || cleanup_and_quit 'Failed to generate initramfs' # Add to database printf '\e[1;34m-->\e[0m\e[1m Updating database\e[0m\n' @@ -748,7 +748,7 @@ deploy () { # Deploy bootloader configuration # also insert newline printf '\n\e[1;34m-->\e[0m\e[1m Adding bootloader entry\e[0m\n' - sed "s/%target%/${data[0]}/" $arkdep_dir/templates/systemd-boot > $(readlink -m $arkdep_boot/loader/entries/${data[0]}.conf) + sed "s/%target%/${data[0]}/" $arkdep_dir/templates/systemd-boot > $arkdep_boot/loader/entries/${data[0]}.conf # Set new deployment as default bootloader entry printf '\e[1;34m-->\e[0m\e[1m Setting new bootloader entry as default\e[0m\n'