Automated migration from a Debian bullseye/buster system to Devuan chimaera/beowulf.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.5 KiB

  1. #!/bin/bash
  2. cd $(dirname $0)
  3. set -x
  4. set -e
  5. if [ "$1" != "1" ] && [ "$1" != "2" ] ; then
  6. cat <<EOF >&2
  7. ** This script performs "apt migration" from Debian bullseye/buster to
  8. ** Devuan chimaera/beowulf.
  9. ** It takes one argument:
  10. ** 1 = (stage 1) change the init system (and some little) and reboot
  11. ** 2 = (stage 2) upgrade to target distribution and reboot
  12. **
  13. ** Use "DIST=beowulf $0 1" to select beowulf.
  14. ** Use "DE=desktop $0 1" to get desktop.
  15. ** Use "DIST=beowulf DE=desktop $0 1" to get both.
  16. EOF
  17. exit 1
  18. fi
  19. : ${DIST:=chimaera} # beowulf
  20. if [ "$DIST" != beowulf ] && [ "$DIST" != chimaera ] ; then
  21. cat <<EOF >&2
  22. ** DIST=$DIST migration is not supported; use DIST=beowulf or chimaera
  23. EOF
  24. exit 1
  25. fi
  26. if [ "$DE" != "" ] && [ "$DE" != "desktop" ] && [ "$DE" != "xfce" ] &&
  27. [ "$DE" != "mate" ] && [ "$DE" != "cinnamon" ] &&
  28. [ "$DE" != "kde" ] ; then
  29. cat <<EOF >&2
  30. ** DE=$DE migration is not supported; use DE=desktop or empty
  31. EOF
  32. exit 1
  33. fi
  34. touch /root/migrate.log
  35. tail -f /root/migrate.log &
  36. exec 1>>/root/migrate.log 2>&1
  37. date -R
  38. echo "arg = $*"
  39. export DEBIAN_FRONTEND=noninteractive
  40. export APT_LISTCHANGES_FRONTEND=none
  41. ENI=/etc/network/interfaces
  42. case "$1" in
  43. 1) # FIRST STAGE
  44. #
  45. # prepare $ENI for proper interface naming
  46. # download and install the Devuan keyring
  47. # install sysvinit-core, to replace systemd at next boot
  48. # disable dbus for the sysvinit boot, and remove some stuff
  49. # set up automatic second stage at boot
  50. eni_snippet() {
  51. cat << EOF >> $ENI
  52. #-- Snippet to bring up $1 - the $2 named wired interface
  53. auto $1
  54. iface $1 inet dhcp
  55. #--
  56. EOF
  57. }
  58. IFACE="$(ip route | awk '$1 == "default" { print $5; exit; }')"
  59. grep -qw eth0 $ENI || eni_snippet eth0 $DIST
  60. [ "$IFACE" = "eth0" ] || [[ "$IFACE" != e* ]] || \
  61. eni_snippet $IFACE buster
  62. wget https://pkgmaster.devuan.org/devuan/pool/main/d/devuan-keyring/devuan-keyring_2017.10.03_all.deb
  63. dpkg -i devuan-keyring_2017.10.03_all.deb
  64. apt-get update -y -q
  65. apt-get -y install sysvinit-core
  66. update-rc.d dbus disable
  67. apt-get -y purge avahi-daemon sane-utils
  68. touch /etc/rc.local
  69. chmod a+x /etc/rc.local
  70. mv /etc/rc.local /etc/rc.local.ORIG
  71. cat <<EOF > /etc/rc.local
  72. #!/bin/sh
  73. # Perform stage 2 of Devuan $DIST migration
  74. /usr/sbin/sshd -D
  75. cd $(pwd)
  76. DIST=$DIST DE=$DE ./$(basename $0) 2
  77. EOF
  78. chmod a+x /etc/rc.local
  79. # Clean out unused packages and reboot
  80. apt-get -y autoremove --purge
  81. echo
  82. echo "Stage 1 completed!"
  83. echo
  84. echo "Now try to reboot using:"
  85. echo "init 6"
  86. echo " or"
  87. echo "systemctl reboot"
  88. echo
  89. echo "Next reboot will perform a dist-upgrade"
  90. echo "Please be patient and wait it completes with another reboot"
  91. echo "Login via ssh and use 'watch ps af' to monitor progress"
  92. ;;
  93. 2) # SECOND STAGE
  94. # restore to "normal" boot
  95. # set up the new sources.list to use $DIST
  96. # update, dist-upgrade and some fixup
  97. # optionally install the xfce desktop environment
  98. [ -f /etc/rc.local.ORIG ] && mv /etc/rc.local.ORIG /etc/rc.local
  99. mv /etc/apt/sources.list /etc/apt/sources.list.ORIG
  100. cat << END > /etc/apt/sources.list
  101. deb http://deb.devuan.org/merged $DIST main contrib non-free
  102. deb http://deb.devuan.org/merged $DIST-updates main contrib non-free
  103. END
  104. apt-get -y update
  105. apt-get -y dist-upgrade
  106. apt-get -y install libelogind0
  107. apt-get -y purge dbus-user-session libnss-systemd systemd plymouth
  108. case "$DE" in
  109. desktop)
  110. apt-get -y install task-xfce-desktop
  111. ;;
  112. xfce|mate|cinnamon|kde)
  113. apt-get -y install task-$DE-desktop
  114. ;;
  115. *)
  116. :
  117. ;;
  118. esac
  119. # Clean out unused packages and reboot
  120. apt-get -y autoremove --purge
  121. reboot
  122. ;;
  123. esac