mirror of
https://github.com/0xbbjubjub/miniguest.git
synced 2025-01-08 13:38:13 +03:00
Add upgrade & remove operations
This commit is contained in:
parent
4e091ff787
commit
c7105c170b
@ -16,7 +16,7 @@
|
||||
# along with Miniguest. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
function run_nix {
|
||||
command "$nix" --experimental-features "nix-command flakes" "$@"
|
||||
command "$nix" --experimental-features "nix-command flakes ca-references" "$@"
|
||||
}
|
||||
|
||||
flake=
|
||||
@ -27,3 +27,34 @@ function parse_flake_reference {
|
||||
flake="${BASH_REMATCH[1]}"
|
||||
guest_name="${BASH_REMATCH[2]}"
|
||||
}
|
||||
|
||||
function install_profile {
|
||||
[[ $# -eq 2 ]] || die "$FUNCNAME: wrong number of arguments!"
|
||||
local guest_name="$1"
|
||||
local target="$2"
|
||||
run_nix profile install --profile "$profiles_dir/$guest_name" "$target" ||
|
||||
die "unable to install $guest_name!" $?
|
||||
}
|
||||
|
||||
function upgrade_profile {
|
||||
[[ $# -eq 1 ]] || die "$FUNCNAME: wrong number of arguments!"
|
||||
local guest_name="$1"
|
||||
run_nix profile upgrade --profile "$guests_dir/$guest_name" ||
|
||||
die "unable to upgrade $guest_name!" $?
|
||||
}
|
||||
|
||||
function reset_profile {
|
||||
[[ $# -eq 1 ]] || die "$FUNCNAME: wrong number of arguments!"
|
||||
local guest_name="$1"
|
||||
run_nix profile remove --profile "$profiles_dir/$guest_name" '.*' ||
|
||||
die "unable to remove guest!" $?
|
||||
}
|
||||
|
||||
function have_control_of_symlink {
|
||||
[[ $# -eq 1 ]] || die "$FUNCNAME: wrong number of arguments!"
|
||||
local symlink="$guests_dir/$guest_name"
|
||||
[[ ! -e $symlink || -L $symlink && $(readlink $symlink) -ef "$profiles_dir/$guest_name" ]] || {
|
||||
echo >&2 "not touching $guests_dir/$guest_name because it's not in an expected state"
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,8 @@ parse_flake_reference "$_arg_flake_reference"
|
||||
|
||||
mkdir -p "$guests_dir" || die "" $?
|
||||
mkdir -p "$profiles_dir" || die "" $?
|
||||
run_nix build --profile "$profiles_dir/$guest_name" "$flake#nixosConfigurations.$guest_name.config.system.build.miniguest" || die "unable to build guest!" $?
|
||||
ln -sf "$profiles_dir/$guest_name" "$guests_dir" || die "" $?
|
||||
|
||||
reset_profile "$guest_name" # FIXME: need an atomic reset-and-install
|
||||
install_profile "$guest_name" "$flake#nixosConfigurations.$guest_name.config.system.build.miniguest"
|
||||
|
||||
have_control_of_symlink "$guest_name" && ln -sf "$profiles_dir/$guest_name" "$guests_dir"
|
||||
|
@ -25,6 +25,14 @@ nix="$_arg_nix"
|
||||
|
||||
source functions.bash
|
||||
|
||||
if test "${_arg_command:?}" = install; then
|
||||
case "${_arg_command:?}" in
|
||||
install)
|
||||
source install.bash "${_arg_leftovers[@]}"
|
||||
fi
|
||||
;;
|
||||
upgrade)
|
||||
source upgrade.bash "${_arg_leftovers[@]}"
|
||||
;;
|
||||
remove)
|
||||
source remove.bash "${_arg_leftovers[@]}"
|
||||
;;
|
||||
esac
|
||||
|
@ -16,7 +16,7 @@
|
||||
# along with Miniguest. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# ARG_POSITIONAL_SINGLE(command, subcommand to run)
|
||||
# ARG_TYPE_GROUP_SET(commands, COMMAND, command, [install,help])
|
||||
# ARG_TYPE_GROUP_SET(commands, COMMAND, command, [install,upgrade,remove,help])
|
||||
# ARG_OPTIONAL_SINGLE(guests-dir, , directory containing guests profiles, /etc/miniguests)
|
||||
# ARG_OPTIONAL_SINGLE(nix, , path to the nix binary, @nixFlakes@/bin/nix)
|
||||
# ARG_LEFTOVERS(subcommand arguments)
|
||||
|
7
miniguest/remove.bash
Normal file
7
miniguest/remove.bash
Normal file
@ -0,0 +1,7 @@
|
||||
source remove_arg.bash
|
||||
|
||||
guest_name="$_arg_guest_name"
|
||||
|
||||
reset_profile "$guest_name"
|
||||
|
||||
have_control_of_symlink "$guest_name" && rm -f "$guests_dir/$guest_name"
|
2
miniguest/remove_arg.bash
Normal file
2
miniguest/remove_arg.bash
Normal file
@ -0,0 +1,2 @@
|
||||
# ARG_POSITIONAL_SINGLE(guest-name, name of guest to remove)
|
||||
# ARGBASH_GO
|
5
miniguest/upgrade.bash
Normal file
5
miniguest/upgrade.bash
Normal file
@ -0,0 +1,5 @@
|
||||
source upgrade_arg.bash
|
||||
|
||||
guest_name="$_arg_guest_name"
|
||||
|
||||
upgrade_profile "$guest_name"
|
2
miniguest/upgrade_arg.bash
Normal file
2
miniguest/upgrade_arg.bash
Normal file
@ -0,0 +1,2 @@
|
||||
# ARG_POSITIONAL_SINGLE(guest-name, name of guest to upgrade)
|
||||
# ARGBASH_GO
|
Loading…
Reference in New Issue
Block a user