freedombone-restore-remote 32KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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_syncthing {
  620. if [[ $RESTORE_APP != 'all' ]]; then
  621. if [[ $RESTORE_APP != 'syncthing' ]]; then
  622. return
  623. fi
  624. fi
  625. if [ -f /etc/systemd/system/syncthing.service ]; then
  626. systemctl stop syncthing
  627. systemctl stop cron
  628. fi
  629. if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
  630. echo $"Restoring syncthing configuration"
  631. temp_restore_dir=/root/tempsyncthingconfig
  632. restore_directory_from_friend $temp_restore_dir syncthingconfig
  633. cp -r $temp_restore_dir/* /
  634. if [ ! "$?" = "0" ]; then
  635. unmount_drive
  636. systemctl start syncthing
  637. systemctl start cron
  638. exit 6833
  639. fi
  640. rm -rf $temp_restore_dir
  641. fi
  642. if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
  643. echo $"Restoring syncthing shared files"
  644. temp_restore_dir=/root/tempsyncthingshared
  645. restore_directory_from_friend $temp_restore_dir syncthingshared
  646. cp -r $temp_restore_dir/* /
  647. if [ ! "$?" = "0" ]; then
  648. unmount_drive
  649. systemctl start syncthing
  650. systemctl start cron
  651. exit 37904
  652. fi
  653. rm -rf $temp_restore_dir
  654. fi
  655. if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
  656. for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
  657. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  658. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  659. if [ ! -d /home/$USERNAME ]; then
  660. ${PROJECT_NAME}-adduser $USERNAME
  661. fi
  662. echo $"Restoring syncthing files for $USERNAME"
  663. temp_restore_dir=/root/tempsyncthing
  664. restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
  665. cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
  666. if [ ! "$?" = "0" ]; then
  667. rm -rf $temp_restore_dir
  668. unmount_drive
  669. systemctl start syncthing
  670. systemctl start cron
  671. exit 68438
  672. fi
  673. rm -rf $temp_restore_dir
  674. # restore device IDs from config settings
  675. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  676. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  677. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  678. fi
  679. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  680. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  681. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  682. fi
  683. fi
  684. done
  685. fi
  686. if [ -f /etc/systemd/system/syncthing.service ]; then
  687. systemctl start syncthing
  688. systemctl start cron
  689. fi
  690. }
  691. function restore_mediagoblin {
  692. if [[ $RESTORE_APP != 'all' ]]; then
  693. if [[ $RESTORE_APP != 'mediagoblin' ]]; then
  694. return
  695. fi
  696. fi
  697. if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
  698. MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
  699. if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
  700. echo $"Restoring Mediagoblin installation"
  701. temp_restore_dir=/root/tempmediagoblin
  702. restore_directory_from_friend $temp_restore_dir mediagoblin
  703. cp -r $temp_restore_dir/* /
  704. if [ ! "$?" = "0" ]; then
  705. exit 5626
  706. fi
  707. rm -rf $temp_restore_dir
  708. fi
  709. chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
  710. fi
  711. }
  712. function restore_gogs {
  713. export GVM_ROOT=$GVM_HOME
  714. if [ -d $GVM_ROOT/bin ]; then
  715. cd $GVM_ROOT/bin
  716. [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
  717. gvm use go${GO_VERSION} --default
  718. systemctl set-environment GOPATH=$GOPATH
  719. fi
  720. if [[ $RESTORE_APP != 'all' ]]; then
  721. if [[ $RESTORE_APP != 'gogs' ]]; then
  722. return
  723. fi
  724. fi
  725. if grep -q "Gogs domain" $COMPLETION_FILE; then
  726. GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
  727. restore_database_from_friend gogs $GIT_DOMAIN_NAME
  728. if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
  729. if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
  730. mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
  731. fi
  732. cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom/
  733. if [ ! "$?" = "0" ]; then
  734. exit 5885
  735. fi
  736. echo $"Restoring Gogs repos"
  737. restore_directory_from_friend /root/tempgogsrepos gogsrepos
  738. cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
  739. if [ ! "$?" = "0" ]; then
  740. exit 7649
  741. fi
  742. echo $"Restoring Gogs authorized_keys"
  743. restore_directory_from_friend /root/tempgogsssh gogsssh
  744. if [ ! -d /home/git/.ssh ]; then
  745. mkdir /home/git/.ssh
  746. fi
  747. cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
  748. if [ ! "$?" = "0" ]; then
  749. exit 74239
  750. fi
  751. rm -rf /root/tempgogs
  752. rm -rf /root/tempgogsrepos
  753. rm -rf /root/tempgogsssh
  754. chown -R git:git /home/git
  755. fi
  756. fi
  757. }
  758. function restore_wiki {
  759. if [[ $RESTORE_APP != 'all' ]]; then
  760. if [[ $RESTORE_APP != 'wiki' ]]; then
  761. return
  762. fi
  763. fi
  764. if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
  765. WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
  766. echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
  767. restore_directory_from_friend /root/tempwiki wiki
  768. cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
  769. if [ ! "$?" = "0" ]; then
  770. exit 868
  771. fi
  772. restore_directory_from_friend /root/tempwiki2 wiki2
  773. cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
  774. if [ ! "$?" = "0" ]; then
  775. exit 869
  776. fi
  777. rm -rf /root/tempwiki
  778. rm -rf /root/tempwiki2
  779. chown -R www-data:www-data /var/lib/dokuwiki/*
  780. # Ensure that the bundled SSL cert is being used
  781. if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
  782. sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
  783. fi
  784. if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
  785. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
  786. ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
  787. fi
  788. fi
  789. }
  790. function restore_blog {
  791. if [[ $RESTORE_APP != 'all' ]]; then
  792. if [[ $RESTORE_APP != 'blog' ]]; then
  793. return
  794. fi
  795. fi
  796. if [ -d $SERVER_DIRECTORY/backup/blog ]; then
  797. FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
  798. echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
  799. temp_restore_dir=/root/tempblog
  800. mkdir $temp_restore_dir
  801. restore_directory_from_friend $temp_restore_dir blog
  802. rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
  803. cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
  804. if [ ! "$?" = "0" ]; then
  805. exit 593
  806. fi
  807. rm -rf $temp_restore_dir
  808. if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
  809. echo $"No content directory found after restoring blog"
  810. exit 287
  811. fi
  812. # Ensure that the bundled SSL cert is being used
  813. if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
  814. sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
  815. fi
  816. for d in /home/*/ ; do
  817. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  818. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  819. if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
  820. mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
  821. fi
  822. done
  823. if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
  824. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
  825. ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
  826. fi
  827. fi
  828. }
  829. function restore_cjdns {
  830. if [[ $RESTORE_APP != 'all' ]]; then
  831. if [[ $RESTORE_APP != 'cjdns' ]]; then
  832. return
  833. fi
  834. fi
  835. if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
  836. echo $"Restoring cjdns installation"
  837. temp_restore_dir=/root/tempcjdns
  838. restore_directory_from_friend $temp_restore_dir cjdns
  839. rm -rf /etc/cjdns
  840. cp -r $temp_restore_dir/etc/cjdns /etc/
  841. if [ ! "$?" = "0" ]; then
  842. exit 7438
  843. fi
  844. rm -rf $temp_restore_dir
  845. fi
  846. }
  847. function restore_voip {
  848. if [[ $RESTORE_APP != 'all' ]]; then
  849. if [[ $RESTORE_APP != 'voip' ]]; then
  850. return
  851. fi
  852. fi
  853. if [ -d $SERVER_DIRECTORY/backup/voip ]; then
  854. echo $"Restoring VoIP settings"
  855. temp_restore_dir=/root/tempvoip
  856. restore_directory_from_friend $temp_restore_dir voip
  857. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
  858. if [ ! "$?" = "0" ]; then
  859. rm -rf $temp_restore_dir
  860. exit 7823
  861. fi
  862. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
  863. if [ ! "$?" = "0" ]; then
  864. rm -rf $temp_restore_dir
  865. exit 7823
  866. fi
  867. cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
  868. if [ ! "$?" = "0" ]; then
  869. rm -rf $temp_restore_dir
  870. exit 276
  871. fi
  872. rm -rf $temp_restore_dir
  873. cp /etc/ssl/certs/mumble* /var/lib/mumble-server
  874. cp /etc/ssl/private/mumble* /var/lib/mumble-server
  875. chown -R mumble-server:mumble-server /var/lib/mumble-server
  876. service sipwitch restart
  877. service mumble-server restart
  878. fi
  879. }
  880. function restore_tox {
  881. if [[ $RESTORE_APP != 'all' ]]; then
  882. if [[ $RESTORE_APP != 'tox' ]]; then
  883. return
  884. fi
  885. fi
  886. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  887. echo $"Restoring Tox node settings"
  888. restore_directory_from_friend / tox
  889. if [ ! "$?" = "0" ]; then
  890. exit 93653
  891. fi
  892. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  893. systemctl restart tox-bootstrapd.service
  894. if [ ! "$?" = "0" ]; then
  895. systemctl status tox-bootstrapd.service
  896. exit 59369
  897. fi
  898. fi
  899. }
  900. function restore_email {
  901. if [[ $RESTORE_APP != 'all' ]]; then
  902. if [[ $RESTORE_APP != 'email' ]]; then
  903. return
  904. fi
  905. fi
  906. for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
  907. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  908. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  909. if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
  910. if [ ! -d /home/$USERNAME ]; then
  911. ${PROJECT_NAME}-adduser $USERNAME
  912. fi
  913. echo $"Restoring emails for $USERNAME"
  914. temp_restore_dir=/root/tempmail
  915. restore_directory_from_friend $temp_restore_dir mail/$USERNAME
  916. if [ ! -d /home/$USERNAME/Maildir ]; then
  917. mkdir /home/$USERNAME/Maildir
  918. fi
  919. tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
  920. if [ ! "$?" = "0" ]; then
  921. exit 927
  922. fi
  923. rm -rf $temp_restore_dir
  924. fi
  925. fi
  926. done
  927. }
  928. function restore_dlna {
  929. if [[ $RESTORE_APP != 'all' ]]; then
  930. if [[ $RESTORE_APP != 'dlna' ]]; then
  931. return
  932. fi
  933. fi
  934. if [ -d /var/cache/minidlna ]; then
  935. if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
  936. echo $"Restoring DLNA cache"
  937. temp_restore_dir=/root/tempdlna
  938. restore_directory_from_friend $temp_restore_dir dlna
  939. cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
  940. if [ ! "$?" = "0" ]; then
  941. exit 982
  942. fi
  943. rm -rf $temp_restore_dir
  944. fi
  945. fi
  946. }
  947. # Social key management
  948. # Recover any key fragments and reconstruct the gpg key
  949. ${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l $BACKUP_LIST
  950. copy_gpg_keys
  951. restore_configuration
  952. restore_mariadb
  953. restore_letsencrypt
  954. restore_mutt_settings
  955. restore_gpg
  956. restore_procmail
  957. restore_spamassassin
  958. restore_admin_readme
  959. restore_ssh_keys
  960. restore_user_config
  961. restore_user_monkeysphere
  962. restore_user_fin
  963. restore_user_local
  964. restore_certs
  965. restore_personal_settings
  966. restore_mailing_list
  967. restore_email
  968. restore_syncthing
  969. restore_mediagoblin
  970. restore_gogs
  971. restore_wiki
  972. restore_blog
  973. restore_cjdns
  974. restore_voip
  975. restore_tox
  976. restore_dlna
  977. echo $"*** Remote restore was successful ***"
  978. exit 0