Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:jetchisel
systemd-vboxinit
ExtraData
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ExtraData of Package systemd-vboxinit
#!/usr/bin/env bash # ============================================================================================ # #: Title : ExtraData # #: Sypnosis : ExtraData # #: Date Created : Thu Oct 17 17:47:24 PHT 2013 / Thu Oct 17 09:48:11 UTC 2013 # #: Last Edit : Thu Jan 16 10:49:02 PST 2020 / Thu Jan 16 02:49:02 UTC 2020 # #: License : GPLv3 # #: Version : 1.0 # #: Author : Jason V. Ferrer '<jetchisel@opensuse.org>' # #: Description : Set extradata to auto or manual of VirtualBox's vms. # #: Options : NONE # #: Home Page : https://github.com/Jetchisel/VBoxAutostart # #: ExtComm : clear,sleep,tput,VBoxManage # # ============================================================================================ # # ******************************************************************************************** # # Reset the font to normal on quit and force exit/quit via ctrl-c and other signals. # # ******************************************************************************************** # trap 'tput sgr0;echo' 0 trap 'exit 2;echo' 1 2 3 15 # ******************************************************************************************** # # Set shell option to have multiple test and avoid regexp. # # ******************************************************************************************** # shopt -s extglob # ******************************************************************************************** # # list only the vms names and save it in an array listvms. # # ******************************************************************************************** # listvms=() while read -u6 -r line; do Vmname=${line#*'"'} Vmname=${Vmname%'"'*} listvms+=("$Vmname") done 6< <(VBoxManage list vms) # ******************************************************************************************** # # The colors. # # ******************************************************************************************** # gb=$(tput setaf 2 && tput bold) reset=$(tput sgr0) # ******************************************************************************************** # # Prints the vms with it's corresponding number within the array. # # ******************************************************************************************** # numbered=() num=() for vm in "${!listvms[@]}"; do num+=("$vm") numbered+=("${listvms[vm]/#/${gb}$vm${reset}) }") done # ******************************************************************************************** # # Function to set all the vms to auto. # # ******************************************************************************************** # AutoAll() { for vm in "${!listvms[@]}"; do VBoxManage setextradata "${listvms[vm]}" pvbx/startupMode auto done } # ******************************************************************************************** # # Function to set all the vms to manual. # # ******************************************************************************************** # ManualAll() { for vm in "${!listvms[@]}"; do VBoxManage setextradata "${listvms[vm]}" pvbx/startupMode manual done } # ******************************************************************************************** # # Function to Get status of all the vms. # # ******************************************************************************************** # StatusAll() { status() { for vm in "${!listvms[@]}"; do VBoxManage getextradata "${listvms[vm]}" pvbx/startupMode done } mapfile -t stats < <(status) for vm in "${!listvms[@]}"; do printf '%s\n' "VirtualMachine[\"${listvms[vm]}\"]=${stats[vm]#*: }" done } # ******************************************************************************************** # # Function to pause so user has the time to review the output and ask to coninue. # # ******************************************************************************************** # paused() { while :; do printf "\n%s\n" printf -v prompt "Press [c] to continue. " read -r -e -p "$prompt" -n1 case $REPLY in [Cc]) clear return 0 clear;; *) printf "%s\n" "Invalid answer!" >&2 esac done } # ******************************************************************************************** # # Function to print an invalid message. # # ******************************************************************************************** # InValid() { printf "\n%s" "Invalid option!" >&2 } # ******************************************************************************************** # # Function to wait for 1 second so user can see the output and clear the screen. # # ******************************************************************************************** # Wait(){ sleep 1 clear } # ******************************************************************************************** # # Format the numbers in the array so it can be tested in one line. # # ******************************************************************************************** # printf -v new "%s|" "@(${num[@]})" new=${new%|} # ******************************************************************************************** # # The Header with the Message in between the LongBar. Formatted with "printf -v". # # ******************************************************************************************** # ColoredChoice=${gb}NUMBER${reset}/${gb}LETTER${reset} Message="| PRESS THE $ColoredChoice OF THE CHOICES BELOW |" LongBar='+===================================================================+' printf -v Header '%s\n' "$LongBar" "$Message" "$LongBar" # ******************************************************************************************** # # The main menu when the script is started. (Bold fonts up to the submenus) # # ******************************************************************************************** # BlankSpace= Main_Menu=( "$Header" "${gb}1${reset}) SET VMS TO AUTO" "${gb}2${reset}) SET VMS TO MANUAL" "${gb}3${reset}) CHECK STATUS OF VMS" "${gb}Q${reset}) EXIT" "$BlankSpace" "(EnterInput) =>" ) printf -v MainMenu '%s\n' "${Main_Menu[@]}" MainMenu=${MainMenu%$'\n'} # ******************************************************************************************** # # Additional options for the submenus. # # ******************************************************************************************** # Other_Options=( "${gb}A${reset}) SELECT All VMS" "${gb}R${reset}) RETURN TO MAIN MENU" "${gb}Q${reset}) EXIT" ) printf -v OtherOptions '%s\n' "${Other_Options[@]}" # ******************************************************************************************** # # The SubMenus # # ******************************************************************************************** # SubMenuAuto=( "$Header" "${numbered[@]}" "${OtherOptions}" "$BlankSpace" "(SetVmsToAuto) =>" ) SubMenuManual=( "$Header" "${numbered[@]}" "${OtherOptions}" "$BlankSpace" "(SetVmsToManual) =>" ) SubMenuStatus=( "$Header" "${numbered[@]}" "${OtherOptions}" "$BlankSpace" "(CheckVmsStatus) =>" ) # ******************************************************************************************** # # Format the Menu's to a variable using printf -v so read can present it properly. # # ******************************************************************************************** # printf -v sub_menu_auto '%s\n' "${SubMenuAuto[@]}" sub_menu_auto=${sub_menu_auto%$'\n'} printf -v sub_menu_manual '%s\n' "${SubMenuManual[@]}" sub_menu_manual=${sub_menu_manual%$'\n'} printf -v sub_menu_status '%s\n' "${SubMenuStatus[@]}" sub_menu_status=${sub_menu_status%$'\n'} # ******************************************************************************************** # # If vms is more than 9, one click button is disabled in the SubMenu's. # # ******************************************************************************************** # OneClick() { if (( ${#listvms[@]} < 10 )); then read -r -e -p "$1" -n1 elif (( ${#listvms[@]} > 9 )); then read -r -e -p "$1" fi } VmsTotalAuto() { OneClick "$sub_menu_auto " } VmsTotalManual() { OneClick "$sub_menu_manual " } VmsTotalStatus() { OneClick "$sub_menu_status " } # ******************************************************************************************** # # Function to set vms to auto. # # ******************************************************************************************** # Auto() { clear while true; do VmsTotalAuto if [[ ${REPLY} = $new ]]; then VBoxManage setextradata "${listvms[${REPLY}]}" pvbx/startupMode auto printf -v single "[\"%s\"] " "${listvms[${REPLY}]}" printf '\n%s\n' "VirtualMachine $single is now on AUTO." paused elif [[ ${REPLY} = [Aa] ]]; then AutoAll printf -v all "[\"%s\"]\n" "${listvms[@]}" printf '%s\n' "$BlankSpace" "VirtualMachine(s):" "$BlankSpace" "$all" "Is now on AUTO." paused elif [[ ${REPLY} = [Rr] ]]; then return 0 elif [[ ${REPLY} = [Qq] ]]; then clear exit 0 else InValid Wait fi done } # ******************************************************************************************** # # Function to set vms to manual. # # ******************************************************************************************** # Manual() { clear while true; do VmsTotalManual if [[ ${REPLY} = $new ]]; then VBoxManage setextradata "${listvms[${REPLY}]}" pvbx/startupMode manual printf -v single "[\"%s\"] " "${listvms[${REPLY}]}" printf '\n%s\n' "VirtualMachine $single is now on MANUAL." paused elif [[ ${REPLY} = [Aa] ]]; then ManualAll printf -v all "[\"%s\"]\n" "${listvms[@]}" printf '%s\n' "$BlankSpace" "VirtualMachine(s):" "$BlankSpace" "$all" "is now on MANUAL." paused elif [[ ${REPLY} = [Rr] ]]; then return 0 clear elif [[ ${REPLY} = [Qq] ]]; then clear exit 0 else InValid Wait fi done } # ******************************************************************************************** # # Function to check status of the vms. # # ******************************************************************************************** # Status() { clear while true; do VmsTotalStatus if [[ ${REPLY} = $new ]]; then result=$(VBoxManage getextradata "${listvms[${REPLY}]}" pvbx/startupMode) printf '\n%s\n' "VirtualMachine[\"${listvms[${REPLY}]}\"]=${result#*: }" paused elif [[ ${REPLY} = [Aa] ]]; then echo StatusAll paused elif [[ ${REPLY} = [Rr] ]]; then return 0 clear elif [[ ${REPLY} = [Qq] ]]; then clear exit 0 else InValid Wait fi done } # ******************************************************************************************** # # Parsing the main menu. # # ******************************************************************************************** # while true; do clear read -r -e -p "${MainMenu} " -n1 case ${REPLY} in 1) Auto ;; 2) Manual clear ;; 3) Status clear ;; [Qq]) clear exit 0;; *) InValid Wait clear ;; esac done # ============================================================================================ # # >>> END OF SCRIPT <<< # # ============================================================================================ #
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor