[arkdep] Implement initial layer command
This commit is contained in:
parent
4c6b7197e4
commit
d543f685fb
1 changed files with 83 additions and 0 deletions
83
arkdep
83
arkdep
|
@ -28,6 +28,7 @@ declare -r dist_load_extensions=0
|
|||
declare -r dist_remove_tar_after_deployment=1
|
||||
declare -r dist_update_diff_style='list'
|
||||
declare -r dist_interactive_mode=1
|
||||
declare -r dist_package_layer_command='pacman -Syy --needed --noconfirm'
|
||||
|
||||
# systemd-boot configuration
|
||||
declare -r boot_entry_title='Arkane Linux - Arkdep'
|
||||
|
@ -134,6 +135,9 @@ if [[ ! $1 == 'init' ]]; then
|
|||
[[ -z ${interactive_mode+x} ]] &&
|
||||
interactive_mode=$dist_interactive_mode &&
|
||||
printf '\e[1;33m<!>\e[0m\e[1m interactive_mode not defined in config, using default\e[0m\n'
|
||||
[[ -z ${package_layer_command+x} ]] &&
|
||||
package_layer_command=$dist_package_layer_command &&
|
||||
printf '\e[1;33m<!>\e[0m\e[1m package_layer_command not defined in config, using default\e[0m\n'
|
||||
fi
|
||||
|
||||
## Common functions
|
||||
|
@ -1257,6 +1261,82 @@ deploy () {
|
|||
|
||||
}
|
||||
|
||||
# Install a package and add it to the layer tracker
|
||||
layer () {
|
||||
|
||||
# If no installation candidates provided
|
||||
if [[ $# -eq 1 ]]; then
|
||||
cleanup_and_quit 'No layer candidates provided'
|
||||
fi
|
||||
|
||||
# By default, as it is discouraged, the layer tracker file is only created upon calling this function
|
||||
# Create layer tracker file if it does not yet exist
|
||||
if [[ ! -f $arkdep_dir/layer ]]; then
|
||||
printf "\e[1;33m<!>\e[0m\e[1m Creating new layer tracker file\e[0m\n"
|
||||
touch $arkdep_dir/layer
|
||||
fi
|
||||
|
||||
# Index layer tracker list
|
||||
declare -r layered=($(cat $arkdep_dir/layer))
|
||||
|
||||
# Program list with duplicates removed
|
||||
declare progs_clean=()
|
||||
|
||||
# Check if prog is already in list, if not add to progs_clean
|
||||
if [[ ${#layered[@]} -gt 0 ]]; then
|
||||
for prog in ${@:2}; do
|
||||
for layer in ${layered[@]}; do
|
||||
# If program is already present in layer tracker it can be ignored
|
||||
if [[ $layer == $prog ]]; then
|
||||
printf "\e[1;33m<!>\e[0m\e[1m $prog is already in layer tracker file and will be ignored\e[0m\n"
|
||||
declare layer_matched=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Add program to layer list unless duplicate
|
||||
if [[ $layer_matched -ne 1 ]]; then
|
||||
progs_clean+=($prog)
|
||||
fi
|
||||
|
||||
unset layer_matched
|
||||
done
|
||||
else
|
||||
progs_clean=(${@:2})
|
||||
fi
|
||||
|
||||
# If progs_clean is zero, error and quit
|
||||
if [[ ${#progs_clean[@]} -eq 0 ]]; then
|
||||
printf "\e[1;33m<!>\e[0m\e[1m All provided layer candidates are already layered\e[0m\n"
|
||||
unlock_and_quit 0
|
||||
fi
|
||||
|
||||
# Notify user of changes and ask for permission if interactive_mode is enabled
|
||||
printf '\e[1;34m-->\e[0m\e[1m The following packages will be layered\e[0m\n'
|
||||
printf "${progs_clean[@]}" | column
|
||||
if [[ $interactive_mode -eq 1 ]]; then
|
||||
read -p 'Proceed with removal? [Y/n] ' remove_confirm
|
||||
|
||||
if [[ ! $remove_confirm =~ ^(y|Y|yes|YES|)$ ]]; then
|
||||
unlock_and_quit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Unlock the partition
|
||||
btrfs property set -f -ts / ro false ||
|
||||
cleanup_and_quit 'Failed to unlock root partition'
|
||||
|
||||
# Install the packages
|
||||
$package_layer_command ${progs_clean[@]} ||
|
||||
cleanup_and_quit 'Failed to install requested packages'
|
||||
|
||||
# If installation was successful add to layer tracker file
|
||||
printf ${progs_clean[@]} >> $arkdep_dir/layer
|
||||
|
||||
unlock_and_quit 0
|
||||
|
||||
}
|
||||
|
||||
[[ $1 == 'init' ]] && init_new_system $2
|
||||
[[ $1 == 'teardown' ]] && teardown
|
||||
[[ $1 == 'get-available' ]] && get_available
|
||||
|
@ -1265,6 +1345,9 @@ deploy () {
|
|||
[[ $1 == 'remove' ]] && remove_deployment $@
|
||||
[[ $1 == 'healthcheck' ]] && healthcheck $1
|
||||
[[ $1 == 'cleanup' ]] && cleanup
|
||||
[[ $1 == 'layer' ]] && layer $@
|
||||
[[ $1 == 'layer-ls' ]] && layer-ls
|
||||
[[ $1 == 'layer-rm' ]] && layer-rm $@
|
||||
|
||||
# No valid params were provided
|
||||
printf '\e[1;31m<#>\e[0m\e[1m No valid parameters provided\e[0m\n'
|
||||
|
|
Loading…
Add table
Reference in a new issue