freedombone-restore-local 32KB

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