diff --git a/proxmox/admin_scripts/bashrc b/proxmox/admin_scripts/bashrc index 55445d7..abc5b9a 100644 --- a/proxmox/admin_scripts/bashrc +++ b/proxmox/admin_scripts/bashrc @@ -8,37 +8,31 @@ esac source /root/telegram.env -alias updl="apt update -q && apt full-upgrade --download-only -y -qq && apt autoremove -y -qq" +alias updl="rup && apt update -q && apt full-upgrade --download-only -y -qq && apt autoremove -y -qq" +#TODO: reinstate restic alias rup="restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd backup /etc ~/.bash_history && restic -q -r local:/root/jc/restic/"$HOSTNAME" -p /root/jc/restic/passwd forget --prune --keep-last 14 --keep-within 3m --keep-weekly 520" #TODO: restic -p ~/jc/restic/passwd -r local:"??no more nas??/restic/$HOSTNAME" init -function up { - read -p "where to? " whereto - if ! ~/jc/migrate_running.sh "$HOSTNAME" "$whereto"; then - tgmsg tgmsg 'ERROR: up: migrate' - return 1 - fi - echo restic… - if ! rup; then - tgmsg 'ERROR: up: restic' - return 1 - fi - if ! updl; then - tgmsg 'ERROR: up: download' - return 1 - fi -} -function upg { - if ! ~/jc/confirm_norunning.sh; then - tgmsg 'ERROR: upg: migratables present' - return 1 +function waitNoRunning { +echo '- - - - - - - - Waiting VMs to migrate or shutdown 200s - - - - - - - -' +while true; do + if "$(basedir "$0")"/confirm_norunning.sh "$@" >/dev/null; then + return fi - if ! ~/jc/shutdown_nomigrates.sh; then + sleep 3 + printf . +done +} +export -f waitNoRunning + +function upg { + if ! "$(basedir "$0")"/shutdown_nomigrates.sh; then tgmsg 'ERROR: upg: signaling nomigrate shutdowns' return 1 fi - if ! timeout 200 bash -c waitNomigrateShutdown; then + + if ! timeout 200 bash -c waitNomigrateShutdown 0; then tgmsg 'ERROR: upg: running VMs before upgrade' return 1 fi @@ -49,25 +43,13 @@ function upg { fi } -function waitNomigrateShutdown { -echo '- - - - - - - - Waiting nomigrate to shutdown 200s - - - - - - - -' -while true; do - if ~/jc/confirm_norunning.sh 1 >/dev/null; then - return - fi - - sleep 3 - printf . -done -} -export -f waitNomigrateShutdown - function upgr { - up || return $? + # shellcheck disable=SC2119 + off || return $? upg || return $? # double confirmation - if ! timeout 200 bash -c waitNomigrateShutdown; then + if ! timeout 200 bash -c waitNomigrateShutdown 1; then tgmsg 'ERROR: upgr: running VMs before reboot' return 1 fi @@ -75,13 +57,24 @@ function upgr { reboot } -function toh { -~/jc/return_migrate.sh ~/jc/desired.yaml "$@" -tgmsg "return_migrate finished: $?" +function _off { + ha-manager crm-command node-maintenance enable "$1" && \ + echo "$1": maintenance mode } -alias des="vim ~/jc/desired.yaml" -alias h="echo 'avail cmds: up upg upgr | toh des | localprogress'" +# shellcheck disable=SC2120 +function off { + if [[ "$#" -gt 0 ]]; then + _off "$@" + return "$?" + else + _off "$HOSTNAME" + fi + + updl +} + +alias h="echo 'avail cmds: updl upg upgr | localprogress'" function localprogress () { watch ls -lh "/var/lib/vz/images/$1" diff --git a/proxmox/admin_scripts/bashrc_sourcer b/proxmox/admin_scripts/bashrc_sourcer deleted file mode 100755 index 3f06859..0000000 --- a/proxmox/admin_scripts/bashrc_sourcer +++ /dev/null @@ -1,9 +0,0 @@ -# If not running interactively, don't do anything -case $- in - *i*) ;; - *) return;; -esac - -if timeout 5 cat "/root/jc/bashrc" >> /dev/null; then - source "/root/jc/bashrc" -fi diff --git a/proxmox/admin_scripts/migrate_running.sh b/proxmox/admin_scripts/migrate_running.sh deleted file mode 100755 index 35a8dad..0000000 --- a/proxmox/admin_scripts/migrate_running.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -e - -if ! which jq >> /dev/null; then - echo "jq not found" - exit 1 -fi - -if [ "$#" -ne 2 ]; then - pvesh get /nodes - echo "usage: $0 " - exit 1 -fi - -from="$1" -target="$2" - -migratable_ids="$(pvesh get "/nodes/${from}/qemu" --output-format json |\ - jq -r 'map(select( .status == "running" and (.tags | split(";") | all(.!="nomigrate")) ) | .vmid) | @csv')" - -if [[ "$migratable_ids" != "" ]]; then - echo "$from $target $migratable_ids" - pvesh create "/nodes/${from}/migrateall" -vms "$migratable_ids" -target "$target" -fi diff --git a/proxmox/admin_scripts/return_migrate.sh b/proxmox/admin_scripts/return_migrate.sh deleted file mode 100755 index 256ae01..0000000 --- a/proxmox/admin_scripts/return_migrate.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -source ~/jc/telegram.env - -set -e -if [ "$#" -lt 1 ]; then - echo "usage: return_migrate.sh [single destination]" - exit 1 -fi -if ! which jq >> /dev/null; then - echo "jq not found" - exit 1 -fi -if ! which yq >> /dev/null; then - echo "yq not found" - exit 1 -fi - -desired_file="$1" -single="$2" - -#TODO: warn about nodes not in the file -#TODO: warn about VMs w/o nomigrate not in the file -yq -r 'keys[]' "$desired_file" | grep -v '^ *#' | while IFS= read -r desired_node; do - # validation of nodes and ids would be nice - desired_ids="$(yq -r --arg node "$desired_node" '.[$node][]' "$desired_file" | tr '\n' ',')" - pvesh get "/nodes" --output-format json | jq -r '.[] | select(.status == "online") | .node' | grep -v '^ *#' | while IFS= read -r node_from; do - if [[ "$node_from" != "$desired_node" ]]; then # not local / recursion - if [[ ! -z "$single" ]] && [[ "$desired_node" != "$single" ]]; then - echo skipping $node_from $desired_node $desired_ids - continue - fi - - echo $node_from $desired_node $desired_ids - pvesh create "/nodes/${node_from}/migrateall" -vms "$desired_ids" -target "$desired_node" - fi - done -done diff --git a/proxmox/admin_scripts/stalk_updates.sh b/proxmox/admin_scripts/stalk_updates.sh deleted file mode 100755 index d2543a5..0000000 --- a/proxmox/admin_scripts/stalk_updates.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -host="$(hostname)" - -cleanup() { - printf "$(tput sgr0)\n" -} -trap cleanup EXIT - -printf 'ID\tName\tup;sec\tver\t(notice)\n' - -pvesh get "/nodes/$host/qemu" --output-format json | jq -r '.[] | select(.status == "running") | "\(.vmid),\(.name),\(.tags)"' |\ -while IFS= read -r vmline; do - vmid="$(cut -d, -f1 <<< "$vmline")" - vmname="$(cut -d, -f2 <<< "$vmline")" - tags="$(cut -d, -f3 <<< "$vmline")" - - printf "$vmid $vmname " - - if grep -q custom <<< "$tags"; then echo "$(tput setaf 5)is custom$(tput sgr0)"; - continue - fi - - printf "$(tput setaf 5)"; qm guest exec "$vmid" -- /usr/bin/apt-get update > /dev/null; code="$?"; printf "$(tput sgr0)" - if [[ "$code" == 255 ]]; then - continue - fi - - apt="$(qm guest exec "$vmid" -- /usr/lib/update-notifier/apt-check | jq '."err-data"' | sed 's/\n$//'| xargs -I: printf " ":)" - printf "$(tput setaf 190)$apt$(tput sgr0) " - - ver="$(qm guest exec "$vmid" -- /usr/bin/lsb_release -a 2>/dev/null | jq '."out-data"' | cut -d'\' -f4 | cut -c 2- )" - printf "$ver" - - expectedTag="unknown" - case "$(cut -d' ' -f1 <<< "$ver")" in - Ubuntu) - expectedTag="ub$(cut -d' ' -f2 <<< "$ver" | cut -d. -f1)" - ;; - Debian) - expectedTag="d$(cut -d' ' -f3 <<< "$ver")" - ;; - esac - - if ! grep -q "$expectedTag" <<< "$tags"; then - printf " $(tput setaf 6)TAG MISMATCH$(tput sgr0)" - fi - - if [[ "$(cut -d';' -f2 <<< "$apt")" != 0 ]]; then - printf " $(tput setaf 3)SECURITY UPDATES$(tput sgr0)" - fi - - echo -done