Files
ansible/proxmox/admin_scripts/bashrc

89 lines
2.0 KiB
Bash

#!/bin/bash
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
source /root/telegram.env
alias updl="apt update -q && apt full-upgrade --download-only -y -qq && apt autoremove -y -qq"
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
fi
if ! ~/jc/shutdown_nomigrates.sh; then
tgmsg 'ERROR: upg: signaling nomigrate shutdowns'
return 1
fi
if ! timeout 200 bash -c waitNomigrateShutdown; then
tgmsg 'ERROR: upg: running VMs before upgrade'
return 1
fi
if ! apt full-upgrade -y; then
tgmsg 'ERROR: upg: upgrade'
return 1
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 $?
upg || return $?
# double confirmation
if ! timeout 200 bash -c waitNomigrateShutdown; then
tgmsg 'ERROR: upgr: running VMs before reboot'
return 1
fi
reboot
}
function toh {
~/jc/return_migrate.sh ~/jc/desired.yaml "$@"
tgmsg "return_migrate finished: $?"
}
alias des="vim ~/jc/desired.yaml"
alias h="echo 'avail cmds: up upg upgr | toh des | localprogress'"
function localprogress () {
watch ls -lh "/var/lib/vz/images/$1"
}