Остання активність 6 months ago

Версія 71a15f0a7aeeec61addbe46541d6804740477e36

buster2bullseye.sh Неформатований
1Please also refer to http://www.debian.org/releases/bullseye/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_buster__upgrade_32-bit_to_64-bit.html?"
5
6# upgrade to UTF-8 locales (http://www.debian.org/releases/bullseye/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/bullseye/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/bullseye/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/buster/bullseye/g /etc/apt/sources.list*
28sed -i "s/ stable/ bullseye/g" /etc/apt/sources.list*
29sed -i s/buster/bullseye/g /etc/apt/preferences*
30sed -i s/buster/bullseye/g /etc/apt/sources.list.d/*buster*
31rename.ul buster bullseye /etc/apt/sources.list.d/*buster*
32rgrep --color buster /etc/apt/sources.list*
33apt update
34
35# check package status
36dpkg --audit
37aptitude search "~ahold" | grep "^.h"
38dpkg --get-selections | grep hold
39dpkg --get-selections "*" > ~/curr-pkgs.txt
40
41# unmark packages auto
42aptitude unmarkauto vim net-tools && \
43aptitude unmarkauto libapache2-mpm-itk && \
44aptitude unmarkauto $(dpkg-query -W 'linux-image-4.19.0*' | cut -f1)
45
46# have a look into required and free disk space
47apt-get -o APT::Get::Trivial-Only=true dist-upgrade || df -h
48
49# record session
50script -t 2>~/upgrade-bullseye.time -a ~/upgrade-bullseye.script
51
52# install our preseed so libc doesn't whine
53cat > /tmp/buster.preseed <<EOF
54libc6 glibc/upgrade boolean true
55libc6 glibc/restart-services string
56libc6 libraries/restart-without-asking boolean true
57EOF
58/usr/bin/debconf-set-selections /tmp/buster.preseed
59
60# update aptitude and apt first
61[ "$(which aptitude)" = "/usr/bin/aptitude" ] && apt install aptitude && \
62[ "$(which apt)" = "/usr/bin/apt" ] && apt install apt
63
64# minimal system upgrade
65apt upgrade
66
67# randomize crontab
68if [ -f /etc/crontab.dpkg-new ]; then CFG=/etc/crontab.dpkg-new; else CFG=/etc/crontab; fi
69sed -i 's#root cd#root perl -e "sleep int(rand(300))" \&\& cd#' $CFG
70sed -i 's#root\ttest#root\tperl -e "sleep int(rand(3600))" \&\& test#' $CFG
71
72# chrony update, modify the new config to our needs and place it where it is expected.
73# Accept MAINTAINERS version (and run this snippet afterwards)
74if [ -f /etc/chrony/chrony.conf.new ]; then CFG=/etc/chrony/chrony.conf.new; else CFG=/etc/chrony/chrony.conf; fi
75sed s/2.debian.pool/0.de.pool/g /usr/share/chrony/chrony.conf > $CFG
76
77# Fix our ssh pub key package configuration
78# Accept MAINTAINERS version (and run this snippet afterwards)
79[ -x /var/lib/dpkg/info/config-openssh-server-authorizedkeys-core.postinst ] && \
80 /var/lib/dpkg/info/config-openssh-server-authorizedkeys-core.postinst configure
81
82# migrate unattended-upgrades config, modify the new config to our needs and place it where it is expected.
83# 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)
84if [ -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 && \
85cp /usr/share/unattended-upgrades/50unattended-upgrades /tmp/ && \
86MAIL=$(grep ^Unattended-Upgrade::Mail $CFG | awk -F\" '{print $2}'); sed -i 's#//Unattended-Upgrade::Mail ".*";#Unattended-Upgrade::Mail "'${MAIL}'";#g' /tmp/50unattended-upgrades && \
87TIME=$(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
88sed -i 's#// "origin=Debian,codename=${distro_codename}-updates"# "origin=Debian,codename=${distro_codename}-updates"#' /tmp/50unattended-upgrades && \
89sed -i 's#//Unattended-Upgrade::Remove-Unused-Dependencies "false"#Unattended-Upgrade::Remove-Unused-Dependencies "true"#' /tmp/50unattended-upgrades && \
90sed -i 's#//Unattended-Upgrade::Automatic-Reboot "false"#Unattended-Upgrade::Automatic-Reboot "true"#' /tmp/50unattended-upgrades && \
91sed -i '/codename=..distro_codename.-updates/ s#^//# #' /tmp/50unattended-upgrades && \
92/bin/bash /usr/bin/ucf --three-way --debconf-ok /tmp/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades && \
93[ "$CFG" == "/etc/apt/apt.conf.d/50unattended-upgrades.ucf-old" ] && mv $CFG /etc/apt/apt.conf.d/50unattended-upgrades.ucf-save
94
95## phpmyadmin
96if [ -f /etc/phpmyadmin/config.inc.php.dpkg-new ]; then CFG=/etc/phpmyadmin/config.inc.php.dpkg-new; \
97 else CFG=/etc/phpmyadmin/config.inc.php; fi
98sed -i "s/\['auth_type'\] = 'cookie'/\['auth_type'\] = 'http'/" $CFG
99sed -i "s#//\$cfg\['Servers'\]\[\$i\]\['auth_type'\] = 'http';#\$cfg['Servers'][\$i]['auth_type'] = 'http';#" $CFG
100
101# transition sshd port changes
102sed -i "s/^#Port 22/Port 1234/" /etc/ssh/sshd_config && /etc/init.d/ssh restart
103
104# full-upgrade
105apt dist-upgrade
106
107# Migrate (webserver) from php7.3 to php7.4
108apt install $(dpkg -l |grep php7.3 | awk '/^i/ { print $2 }' |grep -v ^php7.3-opcache |sed s/php7.3/php/)
109[ -L /etc/apache2/mods-enabled/mpm_prefork.load ] && a2dismod php7.3 && a2enmod php7.4 && systemctl restart apache2; ls -la /etc/php/7.3/*/conf.d/
110# php-fpm
111tail -10 /etc/php/7.3/fpm/pool.d/www.conf
112vi /etc/php/7.4/fpm/pool.d/www.conf
113systemctl disable php7.3-fpm && systemctl stop php7.3-fpm && systemctl restart php7.4-fpm
114# nginx
115rename s/php73/php74/g /etc/nginx/conf.d/*php73*.conf
116sed -i s/php7.3-fpm/php7.4-fpm/g /etc/nginx/conf.d/*.conf /etc/nginx/snippets/*.conf /etc/nginx/sites-available/*
117systemctl restart nginx
118
119# Update old postfix configurations
120cp /etc/postfix/main.cf /tmp/main.cf && \
121if [ $(postconf -n smtpd_relay_restrictions | wc -l) -eq 0 ]; then sed -i '/^myhostname.*/i smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination' /etc/postfix/main.cf; fi && \
122if [ -z $(postconf -nh compatibility_level) ]; then sed -iE 's/^readme_directory = no/readme_directory = no\n\n# See http:\/\/www.postfix.org\/COMPATIBILITY_README.html -- default to 2 on\n# fresh installs.\ncompatibility_level = 2\n\n/' /etc/postfix/main.cf; fi && \
123diff -Nur /tmp/postfix/main.cf /etc/postfix/main.cf && \
124postfix reload
125
126# transition docker-ce to bullseye package
127DOCKER_VER="$(apt-cache policy docker-ce | grep debian-bullseye | head -1 | awk '{print $1}')" && [ -n "${DOCKER_VER}" ] && apt install docker-ce=${DOCKER_VER} docker-ce-cli=${DOCKER_VER}
128
129# transition icingaweb2 to bullseye package
130ICINGAWEB2_VER="$(apt-cache policy icingaweb2 | grep "\.bullseye" | 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}
131
132# remove old squeeze packages left around (keep eyes open!)
133apt autoremove && \
134apt purge $(aptitude search ?obsolete | grep -v -E 'linux-image|mailscanner|phpmyadmin|check-openmanage|check-linux-bonding' | awk '/^i *A/ { print $3 }') && \
135apt purge $(aptitude search ?obsolete | grep -v -E 'linux-image|mailscanner|phpmyadmin|check-openmanage|check-linux-bonding' | awk '/^i/ { print $2 }') && \
136apt purge $(dpkg -l | grep etch | grep -v xen | grep -v unbound | grep -v finch | awk '/^rc/ { print $2 }') && \
137apt purge $(dpkg -l | grep lenny | grep -v xen | awk '/^rc/ { print $2 }') && \
138apt purge $(dpkg -l | grep -E 'deb6|squeeze' | grep -v xen | awk '/^rc/ { print $2 }') && \
139apt purge $(dpkg -l | grep -E 'deb7|wheezy' | grep -v xen | grep -v -E 'linux-image|mailscanner|openswan|debian-security-support' | awk '/^rc/ { print $2 }') && \
140apt purge $(dpkg -l | grep -E 'deb8|jessie' | grep -v xen | grep -v -E 'linux-image|debian-security-support' | awk '{ print $2 }') && \
141apt purge $(dpkg -l | grep -E 'deb9|stretch' | grep -v xen | grep -v -E 'linux-image|debian-security-support|icinga2|phpmyadmin' | awk '{ print $2 }') && \
142apt purge $(dpkg -l | grep -E 'deb10|buster' | grep -v xen | grep -v -E 'linux-image|debian-security-support|icinga2|phpmyadmin' | awk '{ print $2 }') && \
143apt -y install deborphan && apt purge $(deborphan | grep -v xen | grep -v -E 'libpam-cracklib|libapache2-mpm-itk')
144apt purge $(dpkg -l | awk '/^rc/ { print $2 }')
145
146# for the brave YoloOps crowd
147reboot && sleep 180; echo u > /proc/sysrq-trigger ; sleep 2 ; echo s > /proc/sysrq-trigger ; sleep 2 ; echo b > /proc/sysrq-trigger
148
149### not needed until now
150# Upgrade postgres
151# See also https://www.debian.org/releases/buster/amd64/release-notes/ch-information.de.html#plperl
152if [ "$(dpkg -l | grep "postgresql-9.4" | awk {'print $2'})" = "postgresql-9.4" ]; then \
153 apt install postgresql-9.6 && \
154 pg_dropcluster --stop 9.6 main && \
155 /etc/init.d/postgresql stop && \
156 pg_upgradecluster -v 9.6 9.4 main && \
157 sed -i "s/^manual/auto/g" /etc/postgresql/9.6/main/start.conf && \
158 sed -i "s/^port = .*/port = 5432/" /etc/postgresql/9.6/main/postgresql.conf && \
159 sed -i "s/^shared_buffers = .*/shared_buffers = 128MB/" /etc/postgresql/9.6/main/postgresql.conf && \
160 /etc/init.d/postgresql restart; \
161fi
162pg_dropcluster 9.4 main
163