From b811de3770348c1f5ce74896f26c7291af04fa26 Mon Sep 17 00:00:00 2001 From: Neakio Date: Mon, 29 Jul 2024 10:57:30 +0200 Subject: [PATCH 1/2] added -i --- interact/axiom-power | 96 +++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 28 deletions(-) diff --git a/interact/axiom-power b/interact/axiom-power index eb51f14f..84aca59d 100755 --- a/interact/axiom-power +++ b/interact/axiom-power @@ -20,13 +20,15 @@ current=$(ls -lh ~/.axiom/axiom.json | awk '{ print $11 }' | tr '/' '\n' | grep function usage() { cat << EOF - Usage: axiom-power on 'rez\*' #turns on instances starting with 'rez' - axiom-power off '\*' #turns off all instances + Usage: axiom-power on 'rez\*' #turns on instances starting with 'rez' + axiom-power off '\*' #turns off all instances + axiom-power on 'rez\*' -i 2 #turns on the 2 first instances of 'rez' fleet Examples: - on Power on instance by instance name - off Power off instance by instance name - reboot Reboot instance by instance name - help | --help | -h Print this help menu + on Power on instance by instance name + off Power off instance by instance name + reboot Reboot instance by instance name + -i/--instances (optional) The number of instances to power + help | --help | -h Print this help menu EOF exit } @@ -38,6 +40,8 @@ help=true off=false reboot=false force=false +instance=false +amount=false # Parse command line arguments # @@ -76,6 +80,14 @@ do pass+=($i) pass+=($n) fi + if [[ "$arg" == "-i" ]] || [[ "$arg" == "--instances" ]]; then + n=$((i+1)) + number_instance=true + amount=$(echo ${!n}) + set=true + pass+=($i) + pass+=($n) + fi if [[ "$arg" == "--help" ]] || [[ "$arg" == "-h" ]] || [[ "$arg" == "help" ]]; then usage exit @@ -109,49 +121,77 @@ fi # Power Off Snapshots # if [[ "$off" == "true" ]]; then - instances=$(query_instances "$@"|sort -u|tr ' ' '\n') + instances=$(query_instances "$instance"|sort -u|tr ' ' '\n') - if [[ ${#instances} == 0 ]];then + if [[ ${#instances} == 0 ]]; then usage exit fi - for i in $(echo $instances); - do - echo -e "${Yellow}Powering off instance: $i${Color_Off}" - poweroff $i $force; - done + if [[ "$number_instance" == "true" ]]; then + for i in $(seq -f "%02g" 1 "$amount"); + do + instance_i="${instance//\\}" + instance_i="${instance_i//\*/$i}" + echo -e "${Yellow}Powering off instance: $instance_i${Color_Off}" + poweroff $instance_i $force; + done + else + for i in $(echo $instances); + do + echo -e "${Yellow}Powering off instance: $i${Color_Off}" + poweroff $i $force; + done + fi fi # Power On Snapshots # if [[ "$on" == "true" ]]; then - instances=$(query_instances "$@"|sort -u|tr ' ' '\n') + instances=$(query_instances "$instance"|sort -u|tr ' ' '\n') - if [[ ${#instances} == 0 ]];then + if [[ ${#instances} == 0 ]]; then usage exit fi - - for i in $(echo $instances); - do - echo -e "${Yellow}Powering on instance: $i${Color_Off}" - poweron $i $force; - done + if [[ "$number_instance" == "true" ]]; then + for i in $(seq -f "%02g" 1 "$amount"); + do + instance_i="${instance//\\}" + instance_i="${instance_i//\*/$i}" + echo -e "${Yellow}Powering on instance: $instance_i${Color_Off}" + poweron $instance_i $force; + done + else + for i in $(echo $instances); + do + echo -e "${Yellow}Powering on instance: $i${Color_Off}" + poweron $i $force; + done + fi fi # Reboot Snapshots # if [[ "$reboot" == "true" ]]; then - instances=$(query_instances "$@"|sort -u|tr ' ' '\n') + instances=$(query_instances "$instance"|sort -u|tr ' ' '\n') if [[ ${#instances} == 0 ]];then usage exit fi - - for i in $(echo $instances); - do - echo -e "${Yellow}Rebooting instance: $i${Color_Off}" - reboot $i $force; - done + if [[ "$number_instance" == "true" ]]; then + for i in $(seq -f "%02g" 1 "$amount"); + do + instance_i="${instance//\\}" + instance_i="${instance_i//\*/$i}" + echo -e "${Yellow}Rebooting on instance: $instance_i${Color_Off}" + reboot $instance_i $force; + done + else + for i in $(echo $instances); + do + echo -e "${Yellow}Rebooting instance: $i${Color_Off}" + reboot $i $force; + done + fi fi From 322b36bcdccc94a1f36f99f35d566a059c95a6b2 Mon Sep 17 00:00:00 2001 From: Neakio Date: Mon, 29 Jul 2024 13:23:18 +0200 Subject: [PATCH 2/2] typo --- interact/axiom-power | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interact/axiom-power b/interact/axiom-power index 84aca59d..4ddb2852 100755 --- a/interact/axiom-power +++ b/interact/axiom-power @@ -40,8 +40,7 @@ help=true off=false reboot=false force=false -instance=false -amount=false +number_instance=false # Parse command line arguments #