Ultima attività 6 months ago

Revisione f45da30265d465fb401f6f5f3c7029ba8d78fd0a

stretch2buster.sh Raw
1Please also refer to http://www.debian.org/releases/buster/releasenotes and use your brain! If you can’t figure out what one of the commands below does, this is not for you. Expert mode only :)
2
3# Crossgrading ?!?
4[ "$(dpkg --print-architecture)" == "i386" ] && echo "How about crossgrading to amd64 as described in https://stbuehler.de/blog/article/2017/06/28/debian_stretch__upgrade_32-bit_to_64-bit.html?"
5
6# Since running buster with older kernels may not work well (eg jessie kernels) lets see if we have a domU without own kernel
7if [ -d /sys/module/xen_netfront -a $(dpkg -l | grep grub-xen-bin | wc -l) = 0 -a $(dpkg -l | grep linux-image | wc -l) = 0 ]; then echo "Please run 'apt install grub-xen-bin grub-xen linux-image-amd64 && update-grub' to install a recent kernel and boot your domU with it next time"; fi
8
9# upgrade to UTF-8 locales (http://www.debian.org/releases/buster/amd64/release-notes/ap-old-stuff.en.html#switch-utf8)
10dpkg-reconfigure locales
11
12# remove unused config file
13rm -rf /etc/network/options /etc/environment
14
15# are there 3rd party packages installed? (https://www.debian.org/releases/buster/amd64/release-notes/ch-upgrading.de.html#system-status)
16aptitude search '~i(!~ODebian)'
17
18# check for ftp protocol in sources lists (https://www.debian.org/releases/buster/amd64/release-notes/ch-information.en.html#deprecation-of-ftp-apt-mirrors)
19rgrep --color "deb ftp" /etc/apt/sources.list*
20
21# Transition and remove entries from older releases
22sed -i /lenny/d /etc/apt/sources.list*
23sed -i /sarge/d /etc/apt/sources.list*
24sed -i /squeeze/d /etc/apt/sources.list*
25sed -i /wheezy/d /etc/apt/sources.list*
26sed -i /jessie/d /etc/apt/sources.list*
27sed -i /volatile/d /etc/apt/sources.list*
28sed -i /proposed-updates/d /etc/apt/sources.list*
29# change distro (please move 3rd party sources to /etc/apt/sources.list.d/), maybe look into http://ftp.cyconet.org/debian/sources.list.d/
30sed -i s/stretch/buster/g /etc/apt/sources.list*
31sed -i "s/ stable/ buster/g" /etc/apt/sources.list*
32sed -i s/stretch/buster/g /etc/apt/preferences*
33sed -i s/stretch/buster/g /etc/apt/sources.list.d/*stretch*
34rename s/stretch/buster/g /etc/apt/sources.list.d/*stretch*
35rgrep --color stretch /etc/apt/sources.list*
36apt-get update
37
38# check package status
39dpkg --audit
40aptitude search "~ahold" | grep "^.h"
41dpkg --get-selections | grep hold
42
43# unmark packages auto
44aptitude unmarkauto vim net-tools && \
45aptitude unmarkauto libapache2-mpm-itk && \
46aptitude unmarkauto $(dpkg-query -W 'linux-image-4.9.0*' | cut -f1)
47
48# have a look into required and free disk space
49apt-get -o APT::Get::Trivial-Only=true dist-upgrade || df -h
50
51# record session
52script -t 2>~/upgrade-buster.time -a ~/upgrade-buster.script
53
54# install our preseed so libc doesn't whine
55cat > /tmp/stretch.preseed <<EOF
56libc6 glibc/upgrade boolean true
57libc6 glibc/restart-services string
58libc6 libraries/restart-without-asking boolean true
59EOF
60/usr/bin/debconf-set-selections /tmp/stretch.preseed
61
62# update aptitude first
63[ "$(which aptitude)" = "/usr/bin/aptitude" ] && aptitude install aptitude && \
64[ "$(which apt)" = "/usr/bin/apt" ] && apt install apt
65
66# minimal system upgrade
67aptitude upgrade
68
69# randomize crontab
70if [ -f /etc/crontab.dpkg-new ]; then CFG=/etc/crontab.dpkg-new; else CFG=/etc/crontab; fi
71sed -i 's#root cd#root perl -e "sleep int(rand(300))" \&\& cd#' $CFG
72sed -i 's#root\ttest#root\tperl -e "sleep int(rand(3600))" \&\& test#' $CFG
73
74# chrony update, modify the new config to our needs and place it where it is expected.
75# Keep LOCAL config if asked when upgrading
76if [ -f /etc/chrony/chrony.conf.new ]; then CFG=/etc/chrony/chrony.conf.new; else CFG=/etc/chrony/chrony.conf; fi
77sed s/2.debian.pool/0.de.pool/g /usr/share/chrony/chrony.conf > $CFG
78
79# Fix our ssh pub key package configuration
80# Accept MAINTAINERS version (and run this snippet afterwards)
81[ -x /var/lib/dpkg/info/config-openssh-server-authorizedkeys-core.postinst ] && \
82 /var/lib/dpkg/info/config-openssh-server-authorizedkeys-core.postinst configure
83
84# migrate unattended-upgrades config, modify the new config to our needs and place it where it is expected.
85# Keep LOCAL config if asked when upgrading (and run this snippet afterwards, when dpkg is not blocked anymore and choose 'package maintainer version' then, cause this is the one we are adjusting here)
86if [ -f /etc/apt/apt.conf.d/50unattended-upgrades.ucf-old ]; then CFG=/etc/apt/apt.conf.d/50unattended-upgrades.ucf-old; else CFG=/etc/apt/apt.conf.d/50unattended-upgrades; fi && \
87cp /usr/share/unattended-upgrades/50unattended-upgrades /tmp/ && \
88MAIL=$(grep ^Unattended-Upgrade::Mail $CFG | awk -F\" '{print $2}'); sed -i 's#//Unattended-Upgrade::Mail ".*";#Unattended-Upgrade::Mail "'${MAIL}'";#g' /tmp/50unattended-upgrades && \
89TIME=$(grep ^Unattended-Upgrade::Automatic-Reboot-Time $CFG | awk -F\" '{print $2}'); if [ "${TIME}" != "" ]; then sed -i 's#//Unattended-Upgrade::Automatic-Reboot-Time "02:00"#Unattended-Upgrade::Automatic-Reboot-Time "'${TIME}'"#' /tmp/50unattended-upgrades; fi
90sed -i 's#// "origin=Debian,codename=${distro_codename}-updates"# "origin=Debian,codename=${distro_codename}-updates"#' /tmp/50unattended-upgrades && \
91sed -i 's#//Unattended-Upgrade::Remove-Unused-Dependencies "false"#Unattended-Upgrade::Remove-Unused-Dependencies "true"#' /tmp/50unattended-upgrades && \
92sed -i 's#//Unattended-Upgrade::Automatic-Reboot "false"#Unattended-Upgrade::Automatic-Reboot "true"#' /tmp/50unattended-upgrades && \
93sed -i '/codename=..distro_codename.-updates/ s#^//# #' /tmp/50unattended-upgrades && \
94/bin/bash /usr/bin/ucf --three-way --debconf-ok /tmp/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades && \
95[ "$CFG" == "/etc/apt/apt.conf.d/50unattended-upgrades.ucf-old" ] && mv $CFG /etc/apt/apt.conf.d/50unattended-upgrades.ucf-save
96
97## phpmyadmin
98if [ "$(dpkg -l | grep -c phpmyadmin)" = "1" ]; then wget https://gist.githubusercontent.com/waja/77e3d2febb0745478466344f0ce5a50e/raw/deploy_phpmyadmin_buster.sh -O /tmp/a && sh /tmp/a; fi && \
99if [ -f /etc/phpmyadmin/config.inc.php.dpkg-new ]; then CFG=/etc/phpmyadmin/config.inc.php.dpkg-new; \
100 else CFG=/etc/phpmyadmin/config.inc.php; fi
101sed -i "s/\['auth_type'\] = 'cookie'/\['auth_type'\] = 'http'/" $CFG
102sed -i "s#//\$cfg\['Servers'\]\[\$i\]\['auth_type'\] = 'http';#\$cfg['Servers'][\$i]['auth_type'] = 'http';#" $CFG
103
104# transition sshd port changes
105sed -i "s/^#Port 22/Port 1234/" /etc/ssh/sshd_config && /etc/init.d/ssh restart
106
107# full-upgrade
108apt-get dist-upgrade
109
110# Migrate (webserver) from php7.0 to php7.3
111apt install $(dpkg -l |grep php7.0 | awk '/^i/ { print $2 }' |grep -v ^php7.0-opcache |sed s/php7.0/php/)
112a2dismod php7.0; a2enmod php7.3 && systemctl restart apache2; ls -la /etc/php/7.0/*/conf.d/
113# php-fpm
114tail -10 /etc/php/7.0/fpm/pool.d/www.conf
115vi /etc/php/7.3/fpm/pool.d/www.conf
116systemctl disable php7.0-fpm && systemctl stop php7.0-fpm && systemctl restart php7.3-fpm
117# nginx
118rename s/php70/php73/g /etc/nginx/conf.d/*php70*.conf
119sed -i s/php7.0-fpm/php7.3-fpm/g /etc/nginx/conf.d/*.conf /etc/nginx/snippets/*.conf /etc/nginx/sites-available/*
120systemctl restart nginx
121
122# transition docker-ce to buster package
123DOCKER_VER="$(apt-cache policy docker-ce | grep debian-buster | head -1 | awk '{print $1}')" && [ -n "${DOCKER_VER}" ] && apt install docker-ce=${DOCKER_VER} docker-ce-cli=${DOCKER_VER}
124
125# transition icingaweb2 to buster package
126ICINGAWEB2_VER="$(apt-cache policy icingaweb2 | grep "\.buster" | head -1 | awk '{print $1}')" && [ -n "${ICINGAWEB2_VER}" ] && apt install icingaweb2=${ICINGAWEB2_VER} icingaweb2-common=${ICINGAWEB2_VER} icingaweb2-module-monitoring=${ICINGAWEB2_VER} php-icinga=${ICINGAWEB2_VER} icingacli=${ICINGAWEB2_VER}
127
128# provide /etc/dovecot/private/dovecot.key from default config to prevent failing to start dovecot
129ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/dovecot/private/dovecot.key
130
131# Fixing systemd unit for chrooted unbound (https://bugs.debian.org/931583)
132mkdir -p /etc/systemd/system/unbound.service.d/ && cat > /etc/systemd/system/unbound.service.d/override.conf <<EOF
133[Service]
134BindPaths=/run/systemd/notify:/var/lib/unbound/run/systemd/notify
135EOF
136systemctl daemon-reload && systemctl restart unbound
137
138# remove old squeeze packages left around (keep eyes open!)
139apt autoremove && \
140apt purge $(aptitude search ?obsolete | grep -v -E 'linux-image|mailscanner|phpmyadmin|check-openmanage|check-linux-bonding' | awk '/^i *A/ { print $3 }') && \
141apt purge $(aptitude search ?obsolete | grep -v -E 'linux-image|mailscanner|phpmyadmin|check-openmanage|check-linux-bonding' | awk '/^i/ { print $2 }') && \
142apt purge $(dpkg -l | grep etch | grep -v xen | grep -v unbound | grep -v finch | awk '/^rc/ { print $2 }') && \
143apt purge $(dpkg -l | grep lenny | grep -v xen | awk '/^rc/ { print $2 }') && \
144apt purge $(dpkg -l | grep -E 'deb6|squeeze' | grep -v xen | awk '/^rc/ { print $2 }') && \
145apt purge $(dpkg -l | grep -E 'deb7|wheezy' | grep -v xen | grep -v -E 'linux-image|mailscanner|openswan|debian-security-support' | awk '/^rc/ { print $2 }') && \
146apt purge $(dpkg -l | grep -E 'deb8|jessie' | grep -v xen | grep -v -E 'linux-image|debian-security-support' | awk '{ print $2 }') && \
147apt purge $(dpkg -l | grep -E 'deb9|stretch' | grep -v xen | grep -v -E 'linux-image|debian-security-support|icinga2|phpmyadmin' | awk '{ print $2 }') && \
148apt -y install deborphan && apt purge $(deborphan | grep -v xen | grep -v -E 'libpam-cracklib|libapache2-mpm-itk')
149apt purge $(dpkg -l | awk '/^rc/ { print $2 }')
150
151# for the brave YoloOps crowd
152reboot && sleep 180; echo u > /proc/sysrq-trigger ; sleep 2 ; echo s > /proc/sysrq-trigger ; sleep 2 ; echo b > /proc/sysrq-trigger
153
154### not needed until now
155# Upgrade postgres
156# See also https://www.debian.org/releases/stretch/amd64/release-notes/ch-information.de.html#plperl
157if [ "$(dpkg -l | grep "postgresql-9.4" | awk {'print $2'})" = "postgresql-9.4" ]; then \
158 aptitude install postgresql-9.6 && \
159 pg_dropcluster --stop 9.6 main && \
160 /etc/init.d/postgresql stop && \
161 pg_upgradecluster -v 9.6 9.4 main && \
162 sed -i "s/^manual/auto/g" /etc/postgresql/9.6/main/start.conf && \
163 sed -i "s/^port = .*/port = 5432/" /etc/postgresql/9.6/main/postgresql.conf && \
164 sed -i "s/^shared_buffers = .*/shared_buffers = 128MB/" /etc/postgresql/9.6/main/postgresql.conf && \
165 /etc/init.d/postgresql restart; \
166fi
167pg_dropcluster 9.4 main
168