Last active 6 months ago

Revision 754087e0cdf0ed60bb35b117ec7f210db9af7c5f

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