freedombone-restore-local 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Restore from local storage - typically a USB drive
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  31. BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
  32. # whether to restore everything or just a specific application
  33. RESTORE_APP='all'
  34. export TEXTDOMAIN=${PROJECT_NAME}-restore-local
  35. export TEXTDOMAINDIR="/usr/share/locale"
  36. USB_DRIVE=/dev/sdb1
  37. USB_MOUNT=/mnt/usb
  38. # get default USB from config file
  39. CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
  40. if [ -f $CONFIG_FILE ]; then
  41. if grep -q "USB_DRIVE=" $CONFIG_FILE; then
  42. USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
  43. fi
  44. fi
  45. ADMIN_USERNAME=
  46. ADMIN_NAME=
  47. # MariaDB password
  48. DATABASE_PASSWORD=$(cat /root/dbpass)
  49. MICROBLOG_DOMAIN_NAME=
  50. HUBZILLA_DOMAIN_NAME=
  51. OWNCLOUD_DOMAIN_NAME=
  52. GIT_DOMAIN_NAME=
  53. WIKI_DOMAIN_NAME=
  54. FULLBLOG_DOMAIN_NAME=
  55. function mount_drive {
  56. if [ $1 ]; then
  57. USB_DRIVE=/dev/${1}1
  58. fi
  59. # get the admin user
  60. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  61. if [ $2 ]; then
  62. ADMIN_USERNAME=$2
  63. fi
  64. ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
  65. # check that the backup destination is available
  66. if [ ! -b $USB_DRIVE ]; then
  67. echo $"Please attach a USB drive"
  68. exit 1
  69. fi
  70. # unmount if already mounted
  71. umount -f $USB_MOUNT
  72. if [ ! -d $USB_MOUNT ]; then
  73. mkdir $USB_MOUNT
  74. fi
  75. if [ -f /dev/mapper/encrypted_usb ]; then
  76. rm -rf /dev/mapper/encrypted_usb
  77. fi
  78. cryptsetup luksClose encrypted_usb
  79. # mount the encrypted backup drive
  80. cryptsetup luksOpen $USB_DRIVE encrypted_usb
  81. if [ "$?" = "0" ]; then
  82. USB_DRIVE=/dev/mapper/encrypted_usb
  83. fi
  84. mount $USB_DRIVE $USB_MOUNT
  85. if [ ! "$?" = "0" ]; then
  86. echo $"There was a problem mounting the USB drive to $USB_MOUNT"
  87. rm -rf $USB_MOUNT
  88. exit 2
  89. fi
  90. }
  91. function unmount_drive {
  92. sync
  93. umount $USB_MOUNT
  94. if [ ! "$?" = "0" ]; then
  95. echo $"Unable to unmount the drive. This means that the backup did not work"
  96. rm -rf $USB_MOUNT
  97. exit 9
  98. fi
  99. rm -rf $USB_MOUNT
  100. echo $"Setting permissions"
  101. for d in /home/*/ ; do
  102. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  103. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  104. chown -R $USERNAME:$USERNAME /home/$USERNAME
  105. fi
  106. done
  107. if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
  108. echo $"Unmount encrypted USB"
  109. cryptsetup luksClose encrypted_usb
  110. fi
  111. if [ -f /dev/mapper/encrypted_usb ]; then
  112. rm -rf /dev/mapper/encrypted_usb
  113. fi
  114. }
  115. function check_backup_exists {
  116. if [ ! -d $USB_MOUNT/backup ]; then
  117. echo $"No backup directory found on the USB drive."
  118. unmount_drive
  119. exit 2
  120. fi
  121. }
  122. function check_admin_user {
  123. echo $"Checking that admin user exists"
  124. if [ ! -d /home/$ADMIN_USERNAME ]; then
  125. echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username."
  126. unmount_drive
  127. exit 295
  128. fi
  129. }
  130. function copy_gpg_keys {
  131. echo $"Copying GPG keys from admin user to root"
  132. cp -r /home/$ADMIN_USERNAME/.gnupg /root
  133. }
  134. function restore_directory_from_usb {
  135. if [ ! -d ${1} ]; then
  136. mkdir ${1}
  137. fi
  138. obnam restore -r $USB_MOUNT/backup/${2} --to ${1}
  139. }
  140. function restore_database {
  141. RESTORE_SUBDIR="root"
  142. if [ -d $USB_MOUNT/backup/${1} ]; then
  143. echo $"Restoring ${1} database"
  144. restore_directory_from_usb "/root/temp${1}data" "${1}data"
  145. if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
  146. echo $"Unable to restore ${1} database"
  147. rm -rf /root/temp${1}data
  148. unmount_drive
  149. exit 503
  150. fi
  151. mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
  152. if [ ! "$?" = "0" ]; then
  153. echo "$mysqlsuccess"
  154. unmount_drive
  155. exit 964
  156. fi
  157. shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
  158. rm -rf /root/temp${1}data
  159. echo $"Restoring ${1} installation"
  160. if [ ! -d /root/temp${1} ]; then
  161. mkdir /root/temp${1}
  162. fi
  163. restore_directory_from_usb "/root/temp${1}" "${1}"
  164. RESTORE_SUBDIR="var"
  165. if [ ${2} ]; then
  166. # special handline of ttrss
  167. if [[ ${2} == "ttrss" ]]; then
  168. if [ -d /etc/share/tt-rss ]; then
  169. if [ -d /root/temp${1}/etc/share/tt-rss ]; then
  170. rm -rf /etc/share/tt-rss
  171. mv /root/temp${1}/etc/share/tt-rss /etc/share/
  172. if [ ! "$?" = "0" ]; then
  173. unmount_drive
  174. exit 528
  175. fi
  176. if [ -d /etc/letsencrypt/live/${2} ]; then
  177. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  178. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  179. else
  180. # Ensure that the bundled SSL cert is being used
  181. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  182. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  183. fi
  184. fi
  185. fi
  186. fi
  187. fi
  188. if [ -d /var/www/${2}/htdocs ]; then
  189. if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
  190. rm -rf /var/www/${2}/htdocs
  191. mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
  192. if [ ! "$?" = "0" ]; then
  193. unmount_drive
  194. exit 683
  195. fi
  196. if [ -d /etc/letsencrypt/live/${2} ]; then
  197. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  198. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  199. else
  200. # Ensure that the bundled SSL cert is being used
  201. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  202. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  203. fi
  204. fi
  205. fi
  206. fi
  207. fi
  208. fi
  209. }
  210. function update_domains {
  211. if grep -q "RSS reader domain" $COMPLETION_FILE; then
  212. RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
  213. fi
  214. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  215. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  216. fi
  217. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  218. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  219. fi
  220. if grep -q "Owncloud domain" $COMPLETION_FILE; then
  221. OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
  222. fi
  223. if grep -q "Gogs domain" $COMPLETION_FILE; then
  224. GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
  225. fi
  226. if [ -d $USB_MOUNT/backup/wiki ]; then
  227. WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
  228. fi
  229. if [ -d $USB_MOUNT/backup/blog ]; then
  230. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  231. fi
  232. }
  233. function restore_configuration {
  234. if [[ $RESTORE_APP != 'all' ]]; then
  235. if [[ $RESTORE_APP != 'configuration' ]]; then
  236. return
  237. fi
  238. fi
  239. # this restores *.cfg and COMPLETION_FILE
  240. if [ -d $USB_MOUNT/backup/config ]; then
  241. echo $"Restoring configuration files"
  242. restore_directory_from_usb /root/tempconfig config
  243. cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
  244. if [ ! "$?" = "0" ]; then
  245. unmount_drive
  246. rm -rf /root/tempconfig
  247. exit 5294
  248. fi
  249. if [ -f $CONFIG_FILE ]; then
  250. # install according to the config file
  251. freedombone -c $CONFIG_FILE
  252. fi
  253. cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
  254. if [ ! "$?" = "0" ]; then
  255. unmount_drive
  256. rm -rf /root/tempconfig
  257. exit 6382
  258. fi
  259. if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then
  260. cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
  261. if [ ! "$?" = "0" ]; then
  262. unmount_drive
  263. rm -rf /root/tempconfig
  264. exit 62121
  265. fi
  266. fi
  267. rm -rf /root/tempconfig
  268. fi
  269. }
  270. function same_admin_user {
  271. PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  272. if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then
  273. echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME"
  274. unmount_drive
  275. exit 73265
  276. fi
  277. }
  278. function restore_mariadb {
  279. if [[ $RESTORE_APP != 'all' ]]; then
  280. if [[ $RESTORE_APP != 'mariadb' ]]; then
  281. return
  282. fi
  283. fi
  284. if [ -d $USB_MOUNT/backup/mariadb ]; then
  285. echo $"Restoring mysql settings"
  286. restore_directory_from_usb /root/tempmariadb mariadb
  287. echo $"Get the MariaDB password from the backup"
  288. if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then
  289. echo $"MariaDB password file not found"
  290. exit 495
  291. fi
  292. BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db)
  293. if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then
  294. echo $"Restore the MariaDB user table"
  295. mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql)
  296. if [ ! "$?" = "0" ]; then
  297. echo $"Try again using the password obtained from backup"
  298. mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql)
  299. fi
  300. if [ ! "$?" = "0" ]; then
  301. echo "$mysqlsuccess"
  302. unmount_drive
  303. exit 962
  304. fi
  305. echo $"Restarting database"
  306. service mysql restart
  307. echo $"Change the MariaDB password to the backup version"
  308. DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD
  309. fi
  310. shred -zu /root/tempmariadb/root/tempmariadb/db
  311. rm -rf /root/tempmariadb
  312. # Change database password file
  313. echo "$DATABASE_PASSWORD" > /root/dbpass
  314. chmod 600 /root/dbpass
  315. fi
  316. }
  317. function restore_letsencrypt {
  318. if [[ $RESTORE_APP != 'all' ]]; then
  319. if [[ $RESTORE_APP != 'letsencrypt' ]]; then
  320. return
  321. fi
  322. fi
  323. if [ -d $USB_MOUNT/backup/letsencrypt ]; then
  324. echo $"Restoring Lets Encrypt settings"
  325. restore_directory_from_usb / letsencrypt
  326. fi
  327. }
  328. function restore_tor {
  329. if [[ $RESTORE_APP != 'all' ]]; then
  330. if [[ $RESTORE_APP != 'tor' ]]; then
  331. return
  332. fi
  333. fi
  334. if [ -d $USB_MOUNT/backup/tor ]; then
  335. echo $"Restoring Tor settings"
  336. restore_directory_from_usb / tor
  337. fi
  338. }
  339. function restore_mutt_settings {
  340. if [[ $RESTORE_APP != 'all' ]]; then
  341. if [[ $RESTORE_APP != 'mutt' ]]; then
  342. return
  343. fi
  344. fi
  345. if [ -d $USB_MOUNT/backup/mutt ]; then
  346. for d in $USB_MOUNT/backup/mutt/*/ ; do
  347. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  348. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  349. if [ ! -d /home/$USERNAME ]; then
  350. ${PROJECT_NAME}-adduser $USERNAME
  351. fi
  352. echo $"Restoring Mutt settings for $USERNAME"
  353. restore_directory_from_usb /root/tempmutt mutt/$USERNAME
  354. if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then
  355. cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
  356. fi
  357. if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then
  358. cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
  359. fi
  360. if [ ! "$?" = "0" ]; then
  361. rm -rf /root/tempmutt
  362. unmount_drive
  363. exit 276
  364. fi
  365. rm -rf /root/tempmutt
  366. fi
  367. done
  368. fi
  369. }
  370. function restore_gpg {
  371. if [[ $RESTORE_APP != 'all' ]]; then
  372. if [[ $RESTORE_APP != 'gpg' ]]; then
  373. return
  374. fi
  375. fi
  376. if [ -d $USB_MOUNT/backup/gnupg ]; then
  377. for d in $USB_MOUNT/backup/gnupg/*/ ; do
  378. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  379. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  380. if [ ! -d /home/$USERNAME ]; then
  381. ${PROJECT_NAME}-adduser $USERNAME
  382. fi
  383. echo $"Restoring gnupg settings for $USERNAME"
  384. restore_directory_from_usb /root/tempgnupg gnupg/$USERNAME
  385. cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/
  386. if [ ! "$?" = "0" ]; then
  387. rm -rf /root/tempgnupg
  388. unmount_drive
  389. exit 276
  390. fi
  391. rm -rf /root/tempgnupg
  392. if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
  393. cp -r /home/$USERNAME/.gnupg /root
  394. if [ ! "$?" = "0" ]; then
  395. unmount_drive
  396. exit 283
  397. fi
  398. fi
  399. fi
  400. done
  401. fi
  402. }
  403. function restore_procmail {
  404. if [[ $RESTORE_APP != 'all' ]]; then
  405. if [[ $RESTORE_APP != 'procmail' ]]; then
  406. return
  407. fi
  408. fi
  409. if [ -d $USB_MOUNT/backup/procmail ]; then
  410. for d in $USB_MOUNT/backup/procmail/*/ ; do
  411. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  412. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  413. if [ ! -d /home/$USERNAME ]; then
  414. ${PROJECT_NAME}-adduser $USERNAME
  415. fi
  416. echo $"Restoring procmail settings for $USERNAME"
  417. restore_directory_from_usb /root/tempprocmail procmail/$USERNAME
  418. cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
  419. if [ ! "$?" = "0" ]; then
  420. rm -rf /root/tempprocmail
  421. unmount_drive
  422. exit 276
  423. fi
  424. rm -rf /root/tempprocmail
  425. fi
  426. done
  427. fi
  428. }
  429. function restore_spamassassin {
  430. if [[ $RESTORE_APP != 'all' ]]; then
  431. if [[ $RESTORE_APP != 'spamassassin' ]]; then
  432. return
  433. fi
  434. fi
  435. if [ -d $USB_MOUNT/backup/spamassassin ]; then
  436. for d in $USB_MOUNT/backup/spamassassin/*/ ; do
  437. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  438. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  439. if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then
  440. if [ ! -d /home/$USERNAME ]; then
  441. ${PROJECT_NAME}-adduser $USERNAME
  442. fi
  443. echo $"Restoring spamassassin settings for $USERNAME"
  444. restore_directory_from_usb /root/tempspamassassin spamassassin/$USERNAME
  445. cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/
  446. if [ ! "$?" = "0" ]; then
  447. rm -rf /root/tempspamassassin
  448. unmount_drive
  449. exit 276
  450. fi
  451. rm -rf /root/tempspamassassin
  452. fi
  453. fi
  454. done
  455. fi
  456. }
  457. function restore_admin_readme {
  458. if [[ $RESTORE_APP != 'all' ]]; then
  459. if [[ $RESTORE_APP != 'readme' ]]; then
  460. return
  461. fi
  462. fi
  463. if [ -d $USB_MOUNT/backup/readme ]; then
  464. echo $"Restoring admin user README"
  465. # Make a backup of the original README file
  466. # incase old passwords need to be used
  467. if [ -f /home/$ADMIN_USERNAME/README ]; then
  468. if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then
  469. cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original
  470. fi
  471. fi
  472. restore_directory_from_usb /root/tempreadme readme
  473. cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
  474. if [ ! "$?" = "0" ]; then
  475. rm -rf /root/tempreadme
  476. unmount_drive
  477. exit 276
  478. fi
  479. rm -rf /root/tempreadme
  480. fi
  481. }
  482. function restore_ipfs {
  483. if [[ $RESTORE_APP != 'all' ]]; then
  484. if [[ $RESTORE_APP != 'ipfs' ]]; then
  485. return
  486. fi
  487. fi
  488. if [ -d $USB_MOUNT/backup/ipfs ]; then
  489. echo $"Restoring IPFS"
  490. restore_directory_from_usb /root/tempipfs ipfs
  491. cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
  492. if [ ! "$?" = "0" ]; then
  493. rm -rf /root/tempipfs
  494. unmount_drive
  495. exit 276
  496. fi
  497. rm -rf /root/tempipfs
  498. fi
  499. }
  500. function restore_user_ssh_keys {
  501. if [[ $RESTORE_APP != 'all' ]]; then
  502. if [[ $RESTORE_APP != 'ssh' ]]; then
  503. return
  504. fi
  505. fi
  506. if [ -d $USB_MOUNT/backup/ssh ]; then
  507. for d in $USB_MOUNT/backup/ssh/*/ ; do
  508. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  509. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  510. if [ ! -d /home/$USERNAME ]; then
  511. ${PROJECT_NAME}-adduser $USERNAME
  512. fi
  513. echo $"Restoring ssh keys for $USERNAME"
  514. restore_directory_from_usb /root/tempssh ssh/$USERNAME
  515. cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/
  516. if [ ! "$?" = "0" ]; then
  517. rm -rf /root/tempssh
  518. unmount_drive
  519. exit 664
  520. fi
  521. rm -rf /root/tempssh
  522. fi
  523. done
  524. fi
  525. }
  526. function restore_user_config {
  527. if [[ $RESTORE_APP != 'all' ]]; then
  528. if [[ $RESTORE_APP != 'userconfig' ]]; then
  529. return
  530. fi
  531. fi
  532. if [ -d $USB_MOUNT/backup/config ]; then
  533. for d in $USB_MOUNT/backup/config/*/ ; do
  534. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  535. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  536. if [ ! -d /home/$USERNAME ]; then
  537. ${PROJECT_NAME}-adduser $USERNAME
  538. fi
  539. echo $"Restoring config files for $USERNAME"
  540. restore_directory_from_usb /root/tempconfig config/$USERNAME
  541. cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/
  542. if [ ! "$?" = "0" ]; then
  543. rm -rf /root/tempconfig
  544. unmount_drive
  545. exit 664
  546. fi
  547. rm -rf /root/tempconfig
  548. fi
  549. done
  550. fi
  551. }
  552. function restore_user_local {
  553. if [[ $RESTORE_APP != 'all' ]]; then
  554. if [[ $RESTORE_APP != 'userlocal' ]]; then
  555. return
  556. fi
  557. fi
  558. if [ -d $USB_MOUNT/backup/local ]; then
  559. for d in $USB_MOUNT/backup/local/*/ ; do
  560. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  561. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  562. if [ ! -d /home/$USERNAME ]; then
  563. ${PROJECT_NAME}-adduser $USERNAME
  564. fi
  565. echo $"Restoring local files for $USERNAME"
  566. restore_directory_from_usb /root/templocal local/$USERNAME
  567. cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/
  568. if [ ! "$?" = "0" ]; then
  569. rm -rf /root/templocal
  570. unmount_drive
  571. exit 664
  572. fi
  573. rm -rf /root/templocal
  574. fi
  575. done
  576. fi
  577. }
  578. function restore_certs {
  579. if [[ $RESTORE_APP != 'all' ]]; then
  580. if [[ $RESTORE_APP != 'certs' ]]; then
  581. return
  582. fi
  583. fi
  584. if [ -d $USB_MOUNT/backup/ssl ]; then
  585. echo $"Restoring certificates"
  586. mkdir /root/tempssl
  587. restore_directory_from_usb /root/tempssl ssl
  588. cp -r /root/tempssl/etc/ssl/* /etc/ssl
  589. if [ ! "$?" = "0" ]; then
  590. unmount_drive
  591. exit 276
  592. fi
  593. rm -rf /root/tempssl
  594. # restore ownership
  595. if [ -f /etc/ssl/private/xmpp.key ]; then
  596. chown prosody:prosody /etc/ssl/private/xmpp.key
  597. chown prosody:prosody /etc/ssl/certs/xmpp.*
  598. fi
  599. if [ -d /etc/dovecot ]; then
  600. chown root:dovecot /etc/ssl/private/dovecot.*
  601. chown root:dovecot /etc/ssl/certs/dovecot.*
  602. fi
  603. if [ -f /etc/ssl/private/exim.key ]; then
  604. cp /etc/ssl/private/exim.key /etc/exim4
  605. cp /etc/ssl/certs/exim.crt /etc/exim4
  606. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  607. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  608. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  609. fi
  610. if [ -f /etc/ssl/private/mumble.key ]; then
  611. if [ -d /var/lib/mumble-server ]; then
  612. cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
  613. cp /etc/ssl/private/mumble.key /var/lib/mumble-server
  614. chown -R mumble-server:mumble-server /var/lib/mumble-server
  615. fi
  616. fi
  617. fi
  618. }
  619. function restore_personal_settings {
  620. if [[ $RESTORE_APP != 'all' ]]; then
  621. if [[ $RESTORE_APP != 'personal' ]]; then
  622. return
  623. fi
  624. fi
  625. if [ -d $USB_MOUNT/backup/personal ]; then
  626. for d in $USB_MOUNT/backup/personal/*/ ; do
  627. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  628. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  629. if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then
  630. if [ ! -d /home/$USERNAME ]; then
  631. ${PROJECT_NAME}-adduser $USERNAME
  632. fi
  633. echo $"Restoring personal settings for $USERNAME"
  634. restore_directory_from_usb /root/temppersonal personal/$USERNAME
  635. if [ -d /home/$USERNAME/personal ]; then
  636. rm -rf /home/$USERNAME/personal
  637. fi
  638. mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME
  639. if [ ! "$?" = "0" ]; then
  640. unmount_drive
  641. exit 184
  642. fi
  643. rm -rf /root/temppersonal
  644. fi
  645. fi
  646. done
  647. fi
  648. }
  649. function restore_mailing_list {
  650. if [[ $RESTORE_APP != 'all' ]]; then
  651. if [[ $RESTORE_APP != 'mailinglist' ]]; then
  652. return
  653. fi
  654. fi
  655. if [ -d /var/spool/mlmmj ]; then
  656. echo $"Restoring public mailing list"
  657. restore_directory_from_usb /root/tempmailinglist mailinglist
  658. cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj
  659. if [ ! "$?" = "0" ]; then
  660. unmount_drive
  661. exit 526
  662. fi
  663. rm -rf /root/tempmailinglist
  664. fi
  665. }
  666. function restore_xmpp {
  667. if [[ $RESTORE_APP != 'all' ]]; then
  668. if [[ $RESTORE_APP != 'xmpp' ]]; then
  669. return
  670. fi
  671. fi
  672. if [ -d /var/lib/prosody ]; then
  673. echo $"Restoring XMPP settings"
  674. restore_directory_from_usb /root/tempxmpp xmpp
  675. cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody
  676. if [ ! "$?" = "0" ]; then
  677. unmount_drive
  678. exit 725
  679. fi
  680. rm -rf /root/tempxmpp
  681. service prosody restart
  682. chown -R prosody:prosody /var/lib/prosody/*
  683. fi
  684. }
  685. function restore_gnu_social {
  686. if [[ $RESTORE_APP != 'all' ]]; then
  687. if [[ $RESTORE_APP != 'gnusocial' ]]; then
  688. return
  689. fi
  690. fi
  691. if [ $MICROBLOG_DOMAIN_NAME ]; then
  692. restore_database gnusocial ${MICROBLOG_DOMAIN_NAME}
  693. if [ -d /root/tempgnusocial ]; then
  694. rm -rf /root/tempgnusocial
  695. fi
  696. fi
  697. }
  698. function restore_rss_reader {
  699. if [[ $RESTORE_APP != 'all' ]]; then
  700. if [[ $RESTORE_APP != 'ttrss' ]]; then
  701. return
  702. fi
  703. fi
  704. if [ $RSS_READER_DOMAIN_NAME ]; then
  705. restore_database ttrss ${RSS_READER_DOMAIN_NAME}
  706. if [ -d $USB_MOUNT/backup/ttrss ]; then
  707. chown -R www-data:www-data /etc/share/tt-rss
  708. if [ -d /root/tempttrss ]; then
  709. rm -rf /root/tempttrss
  710. fi
  711. fi
  712. fi
  713. }
  714. function restore_hubzilla {
  715. if [[ $RESTORE_APP != 'all' ]]; then
  716. if [[ $RESTORE_APP != 'hubzilla' ]]; then
  717. return
  718. fi
  719. fi
  720. if [ $HUBZILLA_DOMAIN_NAME ]; then
  721. restore_database hubzilla ${HUBZILLA_DOMAIN_NAME}
  722. if [ -d $USB_MOUNT/backup/hubzilla ]; then
  723. if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
  724. mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
  725. fi
  726. chmod 777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
  727. chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
  728. if [ -d /root/temphubzilla ]; then
  729. rm -rf /root/temphubzilla
  730. fi
  731. fi
  732. fi
  733. }
  734. function restore_owncloud {
  735. if [[ $RESTORE_APP != 'all' ]]; then
  736. if [[ $RESTORE_APP != 'owncloud' ]]; then
  737. return
  738. fi
  739. fi
  740. if [ $OWNCLOUD_DOMAIN_NAME ]; then
  741. restore_database owncloud $OWNCLOUD_DOMAIN_NAME
  742. if [ -d $USB_MOUNT/backup/owncloud2 ]; then
  743. restore_directory_from_usb /root/tempowncloud2 owncloud2
  744. cp -r /root/tempowncloud2/etc/owncloud/* /etc/owncloud/
  745. if [ ! "$?" = "0" ]; then
  746. unmount_drive
  747. exit 982
  748. fi
  749. rm -rf /root/tempowncloud
  750. rm -rf /root/tempowncloud2
  751. chown -R www-data:www-data /var/lib/owncloud/data
  752. chown -R www-data:www-data /var/lib/owncloud/backup
  753. chown -R www-data:www-data /var/lib/owncloud/assets
  754. for d in /home/*/ ; do
  755. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  756. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  757. occ files:scan $USERNAME
  758. fi
  759. done
  760. ln -s /usr/share/owncloud /var/www/${OWNCLOUD_DOMAIN_NAME}/htdocs
  761. fi
  762. fi
  763. }
  764. function restore_gogs {
  765. if [[ $RESTORE_APP != 'all' ]]; then
  766. if [[ $RESTORE_APP != 'gogs' ]]; then
  767. return
  768. fi
  769. fi
  770. if [ $GIT_DOMAIN_NAME ]; then
  771. restore_database gogs ${GIT_DOMAIN_NAME}
  772. if [ -d $USB_MOUNT/backup/gogs ]; then
  773. echo $"Restoring Gogs settings"
  774. if [ ! -d /home/git/go/src/github.com/gogits/gogs/custom ]; then
  775. mkdir -p /home/git/go/src/github.com/gogits/gogs/custom
  776. fi
  777. cp -r /root/tempgogs/home/git/go/src/github.com/gogits/gogs/custom/* /home/git/go/src/github.com/gogits/gogs/custom
  778. if [ ! "$?" = "0" ]; then
  779. unmount_drive
  780. exit 981
  781. fi
  782. echo $"Restoring Gogs repos"
  783. restore_directory_from_usb /root/tempgogsrepos gogsrepos
  784. cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
  785. if [ ! "$?" = "0" ]; then
  786. unmount_drive
  787. exit 67574
  788. fi
  789. echo $"Restoring Gogs authorized_keys"
  790. restore_directory_from_usb /root/tempgogsssh gogsssh
  791. if [ ! -d /home/git/.ssh ]; then
  792. mkdir /home/git/.ssh
  793. fi
  794. cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
  795. if [ ! "$?" = "0" ]; then
  796. unmount_drive
  797. exit 8463
  798. fi
  799. rm -rf /root/tempgogs
  800. rm -rf /root/tempgogsrepos
  801. rm -rf /root/tempgogsssh
  802. chown -R git:git /home/git
  803. fi
  804. fi
  805. }
  806. function restore_wiki {
  807. if [[ $RESTORE_APP != 'all' ]]; then
  808. if [[ $RESTORE_APP != 'wiki' ]]; then
  809. return
  810. fi
  811. fi
  812. if [ $WIKI_DOMAIN_NAME ]; then
  813. echo $"Restoring Wiki installation ${WIKI_DOMAIN_NAME}"
  814. restore_directory_from_usb /root/tempwiki wiki
  815. cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
  816. if [ ! "$?" = "0" ]; then
  817. unmount_drive
  818. exit 868
  819. fi
  820. restore_directory_from_usb /root/tempwiki2 wiki2
  821. cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
  822. if [ ! "$?" = "0" ]; then
  823. unmount_drive
  824. exit 869
  825. fi
  826. rm -rf /root/tempwiki
  827. rm -rf /root/tempwiki2
  828. chown -R www-data:www-data /var/lib/dokuwiki/*
  829. # Ensure that the bundled SSL cert is being used
  830. if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
  831. sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
  832. fi
  833. if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
  834. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
  835. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
  836. fi
  837. fi
  838. }
  839. function restore_blog {
  840. if [[ $RESTORE_APP != 'all' ]]; then
  841. if [[ $RESTORE_APP != 'blog' ]]; then
  842. return
  843. fi
  844. fi
  845. if [ $FULLBLOG_DOMAIN_NAME ]; then
  846. echo $"Restoring blog installation"
  847. restore_directory_from_usb /root/tempblog blog
  848. rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
  849. cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
  850. if [ ! "$?" = "0" ]; then
  851. unmount_drive
  852. exit 593
  853. fi
  854. rm -rf /root/tempblog
  855. if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
  856. echo $"No content directory found after restoring blog"
  857. unmount_drive
  858. exit 287
  859. fi
  860. chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
  861. # Ensure that the bundled SSL cert is being used
  862. if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
  863. sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
  864. fi
  865. for d in /home/*/ ; do
  866. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  867. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  868. if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
  869. mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
  870. fi
  871. fi
  872. done
  873. if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
  874. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
  875. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
  876. fi
  877. fi
  878. }
  879. function restore_cjdns {
  880. if [[ $RESTORE_APP != 'all' ]]; then
  881. if [[ $RESTORE_APP != 'cjdns' ]]; then
  882. return
  883. fi
  884. fi
  885. if [ -d $USB_MOUNT/backup/cjdns ]; then
  886. echo $"Restoring cjdns installation"
  887. restore_directory_from_usb /root/tempcjdns cjdns
  888. rm -rf /etc/cjdns
  889. cp -r /root/tempcjdns/etc/cjdns /etc/
  890. if [ ! "$?" = "0" ]; then
  891. unmount_drive
  892. exit 8472
  893. fi
  894. rm -rf /root/tempcjdns
  895. fi
  896. }
  897. function restore_email {
  898. if [[ $RESTORE_APP != 'all' ]]; then
  899. if [[ $RESTORE_APP != 'email' ]]; then
  900. return
  901. fi
  902. fi
  903. if [ -d $USB_MOUNT/backup/mail ]; then
  904. for d in $USB_MOUNT/backup/mail/*/ ; do
  905. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  906. if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then
  907. if [ ! -d /home/$USERNAME ]; then
  908. ${PROJECT_NAME}-adduser $USERNAME
  909. fi
  910. echo $"Restoring emails for $USERNAME"
  911. restore_directory_from_usb /root/tempmail mail/$USERNAME
  912. if [ ! -d /home/$USERNAME/Maildir ]; then
  913. mkdir /home/$USERNAME/Maildir
  914. fi
  915. tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
  916. if [ ! "$?" = "0" ]; then
  917. unmount_drive
  918. exit 927
  919. fi
  920. rm -rf /root/tempmail
  921. fi
  922. done
  923. fi
  924. }
  925. function restore_dlna {
  926. if [[ $RESTORE_APP != 'all' ]]; then
  927. if [[ $RESTORE_APP != 'dlna' ]]; then
  928. return
  929. fi
  930. fi
  931. if [ -d /var/cache/minidlna ]; then
  932. if [ -d $USB_MOUNT/backup/dlna ]; then
  933. echo $"Restoring DLNA cache"
  934. restore_directory_from_usb /root/tempdlna dlna
  935. cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/
  936. if [ ! "$?" = "0" ]; then
  937. rm -rf /root/tempdlna
  938. unmount_drive
  939. exit 982
  940. fi
  941. rm -rf /root/tempdlna
  942. fi
  943. fi
  944. }
  945. function restore_voip {
  946. if [[ $RESTORE_APP != 'all' ]]; then
  947. if [[ $RESTORE_APP != 'voip' ]]; then
  948. return
  949. fi
  950. fi
  951. if [ -d $USB_MOUNT/backup/voip ]; then
  952. echo $"Restoring VoIP settings"
  953. restore_directory_from_usb /root/tempvoip voip
  954. cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
  955. if [ ! "$?" = "0" ]; then
  956. rm -rf /root/tempvoip
  957. unmount_drive
  958. exit 3679
  959. fi
  960. cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
  961. if [ ! "$?" = "0" ]; then
  962. rm -rf /root/tempvoip
  963. unmount_drive
  964. exit 3679
  965. fi
  966. cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
  967. if [ ! "$?" = "0" ]; then
  968. rm -rf /root/tempvoip
  969. unmount_drive
  970. exit 276
  971. fi
  972. rm -rf /root/tempvoip
  973. cp /etc/ssl/certs/mumble* /var/lib/mumble-server
  974. cp /etc/ssl/private/mumble* /var/lib/mumble-server
  975. chown -R mumble-server:mumble-server /var/lib/mumble-server
  976. service sipwitch restart
  977. service mumble-server restart
  978. fi
  979. }
  980. function restore_tox {
  981. if [[ $RESTORE_APP != 'all' ]]; then
  982. if [[ $RESTORE_APP != 'tox' ]]; then
  983. return
  984. fi
  985. fi
  986. if [ -d $USB_MOUNT/backup/tox ]; then
  987. echo $"Restoring Tox node settings"
  988. restore_directory_from_usb / tox
  989. if [ ! "$?" = "0" ]; then
  990. unmount_drive
  991. exit 6393
  992. fi
  993. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  994. systemctl restart tox-bootstrapd.service
  995. if [ ! "$?" = "0" ]; then
  996. systemctl status tox-bootstrapd.service
  997. unmount_drive
  998. exit 59369
  999. fi
  1000. fi
  1001. }
  1002. function get_restore_app {
  1003. if [ ${1} ]; then
  1004. if [ ! -d /home/${1} ]; then
  1005. RESTORE_APP=${1}
  1006. echo $"Restore $RESTORE_APP"
  1007. fi
  1008. fi
  1009. }
  1010. get_restore_app ${2}
  1011. mount_drive ${1} ${2}
  1012. check_backup_exists
  1013. check_admin_user
  1014. copy_gpg_keys
  1015. restore_configuration
  1016. same_admin_user
  1017. update_domains
  1018. restore_mariadb
  1019. restore_letsencrypt
  1020. restore_tor
  1021. restore_mutt_settings
  1022. restore_gpg
  1023. restore_procmail
  1024. restore_spamassassin
  1025. restore_admin_readme
  1026. restore_ipfs
  1027. restore_user_ssh_keys
  1028. restore_user_config
  1029. restore_user_local
  1030. restore_certs
  1031. restore_personal_settings
  1032. restore_mailing_list
  1033. restore_xmpp
  1034. restore_gnu_social
  1035. restore_hubzilla
  1036. restore_rss_reader
  1037. restore_owncloud
  1038. restore_gogs
  1039. restore_wiki
  1040. restore_blog
  1041. restore_cjdns
  1042. restore_email
  1043. restore_dlna
  1044. restore_voip
  1045. restore_tox
  1046. unmount_drive
  1047. echo $"Restore from USB drive is complete. You can now unplug it."
  1048. exit 0