Script to migrate a standard Debian install to Devuan.
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.

485 lines
15 KiB

  1. #!/bin/sh
  2. #############################################################
  3. # Debian to Devuan Migrator v.1.8 for desktops #
  4. # #
  5. # farmatito (c) 2021 <farmatito@tiscali.it> GPLv2 #
  6. # Script to migrate a standard debian install to devuan #
  7. # Supported OS versions: #
  8. # a) Debian buster to Devuan beowulf #
  9. # #
  10. # Supported DE's: #
  11. # 1) GNOME #
  12. # 2) LXDE #
  13. # 3) LXQT #
  14. # 4) XFCE #
  15. # 5) KDE #
  16. # 6) MATE #
  17. # 7) CINNAMON #
  18. #############################################################
  19. FOUND_DE=0
  20. GNOME=0
  21. LXDE=0
  22. LXQT=0
  23. XFCE=0
  24. KDE=0
  25. MATE=0
  26. CINNAMON=0
  27. NETWORK=0
  28. INSTALL_SLIM=0
  29. INSTALL_DBUS=0
  30. _CONTRIB=""
  31. _NONFREE=""
  32. . /etc/os-release
  33. # Prepare for next Debian release and detect version
  34. if test "x$VERSION_ID" = "x10" ; then
  35. echo "Detected: Debian $VERSION"
  36. DEVUAN_CODENAME="beowulf"
  37. else
  38. if test "x$VERSION_ID" = "x11" ; then
  39. echo "Detected: Debian $VERSION"
  40. DEVUAN_CODENAME="chimaera"
  41. fi
  42. fi
  43. # PROGRAMS NEEDED
  44. # TODO test if all needed programs are there (Paranoia)
  45. # CURRENT DEVUAN KEYRING PACKAGE
  46. DEVUAN_KEYRING="devuan-keyring_2017.10.03_all.deb"
  47. # SET PATH
  48. export PATH=$PATH:/usr/sbin:/sbin
  49. # CHECK FOR ROOT
  50. ID=$(id -u)
  51. if test $ID -ne 0 ; then
  52. echo "You need root permissions to run this script. Exiting..."
  53. exit 1
  54. fi
  55. # TEST NETWORK AS MIGRATION WILL FAIL IF NOT ONLINE
  56. NETWORK=$(printf "GET /nm HTTP/1.1\\r\\nHost: network-test.debian.org\\r\\n\\r\\n" | nc -w1 network-test.debian.org 80 | grep -c "NetworkManager is online")
  57. if test $NETWORK -ne 1 ; then
  58. NETWORK=$(printf "GET /ncsi.txt HTTP/1.1\\r\\nHost: www.msftncsi.com\\r\\n\\r\\n" | nc -w1 www.msftncsi.com 80 | grep -c "Microsoft NCSI")
  59. if test $NETWORK -ne 1 ; then
  60. echo "Your network seems to be down. "
  61. echo "Cannot connect to the Internet. Exiting..."
  62. exit 1
  63. fi
  64. fi
  65. #echo "Network Connectivity Status: OK"
  66. # DISCLAIMER #
  67. echo "Warning use at your own risk. BACKUP YOUR DATA FIRST!!!"
  68. echo "Are you sure? [y|n]"
  69. read -r ANS
  70. if test "x$ANS" != "xy" -a "x$ANS" != "xY"; then
  71. exit 0
  72. fi
  73. # TODO ntpdate is deprecated so we need to switch to
  74. # ntpsec-ntpdate or sntp -S pool.ntp.org
  75. # this is less ideal as they have more dependencies.
  76. # INSTALL NTPDATE IF NEEDED
  77. NTPDATE=$(which ntpdate-debian)
  78. if test -x "$NTPDATE" ; then
  79. echo "ntpdate-debian is already installed...good"
  80. # Wrong date and time is one of the causes of failure of apt update
  81. # and subsequent devuan deb packages download which breaks
  82. # the migration process, so we ensure that date and time are set correctly
  83. else
  84. apt install ntpdate
  85. fi
  86. echo "Setting date and time with ntpdate-debian"
  87. ntpdate-debian
  88. # INSTALL WGET IF NEEDED
  89. WGET=$(which wget)
  90. if test -x "$WGET" ; then
  91. echo "wget is already installed...good"
  92. else
  93. apt install wget
  94. fi
  95. # DOWNLOAD DEVUAN KEYRING AND IMPLICIT TEST FOR NETWORK
  96. wget http://deb.devuan.org/devuan/pool/main/d/devuan-keyring/"$DEVUAN_KEYRING"
  97. if test $? -ne 0 ; then
  98. echo "Could not download Devuan Keyring: $DEVUAN_KEYRING"
  99. echo "Exiting..."
  100. exit 1
  101. fi
  102. # INSTALL BEOWULF PACKAGES TO INIT MIGRATION
  103. dpkg -L task-gnome-desktop > /dev/null 2>&1
  104. if test $? -eq 0 ; then
  105. echo "Detected GNOME DE"
  106. GNOME=1
  107. FOUND_DE=1
  108. INSTALL_SLIM=1
  109. INSTALL_DBUS=1
  110. else
  111. dpkg -L task-lxde-desktop > /dev/null 2>&1
  112. if test $? -eq 0 ; then
  113. echo "Detected LXDE DE"
  114. LXDE=1
  115. FOUND_DE=1
  116. INSTALL_DBUS=1
  117. else
  118. dpkg -L task-lxqt-desktop > /dev/null 2>&1
  119. if test $? -eq 0 ; then
  120. echo "Detected LXQT DE"
  121. LXQT=1
  122. FOUND_DE=1
  123. INSTALL_DBUS=1
  124. else
  125. dpkg -L task-xfce-desktop > /dev/null 2>&1
  126. if test $? -eq 0 ; then
  127. echo "Detected XFCE DE"
  128. XFCE=1
  129. FOUND_DE=1
  130. INSTALL_DBUS=1
  131. else
  132. dpkg -L task-kde-desktop > /dev/null 2>&1
  133. if test $? -eq 0 ; then
  134. echo "Detected KDE DE"
  135. KDE=1
  136. FOUND_DE=1
  137. INSTALL_DBUS=1
  138. else
  139. dpkg -L task-mate-desktop > /dev/null 2>&1
  140. if test $? -eq 0 ; then
  141. echo "Detected MATE DE"
  142. MATE=1
  143. FOUND_DE=1
  144. INSTALL_DBUS=1
  145. else
  146. dpkg -L task-cinnamon-desktop > /dev/null 2>&1
  147. if test $? -eq 0 ; then
  148. echo "Detected CINNAMON DE"
  149. CINNAMON=1
  150. FOUND_DE=1
  151. INSTALL_DBUS=1
  152. fi
  153. fi
  154. fi
  155. fi
  156. fi
  157. fi
  158. fi
  159. if test $FOUND_DE -eq 0 ; then
  160. echo "No supported Desktop Environment detected!"
  161. #echo "Is this a server?"
  162. echo "Are you sure you want to continue? [y|n]"
  163. read -r ANS
  164. if test "x$ANS" != "xy" -a "x$ANS" != "xY"; then
  165. exit 0
  166. fi
  167. fi
  168. # RESTORE OLD SU BEHAVIOUR - no keep as before
  169. #echo "ALWAYS_SET_PATH yes" > /etc/default/su
  170. echo "Do you want contrib repos to be included in your apt sources? [y|n]"
  171. read -r ANS
  172. if test "x$ANS" = "xy" -o "x$ANS" = "xY"; then
  173. _CONTRIB=" contrib"
  174. fi
  175. echo "Do you want non-free repos to be included in your apt sources? [y|n]"
  176. read -r ANS
  177. if test "x$ANS" = "xy" -o "x$ANS" = "xY"; then
  178. _NONFREE=" non-free"
  179. fi
  180. # ADD BEOWULF REPOS
  181. # TODO use mktemp /etc/apt/sources.list.d/XXXXXXXXX here and
  182. # only add to sources.list if migration is successful?
  183. # Cleanup in case of failure would be easier this way.
  184. { echo ""; \
  185. echo "deb http://deb.devuan.org/merged $DEVUAN_CODENAME main$_CONTRIB$_NONFREE"; \
  186. echo "deb http://deb.devuan.org/merged $DEVUAN_CODENAME-updates main$_CONTRIB$_NONFREE"; \
  187. echo "deb http://deb.devuan.org/merged $DEVUAN_CODENAME-security main$_CONTRIB$_NONFREE"; } >> /etc/apt/sources.list
  188. # PIN PREFERENCE FOR DEVUAN PACKGES
  189. # TODO use mktemp /etc/apt/preferences.d/XXXXXXXXX ?
  190. { echo "Package: *"; \
  191. echo "Pin: origin \"deb.devuan.org\""; \
  192. echo "Pin-Priority: 900"; } > /etc/apt/preferences.d/"$DEVUAN_CODENAME"
  193. # STOP THE TIMERS FOR APT TO AVOID INTERFERENCES (FILE LOCKS)
  194. systemctl stop apt-daily.timer
  195. systemctl stop apt-daily-upgrade.timer
  196. # INSTALL DEVUAN KEYRING
  197. dpkg -i "$DEVUAN_KEYRING"
  198. rm -f "$DEVUAN_KEYRING"
  199. # UPDATE
  200. apt update
  201. # INSTALL BEOWULF PACKAGES TO INIT MIGRATION
  202. if test $GNOME -eq 1 ; then
  203. apt install task-gnome-desktop debian-pulseaudio-config-override -y
  204. # DISABLE GDM3 TO AVOID BLACK SCREEN AT REBOOT
  205. systemctl disable gdm3
  206. fi
  207. if test $LXDE -eq 1 ; then
  208. apt install task-lxde-desktop debian-pulseaudio-config-override -y
  209. fi
  210. if test $LXQT -eq 1 ; then
  211. echo "* Select Lightdm as Display manager when prompted! *"
  212. echo "* Hit Enter to continue *"
  213. read -r DUMMY
  214. apt install task-lxqt-desktop debian-pulseaudio-config-override -y
  215. fi
  216. if test $XFCE -eq 1 ; then
  217. # Don't install recommends for task-xfce-desktop as it sucks in wicd but
  218. # migrating user is used to network-manager and this will spoil his experience.
  219. apt install task-xfce-desktop --no-install-recommends -y
  220. apt install debian-pulseaudio-config-override -y
  221. # Set network-manager to manually installed or it will be autoremoved later.
  222. apt install network-manager -y
  223. apt install network-manager-gnome -y
  224. fi
  225. if test $KDE -eq 1 ; then
  226. echo "* Select slim as Display manager when prompted! *"
  227. echo "* Hit Enter to continue *"
  228. read -r DUMMY
  229. apt install task-kde-desktop slim --no-install-recommends -y
  230. apt install debian-pulseaudio-config-override -y
  231. systemctl disable sddm
  232. systemctl disable slim
  233. #apt install network-manager -y
  234. #apt install plasm-nm -y
  235. fi
  236. if test $MATE -eq 1 ; then
  237. # Don't install recommends for task-mate-desktop as it sucks in wicd but
  238. # migrating user is used to network-manager and this will spoil his experience.
  239. apt install task-mate-desktop --no-install-recommends -y
  240. apt install debian-pulseaudio-config-override -y
  241. # Set network-manager to manually installed or it will be autoremoved later.
  242. apt install network-manager -y
  243. apt install network-manager-gnome -y
  244. fi
  245. if test $CINNAMON -eq 1 ; then
  246. apt install task-cinnamon-desktop debian-pulseaudio-config-override -y
  247. #apt install network-manager -y
  248. #apt install network-manager-gnome -y
  249. fi
  250. # DOWNLOAD PACKAGES FOR LATER USE
  251. apt-get download util-linux
  252. if test $? -ne 0 ; then
  253. echo "Failed to download util-linux, exiting..."
  254. exit 1
  255. fi
  256. apt-get download libelogind0
  257. if test $? -ne 0 ; then
  258. echo "Failed to download libelogind0, exiting..."
  259. exit 1
  260. fi
  261. apt-get download libpam-elogind
  262. if test $? -ne 0 ; then
  263. echo "Failed to download libpam-elogind, exiting..."
  264. exit 1
  265. fi
  266. apt-get download elogind
  267. if test $? -ne 0 ; then
  268. echo "Failed to download elogind, exiting..."
  269. exit 1
  270. fi
  271. apt-get download init
  272. if test $? -ne 0 ; then
  273. echo "Failed to download init, exiting..."
  274. exit 1
  275. fi
  276. apt-get download sysvinit-core
  277. if test $? -ne 0 ; then
  278. echo "Failed to download sysvinit-core, exiting..."
  279. exit 1
  280. fi
  281. apt-get download initscripts
  282. if test $? -ne 0 ; then
  283. echo "Failed to download initscripts, exiting..."
  284. exit 1
  285. fi
  286. apt-get download sysv-rc
  287. if test $? -ne 0 ; then
  288. echo "Failed to download sysv-rc, exiting..."
  289. exit 1
  290. fi
  291. apt-get download insserv
  292. if test $? -ne 0 ; then
  293. echo "Failed to download insserv, exiting..."
  294. exit 1
  295. fi
  296. apt-get download startpar
  297. if test $? -ne 0 ; then
  298. echo "Failed to download startpar, exiting..."
  299. exit 1
  300. fi
  301. apt-get download eudev
  302. if test $? -ne 0 ; then
  303. echo "Failed to download eudev, exiting..."
  304. exit 1
  305. fi
  306. apt-get download libeudev1
  307. if test $? -ne 0 ; then
  308. echo "Failed to download libeudev1, exiting..."
  309. exit 1
  310. fi
  311. if test $INSTALL_DBUS -eq 1 ; then
  312. apt-get download dbus
  313. if test $? -ne 0 ; then
  314. echo "Failed to download dbus, exiting..."
  315. exit 1
  316. fi
  317. apt-get download dbus-x11
  318. if test $? -ne 0 ; then
  319. echo "Failed to download dbus-x11, exiting..."
  320. exit 1
  321. fi
  322. apt-get download libdbus-1-3
  323. if test $? -ne 0 ; then
  324. echo "Failed to download libdbus-1-3, exiting..."
  325. exit 1
  326. fi
  327. fi
  328. # REMOVE SOME SYSTEMD RELATED PACKAGES THAT GET IN THE WAY
  329. dpkg --purge --force-all dbus-user-session
  330. dpkg --purge --force-all iio-sensor-proxy
  331. dpkg --purge --force-all libnss-systemd
  332. dpkg --purge --force-all libpam-systemd
  333. dpkg --purge --force-all plymouth-label
  334. dpkg --purge --force-all plymouth
  335. dpkg --purge --force-all libplymouth4
  336. # Don't remove breaks desktop-base
  337. #dpkg --purge --force-all fonts-quicksand
  338. dpkg --purge --force-all udev
  339. dpkg --purge --force-all libudev1
  340. # DETECT LIBSYSTEMD AND SAVE A COPY TO KEEP APT HAPPY
  341. LIBSYSTEMD=$(dpkg -L libsystemd0 | grep ".so.0.")
  342. cp "$LIBSYSTEMD" "$LIBSYSTEMD".bak
  343. # BEGIN TO REMOVE SYSTEMD
  344. dpkg --purge --force-all systemd-sysv
  345. # Don't remove it here we need it to reboot the box
  346. #dpkg --purge --force-all systemd
  347. dpkg --purge --force-all libsystemd0
  348. cp "$LIBSYSTEMD".bak "$LIBSYSTEMD"
  349. # FORCE INSTALL DEVUAN PACKAGES TO BE SURE
  350. dpkg -i --force-all ./libeudev1*.deb
  351. dpkg -i --force-all ./util-linux*.deb
  352. dpkg -i --force-all ./libelogind0*.deb
  353. dpkg -i --force-all ./elogind*.deb
  354. dpkg -i --force-all ./libpam-elogind*.deb
  355. dpkg -i --force-all ./eudev*.deb
  356. dpkg -i --force-all ./insserv*.deb
  357. dpkg -i --force-all ./startpar*.deb
  358. dpkg -i --force-all ./sysv-rc*.deb
  359. dpkg -i --force-all ./initscripts*.deb
  360. dpkg -i --force-all ./sysvinit-core*.deb
  361. dpkg -i --force-all ./init*.deb
  362. if test $INSTALL_DBUS -eq 1 ; then
  363. dpkg -i --force-all ./dbus_*.deb
  364. dpkg -i --force-all ./dbus-x11*.deb
  365. dpkg -i --force-all ./libdbus*.deb
  366. fi
  367. # CLEANUP
  368. rm -f util-linux*.deb
  369. rm -f libelogind0*.deb
  370. rm -f libpam-elogind*.deb
  371. rm -f elogind*.deb
  372. rm -f init*.deb
  373. rm -f initscripts*.deb
  374. rm -f sysv-rc*.deb
  375. rm -f sysvinit-core*.deb
  376. rm -f insserv*.deb
  377. rm -f startpar*.deb
  378. rm -f eudev*.deb
  379. rm -f libeudev1*.deb
  380. if test $INSTALL_DBUS -eq 1 ; then
  381. rm -f dbus_*.deb
  382. rm -f dbus-x11*.deb
  383. rm -f libdbus*.deb
  384. fi
  385. # CHECK FOR INITTAB AND INSTALL IF MISSING
  386. if test -f /etc/inittab ; then
  387. echo "Checking for existence of /etc/inittab: found"
  388. else
  389. cp /usr/share/sysvinit/inittab /etc/inittab
  390. fi
  391. # INSTRUCTIONS FOR STAGE 2
  392. INFOTMP=$(mktemp Info-XXXXXXXX.txt)
  393. { echo "********************************************************************************"; \
  394. if test $KDE -eq 1 -o $GNOME -eq 1 ; then
  395. echo "* You will be rebooted to console. *"; \
  396. fi
  397. echo "* After reboot remove references to debian $VERSION_CODENAME from /etc/apt/sources.list *" ; \
  398. echo "* and run in a root terminal: export PATH=\$PATH:/usr/sbin:/sbin *" ; \
  399. echo "* and run: dpkg --purge --force-all systemd *" ; \
  400. if test $LXQT -eq 1 -o $LXDE -eq 1 ; then
  401. echo "* reconfigure your /etc/network/interfaces file to use old-fashion network *" ; \
  402. echo "* names e.g. eth0 or wlan0 (or add net.ifnames=1 to grub command line), *" ; \
  403. echo "* you will be prompted to do it now if you like *" ; \
  404. fi
  405. if test $LXDE -eq 1 ; then
  406. echo "* also check and reconfigure your wicd preferences *" ; \
  407. fi
  408. if test $LXQT -eq 1 ; then
  409. echo "* also check and reconfigure your connman-ui preferences *" ; \
  410. fi
  411. echo "* and run: apt install --reinstall elogind *" ; \
  412. echo "* and run: apt update *" ; \
  413. echo "* and run: apt upgrade *" ; \
  414. echo "* and run: apt dist-upgrade *" ; \
  415. # Don't run apt autoremove --purge or we risk deleting some conf files from packages
  416. # we erroneously removed
  417. echo "* and run: apt autoremove *" ; \
  418. if test $INSTALL_SLIM -eq 1 ; then
  419. echo "* and run: apt install slim (and select slim as display manager) *" ; \
  420. fi
  421. if test $KDE -eq 1 ; then
  422. echo "* and run: update-rc.d slim enable *" ; \
  423. fi
  424. echo "* and run: reboot *" ; \
  425. echo "********************************************************************************" ; } | tee "$PWD/$INFOTMP"
  426. echo "You can find these instructions in the file: $PWD/$INFOTMP"
  427. if test $LXQT -eq 1 -o $LXDE -eq 1 ; then
  428. # WAIT FOR USER TO READ
  429. echo "Hit Enter to continue"
  430. read -r DUMMY
  431. echo "Do you want to edit /etc/network/interfaces now? [y|n]"
  432. read -r ANS
  433. if test "x$ANS" = "xy" -o "x$ANS" = "xY"; then
  434. cp /etc/network/interfaces /etc/network/interfaces.bak
  435. nano /etc/network/interfaces
  436. fi
  437. fi
  438. # DONE
  439. echo "Hit Enter to reboot"
  440. read -r DUMMY
  441. # CLEANUP
  442. rm -f /etc/apt/preferences.d/"$DEVUAN_CODENAME"
  443. rm -f "$LIBSYSTEMD"
  444. # SYSTEMD IS STILL RUNNING SO USE IT FOR A CLEANER REBOOT
  445. systemctl reboot