freedombone-restore-remote 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Restore from a given remote server
  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. CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
  32. BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
  33. export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
  34. export TEXTDOMAINDIR="/usr/share/locale"
  35. SERVER_NAME=$1
  36. # whether to restore everything or just a specific application
  37. RESTORE_APP='all'
  38. if [ ${2} ]; then
  39. RESTORE_APP=${2}
  40. fi
  41. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | -nawk -F ':' '{print $2}')
  42. ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
  43. # Temporary location for data to be backed up to other servers
  44. SERVER_DIRECTORY=/root/remoterestore
  45. BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list
  46. if [ ! $SERVER_NAME ]; then
  47. echo $'restorefromfriend [server]'
  48. exit 1
  49. fi
  50. if [ ! -f $BACKUP_LIST ]; then
  51. echo $"No friends list found at $BACKUP_LIST"
  52. exit 2
  53. fi
  54. if ! grep -q "$SERVER_NAME" $BACKUP_LIST; then
  55. echo $"Server not found within the friends list"
  56. exit 3
  57. fi
  58. REMOTE_SERVER=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $1}')
  59. REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $2}')
  60. REMOTE_DIRECTORY=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $3}')
  61. REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $4}')
  62. REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
  63. NOW=$(date +"%Y-%m-%d %H:%M:%S")
  64. echo "$NOW Starting restore from $REMOTE_SERVER" >> /var/log/remotebackups.log
  65. rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $REMOTE_SERVER/backup $SERVER_DIRECTORY
  66. if [ ! "$?" = "0" ]; then
  67. echo "$NOW Restore from $REMOTE_SERVER failed" >> /var/log/remotebackups.log
  68. # Send a warning email
  69. echo "Restore from $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} restore from friend" $ADMIN_EMAIL_ADDRESS
  70. exit 790
  71. else
  72. echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
  73. fi
  74. # get the version of Go being used
  75. GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
  76. # MariaDB password
  77. DATABASE_PASSWORD=$(cat /root/dbpass)
  78. function restore_directory_from_friend {
  79. if [ ! -d ${1} ]; then
  80. mkdir ${1}
  81. fi
  82. obnam restore -r $SERVER_DIRECTORY/backup/${2} --to ${1}
  83. }
  84. function copy_gpg_keys {
  85. echo $"Copying GPG keys from admin user to root"
  86. cp -r /home/$ADMIN_USERNAME/.gnupg /root
  87. }
  88. function restore_database_from_friend {
  89. DATABASE_PASSWORD=
  90. RESTORE_SUBDIR="root"
  91. if [ -d $SERVER_DIRECTORY/backup/${1} ]; then
  92. echo $"Restoring ${1} database"
  93. restore_directory_from_friend /root/temp${1}data ${1}data
  94. if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
  95. echo $"Unable to restore ${1} database"
  96. rm -rf /root/temp${1}data
  97. exit 503
  98. fi
  99. mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
  100. if [ ! "$?" = "0" ]; then
  101. echo "$mysqlsuccess"
  102. exit 964
  103. fi
  104. shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
  105. rm -rf /root/temp${1}data
  106. echo $"Restoring ${1} installation"
  107. restore_directory_from_friend /root/temp${1} ${1}
  108. RESTORE_SUBDIR="var"
  109. if [ ${1} ]; then
  110. # special handling of ttrss
  111. if [[ ${2} == "ttrss" ]]; then
  112. if [ -d /etc/share/tt-rss ]; then
  113. rm -rf /etc/share/tt-rss
  114. mv /root/temp${1}/etc/share/tt-rss /etc/share/
  115. if [ ! "$?" = "0" ]; then
  116. exit 639
  117. fi
  118. if [ -d /etc/letsencrypt/live/${2} ]; then
  119. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  120. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  121. else
  122. # Ensure that the bundled SSL cert is being used
  123. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  124. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  125. fi
  126. fi
  127. fi
  128. fi
  129. if [ -d /var/www/${2}/htdocs ]; then
  130. if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
  131. rm -rf /var/www/${2}/htdocs
  132. mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
  133. if [ ! "$?" = "0" ]; then
  134. exit 683
  135. fi
  136. if [ -d /etc/letsencrypt/live/${2} ]; then
  137. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  138. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  139. else
  140. # Ensure that the bundled SSL cert is being used
  141. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  142. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  143. fi
  144. fi
  145. fi
  146. fi
  147. fi
  148. fi
  149. }
  150. function restore_configuration {
  151. if [[ $RESTORE_APP != 'all' ]]; then
  152. if [[ $RESTORE_APP != 'configuration' ]]; then
  153. return
  154. fi
  155. fi
  156. if [ -d $SERVER_DIRECTORY/backup/config ]; then
  157. echo $"Restoring configuration files"
  158. temp_restore_dir=/root/tempconfig
  159. restore_directory_from_friend $temp_restore_dir config
  160. cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
  161. if [ ! "$?" = "0" ]; then
  162. unmount_drive
  163. rm -rf $temp_restore_dir
  164. exit 5372
  165. fi
  166. if [ -f $CONFIG_FILE ]; then
  167. # install according to the config file
  168. freedombone -c $CONFIG_FILE
  169. fi
  170. cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
  171. if [ ! "$?" = "0" ]; then
  172. unmount_drive
  173. rm -rf $temp_restore_dir
  174. exit 7252
  175. fi
  176. if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then
  177. cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
  178. if [ ! "$?" = "0" ]; then
  179. unmount_drive
  180. rm -rf $temp_restore_dir
  181. exit 62121
  182. fi
  183. fi
  184. # restore nginx password hashes
  185. if [ -f $temp_restore_dir/root/htpasswd ]; then
  186. cp -f $temp_restore_dir/root/htpasswd /etc/nginx/.htpasswd
  187. fi
  188. rm -rf $temp_restore_dir
  189. fi
  190. }
  191. function restore_mariadb {
  192. if [[ $RESTORE_APP != 'all' ]]; then
  193. if [[ $RESTORE_APP != 'mariadb' ]]; then
  194. return
  195. fi
  196. fi
  197. if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
  198. echo $"Restoring MariaDB settings"
  199. temp_restore_dir=/root/tempmariadb
  200. restore_directory_from_friend $temp_restore_dir mariadb
  201. echo $"Get the MariaDB password from the backup"
  202. if [ ! -f ${temp_restore_dir}${temp_restore_dir}/db ]; then
  203. echo $"MariaDB password file not found"
  204. exit 495
  205. fi
  206. BACKUP_MARIADB_PASSWORD=$(cat ${temp_restore_dir}${temp_restore_dir}/db)
  207. if [[ "$BACKUP_MARIADB_PASSWORD" != "$DATABASE_PASSWORD" ]]; then
  208. echo $"Restore the MariaDB user table"
  209. mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
  210. if [ ! "$?" = "0" ]; then
  211. echo $"Try again using the password obtained from backup"
  212. mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
  213. fi
  214. if [ ! "$?" = "0" ]; then
  215. echo "$mysqlsuccess"
  216. exit 962
  217. fi
  218. echo $"Restarting database"
  219. service mysql restart
  220. echo $"Change the MariaDB password to the backup version"
  221. DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD
  222. fi
  223. shred -zu ${temp_restore_dir}${temp_restore_dir}/db
  224. rm -rf ${temp_restore_dir}
  225. # Change database password file
  226. echo "$DATABASE_PASSWORD" > /root/dbpass
  227. chmod 600 /root/dbpass
  228. fi
  229. }
  230. function restore_letsencrypt {
  231. if [[ $RESTORE_APP != 'all' ]]; then
  232. if [[ $RESTORE_APP != 'letsencrypt' ]]; then
  233. return
  234. fi
  235. fi
  236. if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then
  237. echo $"Restoring Lets Encrypt settings"
  238. restore_directory_from_friend / letsencrypt
  239. fi
  240. }
  241. function restore_tor {
  242. if [[ $RESTORE_APP != 'all' ]]; then
  243. if [[ $RESTORE_APP != 'tor' ]]; then
  244. return
  245. fi
  246. fi
  247. if [ -d $SERVER_DIRECTORY/backup/tor ]; then
  248. echo $"Restoring Tor settings"
  249. restore_directory_from_friend / tor
  250. fi
  251. }
  252. function restore_mutt_settings {
  253. if [[ $RESTORE_APP != 'all' ]]; then
  254. if [[ $RESTORE_APP != 'mutt' ]]; then
  255. return
  256. fi
  257. fi
  258. for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
  259. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  260. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  261. if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
  262. if [ ! -d /home/$USERNAME ]; then
  263. ${PROJECT_NAME}-adduser $USERNAME
  264. fi
  265. echo $"Restoring Mutt settings for $USERNAME"
  266. temp_restore_dir=/root/tempmutt
  267. restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME
  268. if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc ]; then
  269. cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
  270. fi
  271. if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc ]; then
  272. cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
  273. fi
  274. if [ ! "$?" = "0" ]; then
  275. rm -rf ${temp_restore_dir}
  276. exit 276
  277. fi
  278. rm -rf ${temp_restore_dir}
  279. fi
  280. fi
  281. done
  282. }
  283. function restore_gpg {
  284. if [[ $RESTORE_APP != 'all' ]]; then
  285. if [[ $RESTORE_APP != 'gpg' ]]; then
  286. return
  287. fi
  288. fi
  289. for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
  290. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  291. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  292. if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then
  293. if [ ! -d /home/$USERNAME ]; then
  294. ${PROJECT_NAME}-adduser $USERNAME
  295. fi
  296. echo $"Restoring gnupg settings for $USERNAME"
  297. temp_restore_dir=/root/tempgnupg
  298. restore_directory_from_friend ${temp_restore_dir} gnupg/$USERNAME
  299. cp -r ${temp_restore_dir}/home/$USERNAME/.gnupg /home/$USERNAME/
  300. if [ ! "$?" = "0" ]; then
  301. rm -rf ${temp_restore_dir}
  302. exit 276
  303. fi
  304. rm -rf ${temp_restore_dir}
  305. if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
  306. cp -r /home/$USERNAME/.gnupg /root
  307. if [ ! "$?" = "0" ]; then
  308. exit 283
  309. fi
  310. fi
  311. fi
  312. fi
  313. done
  314. }
  315. function restore_procmail {
  316. if [[ $RESTORE_APP != 'all' ]]; then
  317. if [[ $RESTORE_APP != 'procmail' ]]; then
  318. return
  319. fi
  320. fi
  321. for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
  322. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  323. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  324. if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then
  325. if [ ! -d /home/$USERNAME ]; then
  326. ${PROJECT_NAME}-adduser $USERNAME
  327. fi
  328. echo $"Restoring procmail settings for $USERNAME"
  329. temp_restore_dir=/root/tempprocmail
  330. restore_directory_from_friend ${temp_restore_dir} procmail/$USERNAME
  331. cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
  332. if [ ! "$?" = "0" ]; then
  333. rm -rf ${temp_restore_dir}
  334. exit 276
  335. fi
  336. rm -rf ${temp_restore_dir}
  337. fi
  338. fi
  339. done
  340. }
  341. function restore_spamassassin {
  342. if [[ $RESTORE_APP != 'all' ]]; then
  343. if [[ $RESTORE_APP != 'spamassassin' ]]; then
  344. return
  345. fi
  346. fi
  347. for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
  348. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  349. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  350. if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then
  351. if [ ! -d /home/$USERNAME ]; then
  352. ${PROJECT_NAME}-adduser $USERNAME
  353. fi
  354. echo $"Restoring spamassassin settings for $USERNAME"
  355. temp_restore_dir=/root/tempspamassassin
  356. restore_directory_from_friend $temp_restore_dir spamassassin/$USERNAME
  357. cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/
  358. if [ ! "$?" = "0" ]; then
  359. rm -rf $temp_restore_dir
  360. exit 276
  361. fi
  362. rm -rf $temp_restore_dir
  363. fi
  364. fi
  365. done
  366. }
  367. function restore_admin_readme {
  368. if [[ $RESTORE_APP != 'all' ]]; then
  369. if [[ $RESTORE_APP != 'readme' ]]; then
  370. return
  371. fi
  372. fi
  373. if [ -d $SERVER_DIRECTORY/backup/readme ]; then
  374. echo $"Restoring README"
  375. temp_restore_dir=/root/tempreadme
  376. restore_directory_from_friend $temp_restore_dir readme
  377. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
  378. if [ ! "$?" = "0" ]; then
  379. rm -rf $temp_restore_dir
  380. exit 276
  381. fi
  382. rm -rf $temp_restore_dir
  383. fi
  384. }
  385. function restore_ssh_keys {
  386. if [[ $RESTORE_APP != 'all' ]]; then
  387. if [[ $RESTORE_APP != 'ssh' ]]; then
  388. return
  389. fi
  390. fi
  391. for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
  392. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  393. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  394. if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then
  395. if [ ! -d /home/$USERNAME ]; then
  396. ${PROJECT_NAME}-adduser $USERNAME
  397. fi
  398. echo $"Restoring ssh keys for $USERNAME"
  399. temp_restore_dir=/root/tempssh
  400. restore_directory_from_friend $temp_restore_dir ssh/$USERNAME
  401. cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/
  402. if [ ! "$?" = "0" ]; then
  403. rm -rf $temp_restore_dir
  404. exit 664
  405. fi
  406. rm -rf $temp_restore_dir
  407. fi
  408. fi
  409. done
  410. }
  411. function restore_user_config {
  412. if [[ $RESTORE_APP != 'all' ]]; then
  413. if [[ $RESTORE_APP != 'userconfig' ]]; then
  414. return
  415. fi
  416. fi
  417. for d in $SERVER_DIRECTORY/backup/config/*/ ; do
  418. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  419. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  420. if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then
  421. if [ ! -d /home/$USERNAME ]; then
  422. ${PROJECT_NAME}-adduser $USERNAME
  423. fi
  424. echo $"Restoring config files for $USERNAME"
  425. temp_restore_dir=/root/tempconfig
  426. restore_directory_from_friend $temp_restore_dir config/$USERNAME
  427. cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/
  428. if [ ! "$?" = "0" ]; then
  429. rm -rf $temp_restore_dir
  430. exit 664
  431. fi
  432. rm -rf $temp_restore_dir
  433. fi
  434. fi
  435. done
  436. }
  437. function gpg_pubkey_from_email {
  438. key_owner_username=$1
  439. key_email_address=$2
  440. key_id=
  441. if [[ $key_owner_username != "root" ]]; then
  442. key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  443. else
  444. key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  445. fi
  446. echo $key_id
  447. }
  448. function restore_user_monkeysphere {
  449. if [[ $RESTORE_APP != 'all' ]]; then
  450. if [[ $RESTORE_APP != 'usermonkeysphere' ]]; then
  451. return
  452. fi
  453. fi
  454. for d in $SERVER_DIRECTORY/backup/monkeysphere/*/ ; do
  455. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  456. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  457. if [ -d $SERVER_DIRECTORY/backup/monkeysphere/$USERNAME ]; then
  458. if [ ! -d /home/$USERNAME ]; then
  459. ${PROJECT_NAME}-adduser $USERNAME
  460. fi
  461. echo $"Restoring monkeysphere ids for $USERNAME"
  462. temp_restore_dir=/root/tempmonkeysphere
  463. restore_directory_from_friend $temp_restore_dir monkeysphere/$USERNAME
  464. cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/
  465. if [ ! "$?" = "0" ]; then
  466. rm -rf $temp_restore_dir
  467. exit 664
  468. fi
  469. rm -rf $temp_restore_dir
  470. fi
  471. fi
  472. # The admin user is the identity certifier
  473. MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
  474. if grep -q "MY_EMAIL_ADDRESS" $CONFIG_FILE; then
  475. MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIG_FILE | awk -F '=' '{print $2}')
  476. fi
  477. MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
  478. fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  479. monkeysphere-authentication add-identity-certifier $fpr
  480. monkeysphere-authentication update-users
  481. done
  482. }
  483. function restore_user_fin {
  484. if [[ $RESTORE_APP != 'all' ]]; then
  485. if [[ $RESTORE_APP != 'userfin' ]]; then
  486. return
  487. fi
  488. fi
  489. for d in $SERVER_DIRECTORY/backup/fin/*/ ; do
  490. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  491. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  492. if [ -d $SERVER_DIRECTORY/backup/fin/$USERNAME ]; then
  493. if [ ! -d /home/$USERNAME ]; then
  494. ${PROJECT_NAME}-adduser $USERNAME
  495. fi
  496. echo $"Restoring fin files for $USERNAME"
  497. temp_restore_dir=/root/tempfin
  498. restore_directory_from_friend $temp_restore_dir fin/$USERNAME
  499. cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/
  500. if [ ! "$?" = "0" ]; then
  501. rm -rf $temp_restore_dir
  502. exit 664
  503. fi
  504. rm -rf $temp_restore_dir
  505. fi
  506. fi
  507. done
  508. }
  509. function restore_user_local {
  510. if [[ $RESTORE_APP != 'all' ]]; then
  511. if [[ $RESTORE_APP != 'userlocal' ]]; then
  512. return
  513. fi
  514. fi
  515. for d in $SERVER_DIRECTORY/backup/local/*/ ; do
  516. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  517. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  518. if [ -d $SERVER_DIRECTORY/backup/local/$USERNAME ]; then
  519. if [ ! -d /home/$USERNAME ]; then
  520. ${PROJECT_NAME}-adduser $USERNAME
  521. fi
  522. echo $"Restoring local files for $USERNAME"
  523. temp_restore_dir=/root/templocal
  524. restore_directory_from_friend $temp_restore_dir local/$USERNAME
  525. cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/
  526. if [ ! "$?" = "0" ]; then
  527. rm -rf $temp_restore_dir
  528. exit 664
  529. fi
  530. rm -rf $temp_restore_dir
  531. fi
  532. fi
  533. done
  534. }
  535. function restore_certs {
  536. if [[ $RESTORE_APP != 'all' ]]; then
  537. if [[ $RESTORE_APP != 'certs' ]]; then
  538. return
  539. fi
  540. fi
  541. if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
  542. echo $"Restoring certificates"
  543. restore_directory_from_friend /root/tempssl ssl
  544. cp -r /root/tempssl/etc/ssl/* /etc/ssl
  545. if [ ! "$?" = "0" ]; then
  546. exit 276
  547. fi
  548. rm -rf /root/tempssl
  549. # restore ownership
  550. if [ -f /etc/ssl/private/xmpp.key ]; then
  551. chown prosody:prosody /etc/ssl/private/xmpp.key
  552. chown prosody:prosody /etc/ssl/certs/xmpp.*
  553. fi
  554. if [ -d /etc/dovecot ]; then
  555. chown root:dovecot /etc/ssl/private/dovecot.*
  556. chown root:dovecot /etc/ssl/certs/dovecot.*
  557. fi
  558. if [ -f /etc/ssl/private/exim.key ]; then
  559. cp /etc/ssl/private/exim.key /etc/exim4
  560. cp /etc/ssl/certs/exim.crt /etc/exim4
  561. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  562. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  563. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  564. fi
  565. if [ -f /etc/ssl/private/mumble.key ]; then
  566. if [ -d /var/lib/mumble-server ]; then
  567. cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
  568. cp /etc/ssl/private/mumble.key /var/lib/mumble-server
  569. chown -R mumble-server:mumble-server /var/lib/mumble-server
  570. fi
  571. fi
  572. fi
  573. }
  574. function restore_personal_settings {
  575. if [[ $RESTORE_APP != 'all' ]]; then
  576. if [[ $RESTORE_APP != 'personal' ]]; then
  577. return
  578. fi
  579. fi
  580. for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
  581. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  582. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  583. if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then
  584. if [ ! -d /home/$USERNAME ]; then
  585. ${PROJECT_NAME}-adduser $USERNAME
  586. fi
  587. echo $"Restoring personal settings for $USERNAME"
  588. temp_restore_dir=/root/temppersonal
  589. restore_directory_from_friend $temp_restore_dir personal/$USERNAME
  590. if [ -d /home/$USERNAME/personal ]; then
  591. rm -rf /home/$USERNAME/personal
  592. fi
  593. mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
  594. if [ ! "$?" = "0" ]; then
  595. exit 184
  596. fi
  597. rm -rf $temp_restore_dir
  598. fi
  599. fi
  600. done
  601. }
  602. function restore_mailing_list {
  603. if [[ $RESTORE_APP != 'all' ]]; then
  604. if [[ $RESTORE_APP != 'mailinglist' ]]; then
  605. return
  606. fi
  607. fi
  608. if [ -d /var/spool/mlmmj ]; then
  609. echo $"Restoring public mailing list"
  610. temp_restore_dir=/root/tempmailinglist
  611. restore_directory_from_friend $temp_restore_dir mailinglist
  612. cp -r $temp_restore_dir/root/spool/mlmmj/* /var/spool/mlmmj
  613. if [ ! "$?" = "0" ]; then
  614. exit 526
  615. fi
  616. rm -rf $temp_restore_dir
  617. fi
  618. }
  619. function restore_gnusocial {
  620. if [[ $RESTORE_APP != 'all' ]]; then
  621. if [[ $RESTORE_APP != 'gnusocial' ]]; then
  622. return
  623. fi
  624. fi
  625. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  626. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  627. # stop the daemons
  628. cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  629. scripts/stopdaemons.sh
  630. restore_database_from_friend gnusocial ${MICROBLOG_DOMAIN_NAME}
  631. if [ -d /root/tempgnusocial ]; then
  632. rm -rf /root/tempgnusocial
  633. fi
  634. # start the daemons
  635. cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  636. scripts/startdaemons.sh
  637. fi
  638. }
  639. function restore_rss {
  640. if [[ $RESTORE_APP != 'all' ]]; then
  641. if [[ $RESTORE_APP != 'ttrss' ]]; then
  642. return
  643. fi
  644. fi
  645. if grep -q "RSS reader domain" $COMPLETION_FILE; then
  646. RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
  647. restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME}
  648. if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
  649. chown -R www-data:www-data /etc/share/tt-rss
  650. fi
  651. if [ -d /root/tempttrss ]; then
  652. rm -rf /root/tempttrss
  653. fi
  654. fi
  655. }
  656. function restore_hubzilla {
  657. if [[ $RESTORE_APP != 'all' ]]; then
  658. if [[ $RESTORE_APP != 'hubzilla' ]]; then
  659. return
  660. fi
  661. fi
  662. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  663. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  664. restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
  665. if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
  666. if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
  667. mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
  668. fi
  669. chmod 777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
  670. chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
  671. fi
  672. if [ -d /root/temphubzilla ]; then
  673. rm -rf /root/temphubzilla
  674. fi
  675. fi
  676. }
  677. function restore_syncthing {
  678. if [[ $RESTORE_APP != 'all' ]]; then
  679. if [[ $RESTORE_APP != 'syncthing' ]]; then
  680. return
  681. fi
  682. fi
  683. if [ -f /etc/systemd/system/syncthing.service ]; then
  684. systemctl stop syncthing
  685. systemctl stop cron
  686. fi
  687. if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
  688. echo $"Restoring syncthing configuration"
  689. temp_restore_dir=/root/tempsyncthingconfig
  690. restore_directory_from_friend $temp_restore_dir syncthingconfig
  691. cp -r $temp_restore_dir/* /
  692. if [ ! "$?" = "0" ]; then
  693. unmount_drive
  694. systemctl start syncthing
  695. systemctl start cron
  696. exit 6833
  697. fi
  698. rm -rf $temp_restore_dir
  699. fi
  700. if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
  701. echo $"Restoring syncthing shared files"
  702. temp_restore_dir=/root/tempsyncthingshared
  703. restore_directory_from_friend $temp_restore_dir syncthingshared
  704. cp -r $temp_restore_dir/* /
  705. if [ ! "$?" = "0" ]; then
  706. unmount_drive
  707. systemctl start syncthing
  708. systemctl start cron
  709. exit 37904
  710. fi
  711. rm -rf $temp_restore_dir
  712. fi
  713. if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
  714. for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
  715. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  716. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  717. if [ ! -d /home/$USERNAME ]; then
  718. ${PROJECT_NAME}-adduser $USERNAME
  719. fi
  720. echo $"Restoring syncthing files for $USERNAME"
  721. temp_restore_dir=/root/tempsyncthing
  722. restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
  723. cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
  724. if [ ! "$?" = "0" ]; then
  725. rm -rf $temp_restore_dir
  726. unmount_drive
  727. systemctl start syncthing
  728. systemctl start cron
  729. exit 68438
  730. fi
  731. rm -rf $temp_restore_dir
  732. # restore device IDs from config settings
  733. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  734. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  735. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  736. fi
  737. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  738. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  739. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  740. fi
  741. fi
  742. done
  743. fi
  744. if [ -f /etc/systemd/system/syncthing.service ]; then
  745. systemctl start syncthing
  746. systemctl start cron
  747. fi
  748. }
  749. function restore_mediagoblin {
  750. if [[ $RESTORE_APP != 'all' ]]; then
  751. if [[ $RESTORE_APP != 'mediagoblin' ]]; then
  752. return
  753. fi
  754. fi
  755. if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
  756. MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
  757. if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
  758. echo $"Restoring Mediagoblin installation"
  759. temp_restore_dir=/root/tempmediagoblin
  760. restore_directory_from_friend $temp_restore_dir mediagoblin
  761. cp -r $temp_restore_dir/* /
  762. if [ ! "$?" = "0" ]; then
  763. exit 5626
  764. fi
  765. rm -rf $temp_restore_dir
  766. fi
  767. chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  768. fi
  769. }
  770. function restore_gogs {
  771. export GVM_ROOT=$GVM_HOME
  772. if [ -d $GVM_ROOT/bin ]; then
  773. cd $GVM_ROOT/bin
  774. [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
  775. gvm use go${GO_VERSION} --default
  776. systemctl set-environment GOPATH=$GOPATH
  777. fi
  778. if [[ $RESTORE_APP != 'all' ]]; then
  779. if [[ $RESTORE_APP != 'gogs' ]]; then
  780. return
  781. fi
  782. fi
  783. if grep -q "Gogs domain" $COMPLETION_FILE; then
  784. GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
  785. restore_database_from_friend gogs $GIT_DOMAIN_NAME
  786. if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
  787. if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
  788. mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
  789. fi
  790. cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom/
  791. if [ ! "$?" = "0" ]; then
  792. exit 5885
  793. fi
  794. echo $"Restoring Gogs repos"
  795. restore_directory_from_friend /root/tempgogsrepos gogsrepos
  796. cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
  797. if [ ! "$?" = "0" ]; then
  798. exit 7649
  799. fi
  800. echo $"Restoring Gogs authorized_keys"
  801. restore_directory_from_friend /root/tempgogsssh gogsssh
  802. if [ ! -d /home/git/.ssh ]; then
  803. mkdir /home/git/.ssh
  804. fi
  805. cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
  806. if [ ! "$?" = "0" ]; then
  807. exit 74239
  808. fi
  809. rm -rf /root/tempgogs
  810. rm -rf /root/tempgogsrepos
  811. rm -rf /root/tempgogsssh
  812. chown -R git:git /home/git
  813. fi
  814. fi
  815. }
  816. function restore_wiki {
  817. if [[ $RESTORE_APP != 'all' ]]; then
  818. if [[ $RESTORE_APP != 'wiki' ]]; then
  819. return
  820. fi
  821. fi
  822. if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
  823. WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
  824. echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
  825. restore_directory_from_friend /root/tempwiki wiki
  826. cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
  827. if [ ! "$?" = "0" ]; then
  828. exit 868
  829. fi
  830. restore_directory_from_friend /root/tempwiki2 wiki2
  831. cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
  832. if [ ! "$?" = "0" ]; then
  833. exit 869
  834. fi
  835. rm -rf /root/tempwiki
  836. rm -rf /root/tempwiki2
  837. chown -R www-data:www-data /var/lib/dokuwiki/*
  838. # Ensure that the bundled SSL cert is being used
  839. if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
  840. sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
  841. fi
  842. if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
  843. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
  844. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
  845. fi
  846. fi
  847. }
  848. function restore_blog {
  849. if [[ $RESTORE_APP != 'all' ]]; then
  850. if [[ $RESTORE_APP != 'blog' ]]; then
  851. return
  852. fi
  853. fi
  854. if [ -d $SERVER_DIRECTORY/backup/blog ]; then
  855. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  856. echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
  857. temp_restore_dir=/root/tempblog
  858. mkdir $temp_restore_dir
  859. restore_directory_from_friend $temp_restore_dir blog
  860. rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
  861. cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
  862. if [ ! "$?" = "0" ]; then
  863. exit 593
  864. fi
  865. rm -rf $temp_restore_dir
  866. if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
  867. echo $"No content directory found after restoring blog"
  868. exit 287
  869. fi
  870. # Ensure that the bundled SSL cert is being used
  871. if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
  872. sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
  873. fi
  874. for d in /home/*/ ; do
  875. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  876. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  877. if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
  878. mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
  879. fi
  880. done
  881. if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
  882. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
  883. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
  884. fi
  885. fi
  886. }
  887. function restore_cjdns {
  888. if [[ $RESTORE_APP != 'all' ]]; then
  889. if [[ $RESTORE_APP != 'cjdns' ]]; then
  890. return
  891. fi
  892. fi
  893. if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
  894. echo $"Restoring cjdns installation"
  895. temp_restore_dir=/root/tempcjdns
  896. restore_directory_from_friend $temp_restore_dir cjdns
  897. rm -rf /etc/cjdns
  898. cp -r $temp_restore_dir/etc/cjdns /etc/
  899. if [ ! "$?" = "0" ]; then
  900. exit 7438
  901. fi
  902. rm -rf $temp_restore_dir
  903. fi
  904. }
  905. function restore_voip {
  906. if [[ $RESTORE_APP != 'all' ]]; then
  907. if [[ $RESTORE_APP != 'voip' ]]; then
  908. return
  909. fi
  910. fi
  911. if [ -d $SERVER_DIRECTORY/backup/voip ]; then
  912. echo $"Restoring VoIP settings"
  913. temp_restore_dir=/root/tempvoip
  914. restore_directory_from_friend $temp_restore_dir voip
  915. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
  916. if [ ! "$?" = "0" ]; then
  917. rm -rf $temp_restore_dir
  918. exit 7823
  919. fi
  920. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
  921. if [ ! "$?" = "0" ]; then
  922. rm -rf $temp_restore_dir
  923. exit 7823
  924. fi
  925. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
  926. if [ ! "$?" = "0" ]; then
  927. rm -rf $temp_restore_dir
  928. exit 276
  929. fi
  930. rm -rf $temp_restore_dir
  931. cp /etc/ssl/certs/mumble* /var/lib/mumble-server
  932. cp /etc/ssl/private/mumble* /var/lib/mumble-server
  933. chown -R mumble-server:mumble-server /var/lib/mumble-server
  934. service sipwitch restart
  935. service mumble-server restart
  936. fi
  937. }
  938. function restore_tox {
  939. if [[ $RESTORE_APP != 'all' ]]; then
  940. if [[ $RESTORE_APP != 'tox' ]]; then
  941. return
  942. fi
  943. fi
  944. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  945. echo $"Restoring Tox node settings"
  946. restore_directory_from_friend / tox
  947. if [ ! "$?" = "0" ]; then
  948. exit 93653
  949. fi
  950. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  951. systemctl restart tox-bootstrapd.service
  952. if [ ! "$?" = "0" ]; then
  953. systemctl status tox-bootstrapd.service
  954. exit 59369
  955. fi
  956. fi
  957. }
  958. function restore_email {
  959. if [[ $RESTORE_APP != 'all' ]]; then
  960. if [[ $RESTORE_APP != 'email' ]]; then
  961. return
  962. fi
  963. fi
  964. for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
  965. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  966. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  967. if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
  968. if [ ! -d /home/$USERNAME ]; then
  969. ${PROJECT_NAME}-adduser $USERNAME
  970. fi
  971. echo $"Restoring emails for $USERNAME"
  972. temp_restore_dir=/root/tempmail
  973. restore_directory_from_friend $temp_restore_dir mail/$USERNAME
  974. if [ ! -d /home/$USERNAME/Maildir ]; then
  975. mkdir /home/$USERNAME/Maildir
  976. fi
  977. tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
  978. if [ ! "$?" = "0" ]; then
  979. exit 927
  980. fi
  981. rm -rf $temp_restore_dir
  982. fi
  983. fi
  984. done
  985. }
  986. function restore_dlna {
  987. if [[ $RESTORE_APP != 'all' ]]; then
  988. if [[ $RESTORE_APP != 'dlna' ]]; then
  989. return
  990. fi
  991. fi
  992. if [ -d /var/cache/minidlna ]; then
  993. if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
  994. echo $"Restoring DLNA cache"
  995. temp_restore_dir=/root/tempdlna
  996. restore_directory_from_friend $temp_restore_dir dlna
  997. cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
  998. if [ ! "$?" = "0" ]; then
  999. exit 982
  1000. fi
  1001. rm -rf $temp_restore_dir
  1002. fi
  1003. fi
  1004. }
  1005. # Social key management
  1006. # Recover any key fragments and reconstruct the gpg key
  1007. ${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l $BACKUP_LIST
  1008. copy_gpg_keys
  1009. restore_configuration
  1010. restore_mariadb
  1011. restore_letsencrypt
  1012. restore_mutt_settings
  1013. restore_gpg
  1014. restore_procmail
  1015. restore_spamassassin
  1016. restore_admin_readme
  1017. restore_ssh_keys
  1018. restore_user_config
  1019. restore_user_monkeysphere
  1020. restore_user_fin
  1021. restore_user_local
  1022. restore_certs
  1023. restore_personal_settings
  1024. restore_mailing_list
  1025. restore_email
  1026. restore_gnusocial
  1027. restore_hubzilla
  1028. restore_rss
  1029. restore_syncthing
  1030. restore_mediagoblin
  1031. restore_gogs
  1032. restore_wiki
  1033. restore_blog
  1034. restore_cjdns
  1035. restore_voip
  1036. restore_tox
  1037. restore_dlna
  1038. echo $"*** Remote restore was successful ***"
  1039. exit 0