freedombone-restore-remote 41KB

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