2022-07-10 10:48:13 +02:00
|
|
|
---
|
|
|
|
- name: Autoupdate
|
|
|
|
hosts: all
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
- name: Create updates dir /usr/local/sbin/autoupdate.d
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /usr/local/sbin/autoupdate.d
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
state: directory
|
|
|
|
mode: "0700"
|
|
|
|
|
|
|
|
- name: /usr/local/sbin/autoupdate.sh
|
|
|
|
blockinfile:
|
|
|
|
path: /usr/local/sbin/autoupdate.sh
|
|
|
|
mode: "0500"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
create: yes
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
|
|
|
block: |
|
|
|
|
. /etc/bash/gaboshlib.include
|
|
|
|
g_nice
|
|
|
|
g_lockfile
|
|
|
|
g_all-to-syslog
|
2023-07-18 14:16:43 +02:00
|
|
|
DISPLAY=""
|
2022-07-10 10:48:13 +02:00
|
|
|
set -o pipefail
|
2022-12-04 17:24:11 +01:00
|
|
|
for update in $(find /usr/local/sbin/autoupdate.d -name "*.update" -type f | sort)
|
2022-07-10 10:48:13 +02:00
|
|
|
do
|
|
|
|
g_echo "Running: $update"
|
|
|
|
. "$update"
|
2023-08-09 16:49:37 +02:00
|
|
|
#sleep 60
|
2022-07-10 10:48:13 +02:00
|
|
|
done
|
|
|
|
backup: yes
|
|
|
|
validate: /bin/bash -n %s
|
|
|
|
|
|
|
|
- name: /usr/local/sbin/autoupdate.sh shebang
|
|
|
|
lineinfile:
|
|
|
|
path: /usr/local/sbin/autoupdate.sh
|
|
|
|
insertbefore: BOF
|
|
|
|
line: "#!/bin/bash"
|
|
|
|
|
|
|
|
- name: /usr/local/sbin/autoupdate.d/debian.update
|
|
|
|
blockinfile:
|
|
|
|
path: /usr/local/sbin/autoupdate.d/debian.update
|
|
|
|
mode: "0400"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
create: yes
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
|
|
|
block: |
|
2023-07-18 16:15:49 +02:00
|
|
|
g_echo_ok "Checking for systemupdates"
|
2022-07-10 10:48:13 +02:00
|
|
|
apt-get update || g_echo_error "apt-get update fehlgeschlagen"
|
2023-07-18 17:18:57 +02:00
|
|
|
if ! hostname | grep -q ".mint."
|
2022-07-10 10:48:13 +02:00
|
|
|
then
|
2023-07-18 16:15:49 +02:00
|
|
|
if ! apt-get -s dist-upgrade 2>&1 | sed -e "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/'/" | tee $g_tmp/sys-updatelist | egrep "^0.+, 0 .+, 0 .+ 0 .+\."
|
|
|
|
then
|
|
|
|
g_echo_warn "Systemupdate wird eingespielt: $(cat $g_tmp/sys-updatelist)"
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get -yy dist-upgrade | sed -e "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/'/" | tee $g_tmp/sys-update || g_echo_error "apt-get -yy dist-upgrade failed $($g_tmp/sys-update)"
|
|
|
|
DEBIAN_FRONTEND=noninteractive needrestart -b -r a | egrep -q "^NEEDRESTART-KSTA: [2|3]" && g_echo_warn "Server Reboot benötigt"
|
2023-07-18 16:43:53 +02:00
|
|
|
g_echo_warn $(DEBIAN_FRONTEND=noninteractive apt-get -yy --purge autoremove 2>&1 | egrep -A10 "^The following packages will be REMOVED:")
|
2023-07-18 17:03:53 +02:00
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get -yy autoclean
|
|
|
|
g_echo_warn $(find /etc -name '.dpkg-' -o -name '.ucf-' -o -name '*.merge-error')
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get purge '~o'
|
|
|
|
# sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
|
|
|
|
# sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/*
|
|
|
|
# sed -i 's/non-free/non-free non-free-firmware/g' /etc/apt/sources.list
|
|
|
|
# sed -i 's/non-free/non-free non-free-firmware/g' /etc/apt/sources.list.d/*
|
|
|
|
# DEBIAN_FRONTEND=noninteractive apt-get -yy upgrade --without-new-pkgs
|
|
|
|
# DEBIAN_FRONTEND=noninteractive apt-get -yy full-upgrade
|
2023-07-18 16:15:49 +02:00
|
|
|
fi
|
2022-07-10 10:48:13 +02:00
|
|
|
fi
|
2022-09-21 17:41:33 +02:00
|
|
|
[ -x /usr/bin/flatpak ] && flatpak update --system --noninteractive --force-remove
|
2022-07-10 10:48:13 +02:00
|
|
|
backup: yes
|
|
|
|
validate: /bin/bash -n %s
|
|
|
|
|
2022-09-28 12:40:09 +02:00
|
|
|
- name: /usr/local/sbin/autoupdate.d/server.update
|
|
|
|
blockinfile:
|
|
|
|
path: /usr/local/sbin/autoupdate.d/server.update
|
|
|
|
mode: "0400"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
create: yes
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
2022-11-29 13:47:41 +01:00
|
|
|
block: |
|
2023-07-03 14:58:28 +02:00
|
|
|
# Server-Config in Git
|
2023-09-28 14:45:07 +02:00
|
|
|
cd /root
|
2023-07-18 15:39:00 +02:00
|
|
|
[ -d /root/server-$(hostname -s) ] && rm -r /root/server-$(hostname -s)
|
2024-09-29 22:06:11 +02:00
|
|
|
git clone ssh://git@gitea.ds9.dedyn.io:333/olli/server-$(hostname -s).git >/dev/null 2>&1
|
2023-07-18 15:26:07 +02:00
|
|
|
if [ -e /root/server-$(hostname -s)/$(hostname -s).sh ]
|
|
|
|
then
|
|
|
|
bash -x /root/server-$(hostname -s)/$(hostname -s).sh >/var/log/server-$(hostname -s)-update.log 2>&1
|
|
|
|
g_echo_warn "$(egrep -B1 "^changed" /var/log/server-$(hostname -s)-update.log)"
|
2023-07-18 15:39:00 +02:00
|
|
|
g_echo_error "$(egrep -q -B1 -i '^error|^fatal' /var/log/server-$(hostname -s)-update.log && egrep -B50 '^error|^fatal' /var/log/server-$(hostname -s)-update.log)"
|
2023-07-18 15:26:07 +02:00
|
|
|
else
|
2023-09-28 14:45:07 +02:00
|
|
|
g_echo "no server-update-script found /root/server-$(hostname -s)/$(hostname -s).sh"
|
2023-07-18 15:26:07 +02:00
|
|
|
fi
|
2023-09-28 14:45:07 +02:00
|
|
|
[ -x /usr/local/sbin/mint-config-update.sh ] && /usr/local/sbin/mint-config-update.sh
|
2023-07-03 14:58:28 +02:00
|
|
|
backup: yes
|
|
|
|
validate: /bin/bash -n %s
|
|
|
|
|
|
|
|
- name: /usr/local/sbin/autoupdate.d/client.update
|
|
|
|
blockinfile:
|
|
|
|
path: /usr/local/sbin/autoupdate.d/client.update
|
|
|
|
mode: "0400"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
create: yes
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
|
|
|
block: |
|
|
|
|
# individual update script
|
|
|
|
updatesrv="update.$(domainname -d)"
|
|
|
|
if host ${updatesrv} >/dev/null 2>&1
|
|
|
|
then
|
2023-07-19 14:11:36 +02:00
|
|
|
[ -s /etc/mymac ] || ip addr show $(ip route list | grep default | cut -d" " -f5) | grep "link/ether " | perl -pe 's/.*link\/ether //; s/:/-/g' | cut -d" " -f1 >/etc/mymac
|
|
|
|
mac=$(cat /etc/mymac)
|
2023-07-03 14:58:28 +02:00
|
|
|
usr=$(getent passwd 1000 | cut -d: -f1)
|
|
|
|
hst=$(hostname | cut -d. -f1 | perl -pe 's/ //g')
|
2023-07-18 14:16:43 +02:00
|
|
|
curl -s https://update.$(domainname -f)/${mac}--${usr}--${hst}.sh >${g_tmp}/update.sh
|
2023-07-05 16:40:55 +02:00
|
|
|
head -n1 ${g_tmp}/update.sh | grep -q "^#!/bin/bash" && bash ${g_tmp}/update.sh
|
2023-07-03 14:58:28 +02:00
|
|
|
fi
|
2022-09-28 12:40:09 +02:00
|
|
|
backup: yes
|
|
|
|
validate: /bin/bash -n %s
|
|
|
|
|
2022-07-10 10:48:13 +02:00
|
|
|
- name: /etc/cron.d/autoupdate_local
|
|
|
|
blockinfile:
|
|
|
|
path: /etc/cron.d/autoupdate_local
|
|
|
|
mode: "0400"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
create: yes
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
|
|
|
block: |
|
|
|
|
## Auto-Update
|
|
|
|
5 6 * * * root /usr/local/sbin/autoupdate.sh
|
|
|
|
backup: yes
|