mirror of
https://github.com/bashclub/lxc-apt-upgrade.git
synced 2024-11-07 22:31:58 +01:00
Create lxc-update
This commit is contained in:
parent
6acc989eb5
commit
1454b54174
43
usr/local/bin/lxc-update
Normal file
43
usr/local/bin/lxc-update
Normal file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Updates all running lxc containers on a proxmox host
|
||||
|
||||
PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"
|
||||
|
||||
prog="$(basename "$0")"
|
||||
|
||||
usage() {
|
||||
cat >&2 <<-EOF
|
||||
usage: $prog [-h] [-e EXCLUDELIST]
|
||||
installs a preconfigured lxc container on your proxmox server
|
||||
-e EXCLUDELIST list of container ids to exclude from backup (separator: |)
|
||||
-h displays this help text
|
||||
---------------------------------------------------------------------------
|
||||
(C) 2021 lxc-update by bashclub (https://github.com/bashclub)
|
||||
---------------------------------------------------------------------------
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
condition="grep running"
|
||||
|
||||
while getopts "hi:s:c:" opt; do
|
||||
case $opt in
|
||||
h) usage 0 ;;
|
||||
e) condition="$condition | grep -vE '$OPTARG'" ;;
|
||||
*) usage 1 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
ctlist=$(pct list | $condition | cut -d' ' -f1)
|
||||
|
||||
for ct in $ctlist; do
|
||||
for vol in $(pct config $ct | grep -E "^rootfs|^mp[0-9]+" | cut -d ' ' -f2 | cut -d',' -f1); do
|
||||
snapvols="$snapvols $(pvesm path $vol | cut -d'/' -f2-)";
|
||||
done
|
||||
zfs-auto-snapshot --quiet --syslog --label=lxc-auto-update --keep=2 --pre-snapshot=$(pct shutdown $ct && while [[ "$(pct status $ct)" == "status: running" ]];do sleep .1; echo "waiting for shutdown of ct $ct"; done) --post-snapshot=$(pct start $ct) $snapvols
|
||||
pct exec $ct /usr/bin/apt update
|
||||
pct exec $ct -- bash -c "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt -y -qq dist-upgrade"
|
||||
snapvols=
|
||||
done
|
Loading…
Reference in New Issue
Block a user