2023-06-21 18:36:52 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# Print manual if no parameters provided or invalid amount of parameters is provided
|
|
|
|
if [[ ! -n $1 || -n $2 ]]; then
|
|
|
|
cat <<- END
|
2023-09-21 21:51:57 +02:00
|
|
|
Usage: arkdep-build [variant]
|
2023-06-21 18:36:52 +02:00
|
|
|
Variants:
|
2023-08-14 08:53:26 +02:00
|
|
|
archlinux Plain Arch Linux TTY image
|
2023-06-21 18:36:52 +02:00
|
|
|
arkanelinux Arkane Linux GNOME image
|
|
|
|
|
|
|
|
Variants are loaded based on their directory names, the ones listed here
|
2023-08-14 08:35:35 +02:00
|
|
|
are included by default.
|
2023-08-14 08:50:48 +02:00
|
|
|
|
|
|
|
Variables:
|
2023-09-21 21:56:37 +02:00
|
|
|
ARKDEP_NO_TAR Do not create a compressed tarball, only create the images
|
2023-10-08 01:23:01 +02:00
|
|
|
ARKDEP_CUSTOM_NAME Define a custom image name
|
|
|
|
ARKDEP_OUTPUT_TARGET Overwrite location to which images will be written
|
2023-10-08 06:08:53 +02:00
|
|
|
ARKDEP_CONFIGS Define directory in which build will search for configuration files
|
2024-02-24 05:36:24 +01:00
|
|
|
ARKDEP_NO_CLEANUP Do not remove the temporary rootfs upon error or exit
|
2024-02-24 14:38:33 +01:00
|
|
|
ARKDEP_STATIC_WORKDIR Reset workdir back to workable state if still present
|
2023-06-21 18:36:52 +02:00
|
|
|
END
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Common functions
|
|
|
|
#
|
|
|
|
# Cleanup and quit if error
|
|
|
|
cleanup_and_quit () {
|
|
|
|
|
|
|
|
# If any paramters are passed we will assume it to be an error
|
2023-06-22 02:27:51 +02:00
|
|
|
[[ -n $1 ]] && printf "\e[1;31m<#>\e[0m $*\e[0m\n" >&2
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2024-02-24 05:36:24 +01:00
|
|
|
if [[ $ARKDEP_NO_CLEANUP -eq 1 ]]; then
|
|
|
|
printf 'Cleanup disabled, not running cleanup\n'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-29 21:28:37 +01:00
|
|
|
umount -l $workdir
|
2023-09-10 08:26:43 +02:00
|
|
|
|
2023-06-26 00:32:59 +02:00
|
|
|
btrfs property set -ts $workdir ro false
|
|
|
|
btrfs property set -ts $workdir/etc ro false
|
|
|
|
btrfs property set -ts $workdir/var ro false
|
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
# Remove temporary btrfs volumes
|
2023-08-13 06:13:19 +02:00
|
|
|
rm -rf $workdir/etc \
|
2023-06-26 00:32:59 +02:00
|
|
|
$workdir/var \
|
2023-08-13 06:13:19 +02:00
|
|
|
$workdir
|
2023-06-21 18:36:52 +02:00
|
|
|
|
|
|
|
# Quit program if argument provided to function
|
2024-02-22 07:45:21 +01:00
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
|
|
|
# Otherwise just quit, there is no error
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-08 01:23:01 +02:00
|
|
|
## Set common variables
|
|
|
|
#
|
|
|
|
declare -r workdir='/var/tmp/rootfs'
|
|
|
|
declare -r variant="$1"
|
2024-02-22 07:45:21 +01:00
|
|
|
|
|
|
|
if [[ -v ARKDEP_CONFIGS ]]; then
|
|
|
|
declare -r configsdir="$ARKDEP_CONFIGS"
|
|
|
|
else
|
|
|
|
declare -r configsdir="$(readlink -m ./arkdep-build.d/)"
|
|
|
|
fi
|
|
|
|
|
2024-03-09 03:40:07 +01:00
|
|
|
# Before we continue setting variables, lets first ensure the configsdir actually exist
|
|
|
|
# We do this now to give better error reporting to the user
|
|
|
|
if [[ ! -d $configsdir ]]; then
|
|
|
|
printf "\e[1;31m<#>\e[0m\e[1m $configsdir does not exist, are you located inside of the configuration directory's parent directory?\n\e[0m"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-22 07:45:21 +01:00
|
|
|
declare -r variantdir="$configsdir/$variant"
|
2024-03-09 03:40:07 +01:00
|
|
|
declare -r type="$(cat $(readlink -m $variantdir/type) 2> /dev/null || (printf '\e[1;31m<#>\e[0m\e[1m Failed to get build type\n\e[0m'; exit 1))"
|
2024-02-22 07:45:21 +01:00
|
|
|
|
|
|
|
if [[ -v ARKDEP_OUTPUT_TARGET ]]; then
|
|
|
|
declare -r output_target="$ARKDEP_OUTPUT_TARGET"
|
|
|
|
else
|
2023-10-08 01:23:01 +02:00
|
|
|
declare -r output_target="$(pwd)/target/"
|
2024-02-22 07:45:21 +01:00
|
|
|
fi
|
2023-10-08 01:23:01 +02:00
|
|
|
|
2024-02-22 07:45:21 +01:00
|
|
|
## Set common functions
|
|
|
|
#
|
|
|
|
# Generate a 42 character long random string, used for generating psuedo-random image names
|
|
|
|
# Unless overwritten with $ARKDEP_CUSTOM_NAME
|
2023-08-11 08:04:36 +02:00
|
|
|
gen_random_string () {
|
|
|
|
|
2023-10-08 01:23:01 +02:00
|
|
|
if [[ -v ARKDEP_CUSTOM_NAME ]]; then
|
|
|
|
random=$ARKDEP_CUSTOM_NAME
|
2023-08-14 07:23:31 +02:00
|
|
|
else
|
|
|
|
random=$(openssl rand -hex 100 | head -c 42)
|
|
|
|
fi
|
2023-08-11 08:04:36 +02:00
|
|
|
|
|
|
|
printf "${random}\n"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
## Error checking
|
|
|
|
#
|
|
|
|
# Quit if not root
|
2024-02-22 07:45:21 +01:00
|
|
|
if [[ ! $EUID -eq 0 ]]; then
|
2024-03-09 03:40:07 +01:00
|
|
|
printf '\e[1;31m<#>\e[0m\e[1m This program has to be run as root\n\e[0m'
|
2023-06-21 18:36:52 +02:00
|
|
|
exit 1
|
2024-02-22 07:45:21 +01:00
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
|
|
|
# Check if all dependencies are installed, quit if not
|
|
|
|
for prog in btrfs pacstrap; do
|
|
|
|
if ! command -v $prog > /dev/null; then
|
2023-06-22 02:27:51 +02:00
|
|
|
printf "\e[1;31m<#>\e[0m\e[1m Failed to locate $prog, ensure it is installed\e[0m\n"
|
2023-06-21 18:36:52 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check if requested variant exists
|
2024-02-22 07:45:21 +01:00
|
|
|
if [[ ! -d $variantdir ]]; then
|
2024-03-09 03:40:07 +01:00
|
|
|
printf '\e[1;31m<#>\e[0m\e[1m The requested variant does not exist\e[0m\n'
|
2023-06-21 18:36:52 +02:00
|
|
|
exit 1
|
2024-02-22 07:45:21 +01:00
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2023-06-22 01:53:19 +02:00
|
|
|
## Variants
|
|
|
|
#
|
2023-06-21 18:36:52 +02:00
|
|
|
# Build archlinux type image
|
2023-06-25 20:27:47 +02:00
|
|
|
if [[ $type == 'archlinux' ]]; then
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2024-02-22 07:45:21 +01:00
|
|
|
# Ensure bootstrap.list exists, if not error and quit
|
|
|
|
if [[ ! -e $variantdir/bootstrap.list ]]; then
|
2024-03-09 03:40:07 +01:00
|
|
|
printf "\e[1;31m<#>\e[0m\e[1m The required file 'bootstrap.list' is not preset in $(readlink -m $variantdir)\e[0m\n"
|
2023-06-21 18:36:52 +02:00
|
|
|
exit 1
|
2023-08-10 06:44:20 +02:00
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2023-06-22 02:27:51 +02:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Started Arch linux image build\e[0m\n'
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2024-02-24 14:38:33 +01:00
|
|
|
# Allow user to reuse subvolumes for testing
|
|
|
|
if [[ ! $ARKDEP_STATIC_WORKDIR -eq 1 ]] && [[ ! -d $workdir ]]; then
|
|
|
|
# Create temporary Btrfs subvolume
|
|
|
|
printf "\e[1;34m-->\e[0m\e[1m Creating temporary Btrfs subvolumes at $(readlink -m $workdir)\e[0m\n"
|
|
|
|
btrfs subvolume create $workdir || cleanup_and_quit "Failed to create btrfs subvolume $(readlink -m $workdir)"
|
|
|
|
btrfs subvolume create $workdir/etc || cleanup_and_quit "Failed to create btrfs subvolume $(readlink -m $workdir/etc)"
|
|
|
|
btrfs subvolume create $workdir/var || cleanup_and_quit "Failed to create btrfs subvolume $(readlink -m $workdir/var)"
|
|
|
|
elif [[ ! $ARKDEP_STATIC_WORKDIR -eq 1 ]]; then
|
|
|
|
cleanup_and_quit "Failed to create btrfs subvolume $workdir for it already exists"
|
|
|
|
else
|
|
|
|
printf "\e[1;34m-->\e[0m\e[1m Returning $(readlink -m $workdir) to a workable state, this should be done for testing only\e[0m\n"
|
|
|
|
|
|
|
|
# Get the rootfs working again, this should only be done for testing
|
|
|
|
for file in passwd group shadow; do
|
|
|
|
mv $workdir/usr/lib/$file $workdir/etc/$file
|
|
|
|
done
|
|
|
|
|
|
|
|
btrfs property set -ts $workdir ro false || cleanup_and_quit 'Failed to set root to read-only'
|
|
|
|
btrfs property set -ts $workdir/etc ro false || cleanup_and_quit 'Failed to set etc to read-only'
|
|
|
|
btrfs property set -ts $workdir/var ro false || cleanup_and_quit 'Failed to set var to read-only'
|
|
|
|
|
|
|
|
echo 'root:x:0:0::/root:/bin/bash' | tee -a $workdir/etc/passwd
|
|
|
|
echo 'root:x:0:root' | tee -a $workdir/etc/group
|
|
|
|
echo 'root:!::::::' | tee -a $workdir/etc/shadow
|
|
|
|
|
|
|
|
rm $workdir/var/usr/local
|
|
|
|
mv $workdir/var/usrlocal $workdir/usr/local
|
|
|
|
|
|
|
|
rm $workdir/usr/lib/locale
|
|
|
|
mv $workdir/var/usrliblocale $workdir/usr/lib/locale
|
|
|
|
|
|
|
|
rm $workdir/var/roothome
|
|
|
|
mv $workdir/var/roothome $workdir/root
|
|
|
|
|
|
|
|
rm $workdir/opt
|
|
|
|
mv $workdir/var/opt $workdir/opt
|
|
|
|
|
|
|
|
# srv symlink
|
|
|
|
rm $workdir/srv
|
|
|
|
mv $workdir/var/srv $workdir/srv
|
|
|
|
|
|
|
|
# mnt symlink
|
|
|
|
rm $workdir/mnt
|
|
|
|
mv $workdir/var/mnt $workdir/mnt
|
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2023-09-10 08:26:43 +02:00
|
|
|
printf "\e[1;34m-->\e[0m\e[1m Creating bind mount at $(readlink -m $workdir)\e[0m\n"
|
|
|
|
mount --bind $workdir $workdir
|
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
# Read base package list and install base system
|
2024-02-22 07:45:21 +01:00
|
|
|
readarray bootstrap_packages < $variantdir/bootstrap.list
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Installing base packages\e[0m\n'
|
2024-02-28 08:58:28 +01:00
|
|
|
# If pacman.conf is available in overlay, use it
|
2024-02-28 09:55:50 +01:00
|
|
|
if [[ -f $variantdir/overlay/etc/pacman.conf ]]; then
|
|
|
|
pacstrap -c -C $variantdir/overlay/etc/pacman.conf $workdir ${bootstrap_packages[*]} || cleanup_and_quit 'Failed to install secondary package list'
|
2024-02-28 08:58:28 +01:00
|
|
|
else
|
|
|
|
pacstrap -c $workdir ${bootstrap_packages[*]} || cleanup_and_quit 'Failed to install secondary package list'
|
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2023-08-13 06:13:19 +02:00
|
|
|
# If overlay directory exists in variant copy it's contents to the temporary subvolume
|
2024-02-22 07:45:21 +01:00
|
|
|
if [[ -d $variantdir/overlay ]]; then
|
2023-12-11 22:23:06 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Copying overlay to root\e[0m\n'
|
2024-02-22 07:45:21 +01:00
|
|
|
cp -rv $variantdir/overlay/* $workdir/
|
2023-08-13 06:13:19 +02:00
|
|
|
fi
|
2023-08-10 06:44:20 +02:00
|
|
|
|
2024-02-21 11:33:09 +01:00
|
|
|
# Run post-bootstrap script if exists
|
2024-02-22 14:48:01 +01:00
|
|
|
if [[ -f $variantdir/extensions/post-bootstrap.sh ]]; then
|
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Running post-bootstrap extension\e[0m\n'
|
|
|
|
(source $variantdir/extensions/post-bootstrap.sh)
|
2024-02-21 11:33:09 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-13 06:13:19 +02:00
|
|
|
# Read package list and install secondary system components, skip if not used
|
2024-02-22 07:45:21 +01:00
|
|
|
if [[ -e $variantdir/package.list ]]; then
|
2023-09-19 00:23:53 +02:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Installing secondary packages\e[0m\n'
|
2024-02-29 20:32:40 +01:00
|
|
|
|
|
|
|
# Mount the pacman cache
|
|
|
|
mount --bind /var/cache/pacman/pkg $workdir/var/cache/pacman/pkg
|
|
|
|
|
|
|
|
# Read package list and install
|
2024-02-22 07:45:21 +01:00
|
|
|
readarray packages < $variantdir/package.list
|
2023-06-21 18:36:52 +02:00
|
|
|
arch-chroot $workdir pacman -S --noconfirm ${packages[*]} || cleanup_and_quit 'Failed to install base packages'
|
2024-02-29 20:32:40 +01:00
|
|
|
|
|
|
|
# Unmount pacman cache
|
2024-02-29 21:28:37 +01:00
|
|
|
umount -l $workdir/var/cache/pacman/pkg
|
2023-06-21 18:36:52 +02:00
|
|
|
fi
|
|
|
|
|
2024-02-21 11:33:09 +01:00
|
|
|
# Run post-install script if exists
|
2024-02-22 14:48:01 +01:00
|
|
|
if [[ -f $variantdir/extensions/post-install.sh ]]; then
|
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Running post-install extension\e[0m\n'
|
|
|
|
(source $variantdir/extensions/post-install.sh)
|
2024-02-21 11:33:09 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-09 08:09:20 +02:00
|
|
|
# Clear pacman cache
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Clearing pacman cache\e[0m\n'
|
2023-10-24 13:50:33 +00:00
|
|
|
arch-chroot $workdir pacman -Scc <<< Y <<< Y
|
2023-12-09 04:06:26 +01:00
|
|
|
# Insert a new line to clean, the previous command fails to do so
|
|
|
|
printf '\n'
|
2023-08-09 08:09:20 +02:00
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
# Remove subvolumes created by systemd
|
|
|
|
[[ -d $workdir/var/lib/portables ]] &&
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Removing systemd subvolume var/lib/portables\e[0m\n'
|
2023-06-21 18:36:52 +02:00
|
|
|
btrfs subvolume delete $workdir/var/lib/portables
|
|
|
|
[[ -d $workdir/var/lib/machines ]] &&
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Removing systemd subvolume var/lib/machines\e[0m\n'
|
2023-06-21 18:36:52 +02:00
|
|
|
btrfs subvolume delete $workdir/var/lib/machines
|
|
|
|
|
2023-09-19 00:23:53 +02:00
|
|
|
# Make /usr/local symlink in var
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Moving dirs to var and creating symlinks\e[0m\n'
|
2023-09-19 00:23:53 +02:00
|
|
|
mv $workdir/usr/local $workdir/var/usrlocal || cleanup_and_quit 'Failed to move usr/local to var/usrlocal'
|
2023-11-26 11:50:38 +00:00
|
|
|
ln -sv ../var/usrlocal $workdir/usr/local || cleanup_and_quit 'Failed to create usrlocal symlink'
|
2023-09-19 00:23:53 +02:00
|
|
|
|
2023-10-24 13:11:38 +00:00
|
|
|
# locale symlink
|
2023-10-18 17:50:52 +02:00
|
|
|
mv $workdir/usr/lib/locale $workdir/var/usrliblocale || cleanup_and_quit 'Failed to move usr/local to var/usrlocal'
|
2023-10-26 18:58:35 +00:00
|
|
|
ln -sv ../../../var/usrliblocale $workdir/usr/lib/locale || cleanup_and_quit 'Failed to create usrlocal symlink'
|
2023-10-24 13:11:38 +00:00
|
|
|
|
|
|
|
# roothome symlink
|
|
|
|
mv $workdir/root $workdir/var/roothome || cleanup_and_quit 'Failed to move root to var/roothome'
|
2023-10-24 14:52:28 +00:00
|
|
|
ln -sv var/roothome $workdir/root || cleanup_and_quit 'Failed to create roothome symlink'
|
2023-10-24 13:11:38 +00:00
|
|
|
|
|
|
|
# Opt symlink
|
|
|
|
mv $workdir/opt $workdir/var/opt || cleanup_and_quit 'Failed to move opt to var/opt'
|
2023-10-24 14:52:28 +00:00
|
|
|
ln -sv var/opt $workdir/opt || cleanup_and_quit 'Failed to create opt symlink'
|
2023-10-24 13:11:38 +00:00
|
|
|
|
|
|
|
# srv symlink
|
|
|
|
mv $workdir/srv $workdir/var/srv || cleanup_and_quit 'Failed to move srv to var/srv'
|
2023-10-24 14:52:28 +00:00
|
|
|
ln -sv var/srv $workdir/srv || cleanup_and_quit 'Failed to create srv symlink'
|
2023-10-18 17:50:52 +02:00
|
|
|
|
2023-10-24 14:44:51 +00:00
|
|
|
# mnt symlink
|
|
|
|
mv $workdir/mnt $workdir/var/mnt || cleanup_and_quit 'Failed to move mnt to var/mnt'
|
2023-10-24 14:52:28 +00:00
|
|
|
ln -sv var/mnt $workdir/mnt || cleanup_and_quit 'Failed to create mnt symlink'
|
2023-10-24 14:44:51 +00:00
|
|
|
|
2024-03-03 14:44:37 +01:00
|
|
|
# NetworkManager system-connections symlink if installed
|
|
|
|
if [[ -d $workdir/etc/NetworkManager ]]; then
|
2024-03-03 15:20:12 +01:00
|
|
|
mv $workdir/etc/NetworkManager/system-connections $workdir/var/nm-system-connections || cleanup_and_quit 'Failed to move etc/NetworkManager/system-connections to var/nm-system-connections'
|
2024-03-03 14:44:37 +01:00
|
|
|
ln -sv ../../var/nm-system-connections $workdir/etc/NetworkManager/system-connections || cleanup_and_quit 'Failed to create nm-system-connections symlink'
|
|
|
|
fi
|
|
|
|
|
2024-02-24 13:33:57 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Moving passwd, shadow and group files to usr/lib\e[0m\n'
|
2023-10-26 18:10:48 +00:00
|
|
|
|
|
|
|
# Create second passwd, group and shadow file in usr/lib and configure
|
|
|
|
for file in passwd group shadow; do
|
|
|
|
grep -v "^root:" $workdir/etc/$file > $workdir/usr/lib/$file
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove all users except for root, is typically overwritten by user overlay but
|
|
|
|
# may be used during os installation as a template
|
|
|
|
for file in passwd group shadow; do
|
|
|
|
grep "^root:" $workdir/etc/$file > $workdir/etc/$file-tmp
|
|
|
|
mv $workdir/etc/$file-tmp $workdir/etc/$file
|
|
|
|
done
|
|
|
|
|
|
|
|
# Ensure passwd/group/shadow permissions are set properly
|
2023-11-06 19:46:07 +00:00
|
|
|
chmod 600 $workdir/etc/shadow $workdir/usr/lib/shadow
|
|
|
|
chmod 644 $workdir/etc/{passwd,group} $workdir/usr/lib/{passwd,group}
|
2023-10-26 18:10:48 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# nss-switch.conf is added using the overlay
|
|
|
|
#
|
|
|
|
|
|
|
|
# Remove passwd/group/shadow backup files
|
|
|
|
rm $workdir/etc/{passwd-,shadow-,group-}
|
|
|
|
|
2024-02-24 13:33:57 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Moving CPU microcode to usr/lib\e[0m\n'
|
|
|
|
# Move CPU firmware to /usr/lib if present
|
|
|
|
mv $workdir/boot/*-ucode.img $workdir/usr/lib/
|
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
# Make subvolume read-only
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Adding read-only property to subvolumes\e[0m\n'
|
2023-09-19 00:23:53 +02:00
|
|
|
btrfs property set -ts $workdir ro true || cleanup_and_quit 'Failed to set root to read-only'
|
|
|
|
btrfs property set -ts $workdir/etc ro true || cleanup_and_quit 'Failed to set etc to read-only'
|
|
|
|
btrfs property set -ts $workdir/var ro true || cleanup_and_quit 'Failed to set var to read-only'
|
2023-06-21 18:36:52 +02:00
|
|
|
|
2023-08-11 08:04:36 +02:00
|
|
|
# Generate random name for new image
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Generating psuedo-random image name\e[0m\n'
|
2023-08-11 08:04:36 +02:00
|
|
|
declare -r image_name=$(gen_random_string)
|
2023-08-14 07:23:31 +02:00
|
|
|
printf "$image_name\n"
|
2023-08-11 08:04:36 +02:00
|
|
|
|
|
|
|
# Create dir for storing the images
|
|
|
|
mkdir -vp $(readlink -m $output_target/$image_name)
|
|
|
|
|
2023-06-21 18:36:52 +02:00
|
|
|
# Write subvolume to image
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Creating images\e[0m\n'
|
2023-08-13 06:13:19 +02:00
|
|
|
btrfs send -f $output_target/$image_name/$image_name-rootfs.img $workdir
|
|
|
|
btrfs send -f $output_target/$image_name/$image_name-etc.img $workdir/etc
|
|
|
|
btrfs send -f $output_target/$image_name/$image_name-var.img $workdir/var
|
|
|
|
|
2023-09-21 21:56:37 +02:00
|
|
|
if [[ ! -v ARKDEP_NO_TAR ]]; then
|
2023-12-11 22:11:25 +01:00
|
|
|
printf '\e[1;34m-->\e[0m\e[1m Compressing images\e[0m\n'
|
2023-08-14 19:08:51 +02:00
|
|
|
tar -cv -I 'zstd -12 -T0 ' -f $output_target/$image_name.tar.zst -C $output_target/$image_name .
|
2023-08-14 08:50:48 +02:00
|
|
|
fi
|
2023-06-21 18:36:52 +02:00
|
|
|
|
|
|
|
cleanup_and_quit
|
2023-08-11 08:04:36 +02:00
|
|
|
|
2023-09-16 18:04:30 +02:00
|
|
|
fi
|