Bob Mottram 8 år sedan
förälder
incheckning
f11a4f2080
3 ändrade filer med 819 tillägg och 780 borttagningar
  1. 22
    19
      src/freedombone-backup-local
  2. 664
    653
      src/freedombone-restore-local
  3. 133
    108
      src/freedombone-restore-remote

+ 22
- 19
src/freedombone-backup-local Visa fil

@@ -285,48 +285,51 @@ function prepare_directories {
285 285
 
286 286
 function backup_configuration {
287 287
 	echo $"Backing up ${PROJECT_NAME} configuration files"
288
-	if [ ! -d /root/tempbackupconfig ]; then
289
-		mkdir -p /root/tempbackupconfig
288
+	temp_backup_dir=/root/tempbackupconfig
289
+	if [ ! -d $temp_backup_dir ]; then
290
+		mkdir -p $temp_backup_dir
290 291
 	fi
291
-	cp -f $CONFIG_FILE /root/tempbackupconfig
292
-	cp -f $COMPLETION_FILE /root/tempbackupconfig
292
+	cp -f $CONFIG_FILE $temp_backup_dir
293
+	cp -f $COMPLETION_FILE $temp_backup_dir
293 294
 	if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
294
-		cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
295
+		cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
295 296
 	fi
296 297
 	# nginx password hashes
297 298
 	if [ -f /etc/nginx/.htpasswd ]; then
298
-		cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd
299
+		cp -f /etc/nginx/.htpasswd $temp_backup_dir/htpasswd
299 300
 	fi
300
-	backup_directory_to_usb /root/tempbackupconfig config
301
+	backup_directory_to_usb $temp_backup_dir config
301 302
 }
302 303
 
303 304
 function backup_admin_readme {
304 305
 	if [ -f /home/$ADMIN_USERNAME/README ]; then
305 306
 		echo $"Backing up README"
306
-		if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
307
-			mkdir -p /home/$ADMIN_USERNAME/tempbackup
307
+		temp_backup_dir=/home/$ADMIN_USERNAME/tempbackup
308
+		if [ ! -d $temp_backup_dir ]; then
309
+			mkdir -p $temp_backup_dir
308 310
 		fi
309
-		cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
310
-		backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
311
+		cp -f /home/$ADMIN_USERNAME/README $temp_backup_dir
312
+		backup_directory_to_usb $temp_backup_dir readme
311 313
 	fi
312 314
 }
313 315
 
314 316
 function backup_mariadb {
315 317
 	if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
316
-		if [ ! -d /root/tempmariadb ]; then
317
-			mkdir /root/tempmariadb
318
+		temp_backup_dir=/root/tempmariadb
319
+		if [ ! -d $temp_backup_dir ]; then
320
+			mkdir $temp_backup_dir
318 321
 		fi
319
-		mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
320
-		if [ ! -s /root/tempmariadb/mysql.sql ]; then
322
+		mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > $temp_backup_dir/mysql.sql
323
+		if [ ! -s $temp_backup_dir/mysql.sql ]; then
321 324
 			echo $"Unable to backup mysql settings"
322
-			rm -rf /root/tempmariadb
325
+			rm -rf $temp_backup_dir
323 326
 			umount $USB_MOUNT
324 327
 			rm -rf $USB_MOUNT
325 328
 			exit 8
326 329
 		fi
327
-		echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
328
-		chmod 400 /root/tempmariadb/db
329
-		backup_directory_to_usb /root/tempmariadb mariadb
330
+		echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
331
+		chmod 400 $temp_backup_dir/db
332
+		backup_directory_to_usb $temp_backup_dir mariadb
330 333
 	fi
331 334
 }
332 335
 

+ 664
- 653
src/freedombone-restore-local
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 133
- 108
src/freedombone-restore-remote Visa fil

@@ -179,12 +179,13 @@ function restore_configuration {
179 179
 	fi
180 180
 	if [ -d $SERVER_DIRECTORY/backup/config ]; then
181 181
 		echo $"Restoring configuration files"
182
-		restore_directory_from_friend /root/tempconfig config
182
+		temp_restore_dir=/root/tempconfig
183
+		restore_directory_from_friend $temp_restore_dir config
183 184
 
184
-		cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
185
+		cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
185 186
 		if [ ! "$?" = "0" ]; then
186 187
 			unmount_drive
187
-			rm -rf /root/tempconfig
188
+			rm -rf $temp_restore_dir
188 189
 			exit 5372
189 190
 		fi
190 191
 		if [ -f $CONFIG_FILE ]; then
@@ -192,28 +193,28 @@ function restore_configuration {
192 193
 			freedombone -c $CONFIG_FILE
193 194
 		fi
194 195
 
195
-		cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
196
+		cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
196 197
 		if [ ! "$?" = "0" ]; then
197 198
 			unmount_drive
198
-			rm -rf /root/tempconfig
199
+			rm -rf $temp_restore_dir
199 200
 			exit 7252
200 201
 		fi
201 202
 
202
-		if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then
203
-			cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
203
+		if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then
204
+			cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
204 205
 			if [ ! "$?" = "0" ]; then
205 206
 				unmount_drive
206
-				rm -rf /root/tempconfig
207
+				rm -rf $temp_restore_dir
207 208
 				exit 62121
208 209
 			fi
209 210
 		fi
210 211
 
211 212
 		# restore nginx password hashes
212
-		if [ -f /root/tempconfig/root/htpasswd ]; then
213
-			cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd
213
+		if [ -f $temp_restore_dir/root/htpasswd ]; then
214
+			cp -f $temp_restore_dir/root/htpasswd /etc/nginx/.htpasswd
214 215
 		fi
215 216
 
216
-		rm -rf /root/tempconfig
217
+		rm -rf $temp_restore_dir
217 218
 	fi
218 219
 }
219 220
 
@@ -225,19 +226,20 @@ function restore_mariadb {
225 226
 	fi
226 227
 	if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
227 228
 		echo $"Restoring MariaDB settings"
228
-		restore_directory_from_friend /root/tempmariadb mariadb
229
+		temp_restore_dir=/root/tempmariadb
230
+		restore_directory_from_friend $temp_restore_dir mariadb
229 231
 		echo $"Get the MariaDB password from the backup"
230
-		if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then
232
+		if [ ! -f ${temp_restore_dir}${temp_restore_dir}/db ]; then
231 233
 			echo $"MariaDB password file not found"
232 234
 			exit 495
233 235
 		fi
234
-		BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db)
236
+		BACKUP_MARIADB_PASSWORD=$(cat ${temp_restore_dir}${temp_restore_dir}/db)
235 237
 		if [[ "$BACKUP_MARIADB_PASSWORD" != "$DATABASE_PASSWORD" ]]; then
236 238
 			echo $"Restore the MariaDB user table"
237
-			mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql)
239
+			mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
238 240
 			if [ ! "$?" = "0" ]; then
239 241
 				echo $"Try again using the password obtained from backup"
240
-				mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql)
242
+				mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
241 243
 			fi
242 244
 			if [ ! "$?" = "0" ]; then
243 245
 				echo "$mysqlsuccess"
@@ -248,8 +250,8 @@ function restore_mariadb {
248 250
 			echo $"Change the MariaDB password to the backup version"
249 251
 			DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD
250 252
 		fi
251
-		shred -zu /root/tempmariadb/root/tempmariadb/db
252
-		rm -rf /root/tempmariadb
253
+		shred -zu ${temp_restore_dir}${temp_restore_dir}/db
254
+		rm -rf ${temp_restore_dir}
253 255
 
254 256
 		# Change database password file
255 257
 		echo "$DATABASE_PASSWORD" > /root/dbpass
@@ -295,18 +297,19 @@ function restore_mutt_settings {
295 297
 					${PROJECT_NAME}-adduser $USERNAME
296 298
 				fi
297 299
 				echo $"Restoring Mutt settings for $USERNAME"
298
-				restore_directory_from_friend /root/tempmutt mutt/$USERNAME
299
-				if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then
300
-					cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
300
+				temp_restore_dir=/root/tempmutt
301
+				restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME
302
+				if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc ]; then
303
+					cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
301 304
 				fi
302
-				if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then
303
-					cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
305
+				if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc ]; then
306
+					cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
304 307
 				fi
305 308
 				if [ ! "$?" = "0" ]; then
306
-					rm -rf /root/tempmutt
309
+					rm -rf ${temp_restore_dir}
307 310
 					exit 276
308 311
 				fi
309
-				rm -rf /root/tempmutt
312
+				rm -rf ${temp_restore_dir}
310 313
 			fi
311 314
 		fi
312 315
 	done
@@ -326,13 +329,14 @@ function restore_gpg {
326 329
 					${PROJECT_NAME}-adduser $USERNAME
327 330
 				fi
328 331
 				echo $"Restoring gnupg settings for $USERNAME"
329
-				restore_directory_from_friend /root/tempgnupg gnupg/$USERNAME
330
-				cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/
332
+				temp_restore_dir=/root/tempgnupg
333
+				restore_directory_from_friend ${temp_restore_dir} gnupg/$USERNAME
334
+				cp -r ${temp_restore_dir}/home/$USERNAME/.gnupg /home/$USERNAME/
331 335
 				if [ ! "$?" = "0" ]; then
332
-					rm -rf /root/tempgnupg
336
+					rm -rf ${temp_restore_dir}
333 337
 					exit 276
334 338
 				fi
335
-				rm -rf /root/tempgnupg
339
+				rm -rf ${temp_restore_dir}
336 340
 				if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
337 341
 					cp -r /home/$USERNAME/.gnupg /root
338 342
 					if [ ! "$?" = "0" ]; then
@@ -358,13 +362,14 @@ function restore_procmail {
358 362
 					${PROJECT_NAME}-adduser $USERNAME
359 363
 				fi
360 364
 				echo $"Restoring procmail settings for $USERNAME"
361
-				restore_directory_from_friend /root/tempprocmail procmail/$USERNAME
362
-				cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
365
+				temp_restore_dir=/root/tempprocmail
366
+				restore_directory_from_friend ${temp_restore_dir} procmail/$USERNAME
367
+				cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
363 368
 				if [ ! "$?" = "0" ]; then
364
-					rm -rf /root/tempprocmail
369
+					rm -rf ${temp_restore_dir}
365 370
 					exit 276
366 371
 				fi
367
-				rm -rf /root/tempprocmail
372
+				rm -rf ${temp_restore_dir}
368 373
 			fi
369 374
 		fi
370 375
 	done
@@ -384,13 +389,14 @@ function restore_spamassassin {
384 389
 					${PROJECT_NAME}-adduser $USERNAME
385 390
 				fi
386 391
 				echo $"Restoring spamassassin settings for $USERNAME"
387
-				restore_directory_from_friend /root/tempspamassassin spamassassin/$USERNAME
388
-				cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/
392
+				temp_restore_dir=/root/tempspamassassin
393
+				restore_directory_from_friend $temp_restore_dir spamassassin/$USERNAME
394
+				cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/
389 395
 				if [ ! "$?" = "0" ]; then
390
-					rm -rf /root/tempspamassassin
396
+					rm -rf $temp_restore_dir
391 397
 					exit 276
392 398
 				fi
393
-				rm -rf /root/tempspamassassin
399
+				rm -rf $temp_restore_dir
394 400
 			fi
395 401
 		fi
396 402
 	done
@@ -404,13 +410,14 @@ function restore_admin_readme {
404 410
 	fi
405 411
 	if [ -d $SERVER_DIRECTORY/backup/readme ]; then
406 412
 		echo $"Restoring README"
407
-		restore_directory_from_friend /root/tempreadme readme
408
-		cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
413
+		temp_restore_dir=/root/tempreadme
414
+		restore_directory_from_friend $temp_restore_dir readme
415
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
409 416
 		if [ ! "$?" = "0" ]; then
410
-			rm -rf /root/tempreadme
417
+			rm -rf $temp_restore_dir
411 418
 			exit 276
412 419
 		fi
413
-		rm -rf /root/tempreadme
420
+		rm -rf $temp_restore_dir
414 421
 	fi
415 422
 }
416 423
 
@@ -422,13 +429,14 @@ function restore_ipfs {
422 429
 	fi
423 430
 	if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
424 431
 		echo $"Restoring IPFS"
425
-		restore_directory_from_friend /root/tempipfs ipfs
426
-		cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
432
+		temp_restore_dir=/root/tempipfs
433
+		restore_directory_from_friend $temp_restore_dir ipfs
434
+		cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
427 435
 		if [ ! "$?" = "0" ]; then
428
-			rm -rf /root/tempipfs
436
+			rm -rf $temp_restore_dir
429 437
 			exit 276
430 438
 		fi
431
-		rm -rf /root/tempipfs
439
+		rm -rf $temp_restore_dir
432 440
 	fi
433 441
 }
434 442
 
@@ -446,13 +454,14 @@ function restore_ssh_keys {
446 454
 					${PROJECT_NAME}-adduser $USERNAME
447 455
 				fi
448 456
 				echo $"Restoring ssh keys for $USERNAME"
449
-				restore_directory_from_friend /root/tempssh ssh/$USERNAME
450
-				cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/
457
+				temp_restore_dir=/root/tempssh
458
+				restore_directory_from_friend $temp_restore_dir ssh/$USERNAME
459
+				cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/
451 460
 				if [ ! "$?" = "0" ]; then
452
-					rm -rf /root/tempssh
461
+					rm -rf $temp_restore_dir
453 462
 					exit 664
454 463
 				fi
455
-				rm -rf /root/tempssh
464
+				rm -rf $temp_restore_dir
456 465
 			fi
457 466
 		fi
458 467
 	done
@@ -472,13 +481,14 @@ function restore_user_config {
472 481
 					${PROJECT_NAME}-adduser $USERNAME
473 482
 				fi
474 483
 				echo $"Restoring config files for $USERNAME"
475
-				restore_directory_from_friend /root/tempconfig config/$USERNAME
476
-				cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/
484
+				temp_restore_dir=/root/tempconfig
485
+				restore_directory_from_friend $temp_restore_dir config/$USERNAME
486
+				cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/
477 487
 				if [ ! "$?" = "0" ]; then
478
-					rm -rf /root/tempconfig
488
+					rm -rf $temp_restore_dir
479 489
 					exit 664
480 490
 				fi
481
-				rm -rf /root/tempconfig
491
+				rm -rf $temp_restore_dir
482 492
 			fi
483 493
 		fi
484 494
 	done
@@ -510,13 +520,14 @@ function restore_user_monkeysphere {
510 520
 					${PROJECT_NAME}-adduser $USERNAME
511 521
 				fi
512 522
 				echo $"Restoring monkeysphere ids for $USERNAME"
513
-				restore_directory_from_friend /root/tempmonkeysphere monkeysphere/$USERNAME
514
-				cp -r /root/tempmonkeysphere/home/$USERNAME/.monkeysphere /home/$USERNAME/
523
+				temp_restore_dir=/root/tempmonkeysphere
524
+				restore_directory_from_friend $temp_restore_dir monkeysphere/$USERNAME
525
+				cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/
515 526
 				if [ ! "$?" = "0" ]; then
516
-					rm -rf /root/tempmonkeysphere
527
+					rm -rf $temp_restore_dir
517 528
 					exit 664
518 529
 				fi
519
-				rm -rf /root/tempmonkeysphere
530
+				rm -rf $temp_restore_dir
520 531
 			fi
521 532
 		fi
522 533
 
@@ -546,13 +557,14 @@ function restore_user_fin {
546 557
 					${PROJECT_NAME}-adduser $USERNAME
547 558
 				fi
548 559
 				echo $"Restoring fin files for $USERNAME"
549
-				restore_directory_from_friend /root/tempfin fin/$USERNAME
550
-				cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/
560
+				temp_restore_dir=/root/tempfin
561
+				restore_directory_from_friend $temp_restore_dir fin/$USERNAME
562
+				cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/
551 563
 				if [ ! "$?" = "0" ]; then
552
-					rm -rf /root/tempfin
564
+					rm -rf $temp_restore_dir
553 565
 					exit 664
554 566
 				fi
555
-				rm -rf /root/tempfin
567
+				rm -rf $temp_restore_dir
556 568
 			fi
557 569
 		fi
558 570
 	done
@@ -572,13 +584,14 @@ function restore_user_local {
572 584
 					${PROJECT_NAME}-adduser $USERNAME
573 585
 				fi
574 586
 				echo $"Restoring local files for $USERNAME"
575
-				restore_directory_from_friend /root/templocal local/$USERNAME
576
-				cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/
587
+				temp_restore_dir=/root/templocal
588
+				restore_directory_from_friend $temp_restore_dir local/$USERNAME
589
+				cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/
577 590
 				if [ ! "$?" = "0" ]; then
578
-					rm -rf /root/templocal
591
+					rm -rf $temp_restore_dir
579 592
 					exit 664
580 593
 				fi
581
-				rm -rf /root/templocal
594
+				rm -rf $temp_restore_dir
582 595
 			fi
583 596
 		fi
584 597
 	done
@@ -639,15 +652,16 @@ function restore_personal_settings {
639 652
 					${PROJECT_NAME}-adduser $USERNAME
640 653
 				fi
641 654
 				echo $"Restoring personal settings for $USERNAME"
642
-				restore_directory_from_friend /root/temppersonal personal/$USERNAME
655
+				temp_restore_dir=/root/temppersonal
656
+				restore_directory_from_friend $temp_restore_dir personal/$USERNAME
643 657
 				if [ -d /home/$USERNAME/personal ]; then
644 658
 					rm -rf /home/$USERNAME/personal
645 659
 				fi
646
-				mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME
660
+				mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
647 661
 				if [ ! "$?" = "0" ]; then
648 662
 					exit 184
649 663
 				fi
650
-				rm -rf /root/temppersonal
664
+				rm -rf $temp_restore_dir
651 665
 			fi
652 666
 		fi
653 667
 	done
@@ -661,12 +675,13 @@ function restore_mailing_list {
661 675
 	fi
662 676
 	if [ -d /var/spool/mlmmj ]; then
663 677
 		echo $"Restoring public mailing list"
664
-		restore_directory_from_friend /root/tempmailinglist mailinglist
665
-		cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj
678
+		temp_restore_dir=/root/tempmailinglist
679
+		restore_directory_from_friend $temp_restore_dir mailinglist
680
+		cp -r $temp_restore_dir/root/spool/mlmmj/* /var/spool/mlmmj
666 681
 		if [ ! "$?" = "0" ]; then
667 682
 			exit 526
668 683
 		fi
669
-		rm -rf /root/tempmailinglist
684
+		rm -rf $temp_restore_dir
670 685
 	fi
671 686
 }
672 687
 
@@ -678,12 +693,13 @@ function restore_xmpp {
678 693
 	fi
679 694
 	if [ -d /var/lib/prosody ]; then
680 695
 		echo $"Restoring XMPP settings"
681
-		restore_directory_from_friend /root/tempxmpp xmpp
682
-		cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody
696
+		temp_restore_dir=/root/tempxmpp
697
+		restore_directory_from_friend $temp_restore_dir xmpp
698
+		cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
683 699
 		if [ ! "$?" = "0" ]; then
684 700
 			exit 725
685 701
 		fi
686
-		rm -rf /root/tempxmpp
702
+		rm -rf $temp_restore_dir
687 703
 		service prosody restart
688 704
 		chown -R prosody:prosody /var/lib/prosody/*
689 705
 	fi
@@ -767,28 +783,30 @@ function restore_syncthing {
767 783
 
768 784
 	if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
769 785
 		echo $"Restoring syncthing configuration"
770
-		restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig
771
-		cp -r /root/tempsyncthingconfig/* /
786
+		temp_restore_dir=/root/tempsyncthingconfig
787
+		restore_directory_from_friend $temp_restore_dir syncthingconfig
788
+		cp -r $temp_restore_dir/* /
772 789
 		if [ ! "$?" = "0" ]; then
773 790
 			unmount_drive
774 791
 			systemctl start syncthing
775 792
 			systemctl start cron
776 793
 			exit 6833
777 794
 		fi
778
-		rm -rf /root/tempsyncthingconfig
795
+		rm -rf $temp_restore_dir
779 796
 	fi
780 797
 
781 798
 	if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
782 799
 		echo $"Restoring syncthing shared files"
783
-		restore_directory_from_friend /root/tempsyncthingshared syncthingshared
784
-		cp -r /root/tempsyncthingshared/* /
800
+		temp_restore_dir=/root/tempsyncthingshared
801
+		restore_directory_from_friend $temp_restore_dir syncthingshared
802
+		cp -r $temp_restore_dir/* /
785 803
 		if [ ! "$?" = "0" ]; then
786 804
 			unmount_drive
787 805
 			systemctl start syncthing
788 806
 			systemctl start cron
789 807
 			exit 37904
790 808
 		fi
791
-		rm -rf /root/tempsyncthingshared
809
+		rm -rf $temp_restore_dir
792 810
 	fi
793 811
 
794 812
 	if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
@@ -799,16 +817,17 @@ function restore_syncthing {
799 817
 					${PROJECT_NAME}-adduser $USERNAME
800 818
 				fi
801 819
 				echo $"Restoring syncthing files for $USERNAME"
802
-				restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME
803
-				cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/
820
+				temp_restore_dir=/root/tempsyncthing
821
+				restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
822
+				cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
804 823
 				if [ ! "$?" = "0" ]; then
805
-					rm -rf /root/tempsyncthing
824
+					rm -rf $temp_restore_dir
806 825
 					unmount_drive
807 826
 					systemctl start syncthing
808 827
 					systemctl start cron
809 828
 					exit 68438
810 829
 				fi
811
-				rm -rf /root/tempsyncthing
830
+				rm -rf $temp_restore_dir
812 831
 
813 832
 				# restore device IDs from config settings
814 833
 				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
@@ -839,12 +858,13 @@ function restore_mediagoblin {
839 858
 		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
840 859
 		if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
841 860
 			echo $"Restoring Mediagoblin installation"
842
-			restore_directory_from_friend /root/tempmediagoblin mediagoblin
843
-			cp -r /root/tempmediagoblin/* /
861
+			temp_restore_dir=/root/tempmediagoblin
862
+			restore_directory_from_friend $temp_restore_dir mediagoblin
863
+			cp -r $temp_restore_dir/* /
844 864
 			if [ ! "$?" = "0" ]; then
845 865
 				exit 5626
846 866
 			fi
847
-			rm -rf /root/tempmediagoblin
867
+			rm -rf $temp_restore_dir
848 868
 		fi
849 869
 		chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
850 870
 	fi
@@ -940,14 +960,15 @@ function restore_blog {
940 960
 	if [ -d $SERVER_DIRECTORY/backup/blog ]; then
941 961
 		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
942 962
 		echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
943
-		mkdir /root/tempblog
944
-		restore_directory_from_friend /root/tempblog blog
963
+		temp_restore_dir=/root/tempblog
964
+		mkdir $temp_restore_dir
965
+		restore_directory_from_friend $temp_restore_dir blog
945 966
 		rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
946
-		cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
967
+		cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
947 968
 		if [ ! "$?" = "0" ]; then
948 969
 			exit 593
949 970
 		fi
950
-		rm -rf /root/tempblog
971
+		rm -rf $temp_restore_dir
951 972
 		if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
952 973
 			echo $"No content directory found after restoring blog"
953 974
 			exit 287
@@ -978,13 +999,14 @@ function restore_cjdns {
978 999
 	fi
979 1000
 	if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
980 1001
 		echo $"Restoring cjdns installation"
981
-		restore_directory_from_friend /root/tempcjdns cjdns
1002
+		temp_restore_dir=/root/tempcjdns
1003
+		restore_directory_from_friend $temp_restore_dir cjdns
982 1004
 		rm -rf /etc/cjdns
983
-		cp -r /root/tempcjdns/etc/cjdns /etc/
1005
+		cp -r $temp_restore_dir/etc/cjdns /etc/
984 1006
 		if [ ! "$?" = "0" ]; then
985 1007
 			exit 7438
986 1008
 		fi
987
-		rm -rf /root/tempcjdns
1009
+		rm -rf $temp_restore_dir
988 1010
 	fi
989 1011
 }
990 1012
 
@@ -996,23 +1018,24 @@ function restore_voip {
996 1018
 	fi
997 1019
 	if [ -d $SERVER_DIRECTORY/backup/voip ]; then
998 1020
 		echo $"Restoring VoIP settings"
999
-		restore_directory_from_friend /root/tempvoip voip
1000
-		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
1021
+		temp_restore_dir=/root/tempvoip
1022
+		restore_directory_from_friend $temp_restore_dir voip
1023
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
1001 1024
 		if [ ! "$?" = "0" ]; then
1002
-			rm -rf /root/tempvoip
1025
+			rm -rf $temp_restore_dir
1003 1026
 			exit 7823
1004 1027
 		fi
1005
-		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
1028
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
1006 1029
 		if [ ! "$?" = "0" ]; then
1007
-			rm -rf /root/tempvoip
1030
+			rm -rf $temp_restore_dir
1008 1031
 			exit 7823
1009 1032
 		fi
1010
-		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
1033
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
1011 1034
 		if [ ! "$?" = "0" ]; then
1012
-			rm -rf /root/tempvoip
1035
+			rm -rf $temp_restore_dir
1013 1036
 			exit 276
1014 1037
 		fi
1015
-		rm -rf /root/tempvoip
1038
+		rm -rf $temp_restore_dir
1016 1039
 		cp /etc/ssl/certs/mumble* /var/lib/mumble-server
1017 1040
 		cp /etc/ssl/private/mumble* /var/lib/mumble-server
1018 1041
 		chown -R mumble-server:mumble-server /var/lib/mumble-server
@@ -1056,15 +1079,16 @@ function restore_email {
1056 1079
 					${PROJECT_NAME}-adduser $USERNAME
1057 1080
 				fi
1058 1081
 				echo $"Restoring emails for $USERNAME"
1059
-				restore_directory_from_friend /root/tempmail mail/$USERNAME
1082
+				temp_restore_dir=/root/tempmail
1083
+				restore_directory_from_friend $temp_restore_dir mail/$USERNAME
1060 1084
 				if [ ! -d /home/$USERNAME/Maildir ]; then
1061 1085
 					mkdir /home/$USERNAME/Maildir
1062 1086
 				fi
1063
-				tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
1087
+				tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
1064 1088
 				if [ ! "$?" = "0" ]; then
1065 1089
 					exit 927
1066 1090
 				fi
1067
-				rm -rf /root/tempmail
1091
+				rm -rf $temp_restore_dir
1068 1092
 			fi
1069 1093
 		fi
1070 1094
 	done
@@ -1079,12 +1103,13 @@ function restore_dlna {
1079 1103
 	if [ -d /var/cache/minidlna ]; then
1080 1104
 		if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
1081 1105
 			echo $"Restoring DLNA cache"
1082
-			restore_directory_from_friend /root/tempdlna dlna
1083
-			cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/
1106
+			temp_restore_dir=/root/tempdlna
1107
+			restore_directory_from_friend $temp_restore_dir dlna
1108
+			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
1084 1109
 			if [ ! "$?" = "0" ]; then
1085 1110
 				exit 982
1086 1111
 			fi
1087
-			rm -rf /root/tempdlna
1112
+			rm -rf $temp_restore_dir
1088 1113
 		fi
1089 1114
 	fi
1090 1115
 }