freedombone-restore-local 37KB

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