소스 검색

Consolidate drive mount/unmount functions

Bob Mottram 8 년 전
부모
커밋
c6fe64ad7c
3개의 변경된 파일117개의 추가작업 그리고 116개의 파일을 삭제
  1. 2
    1
      src/freedombone-backup-local
  2. 110
    113
      src/freedombone-restore-local
  3. 5
    2
      src/freedombone-utils-backup

+ 2
- 1
src/freedombone-backup-local 파일 보기

@@ -36,7 +36,7 @@ ENABLE_BACKUP_VERIFICATION="no"
36 36
 export TEXTDOMAIN=${PROJECT_NAME}-backup-local
37 37
 export TEXTDOMAINDIR="/usr/share/locale"
38 38
 
39
-# include utils which allow function_check
39
+# include utils which allow function_check and drive mount
40 40
 UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
41 41
 for f in $UTILS_FILES
42 42
 do
@@ -426,5 +426,6 @@ backup_admin_readme
426 426
 backup_mariadb
427 427
 backup_extra_directories
428 428
 backup_unmount_drive $USB_DRIVE $USB_MOUNT
429
+echo $"Backup to USB drive is complete. You can now unplug it."
429 430
 
430 431
 exit 0

+ 110
- 113
src/freedombone-restore-local 파일 보기

@@ -38,6 +38,13 @@ RESTORE_APP='all'
38 38
 export TEXTDOMAIN=${PROJECT_NAME}-restore-local
39 39
 export TEXTDOMAINDIR="/usr/share/locale"
40 40
 
41
+# include utils which allow function_check and drive mount
42
+UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
43
+for f in $UTILS_FILES
44
+do
45
+  source $f
46
+done
47
+
41 48
 USB_DRIVE=/dev/sdb1
42 49
 USB_MOUNT=/mnt/usb
43 50
 
@@ -53,8 +60,11 @@ fi
53 60
 GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
54 61
 GVM_HOME=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GVM_HOME=' | head -n 1 | awk -F '=' '{print $2}')
55 62
 
56
-ADMIN_USERNAME=
63
+ADMIN_USERNAME=''
57 64
 ADMIN_NAME=
65
+if [ -f $COMPLETION_FILE ]; then
66
+	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
67
+fi
58 68
 
59 69
 # MariaDB password
60 70
 DATABASE_PASSWORD=$(cat /root/dbpass)
@@ -66,61 +76,8 @@ GIT_DOMAIN_NAME=
66 76
 WIKI_DOMAIN_NAME=
67 77
 FULLBLOG_DOMAIN_NAME=
68 78
 
69
-function mount_drive {
70
-	if [ $1 ]; then
71
-		USB_DRIVE=/dev/${1}1
72
-	fi
73
-
74
-	if [ $2 ]; then
75
-		RESTORE_APP=$2
76
-	fi
77
-
78
-	# get the admin user
79
-	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
80
-	if [ $3 ]; then
81
-		ADMIN_USERNAME=$3
82
-	fi
83
-	ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
84
-
85
-	# check that the backup destination is available
86
-	if [ ! -b $USB_DRIVE ]; then
87
-		echo $"Please attach a USB drive"
88
-		exit 1
89
-	fi
90
-
91
-	# unmount if already mounted
92
-	umount -f $USB_MOUNT
93
-	if [ ! -d $USB_MOUNT ]; then
94
-		mkdir $USB_MOUNT
95
-	fi
96
-	if [ -f /dev/mapper/encrypted_usb ]; then
97
-		rm -rf /dev/mapper/encrypted_usb
98
-	fi
99
-	cryptsetup luksClose encrypted_usb
100
-
101
-	# mount the encrypted backup drive
102
-	cryptsetup luksOpen $USB_DRIVE encrypted_usb
103
-	if [ "$?" = "0" ]; then
104
-		USB_DRIVE=/dev/mapper/encrypted_usb
105
-	fi
106
-	mount $USB_DRIVE $USB_MOUNT
107
-	if [ ! "$?" = "0" ]; then
108
-		echo $"There was a problem mounting the USB drive to $USB_MOUNT"
109
-		rm -rf $USB_MOUNT
110
-		exit 2
111
-	fi
112
-}
113
-
114
-function unmount_drive {
115
-	sync
116
-	umount $USB_MOUNT
117
-	if [ ! "$?" = "0" ]; then
118
-		echo $"Unable to unmount the drive. This means that the backup did not work"
119
-		rm -rf $USB_MOUNT
120
-		exit 9
121
-	fi
122
-	rm -rf $USB_MOUNT
123
-
79
+# after user files have been restored permissions may need to be set
80
+function set_user_permissions {
124 81
 	echo $"Setting permissions"
125 82
 	for d in /home/*/ ; do
126 83
 		USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
@@ -128,20 +85,13 @@ function unmount_drive {
128 85
 			chown -R $USERNAME:$USERNAME /home/$USERNAME
129 86
 		fi
130 87
 	done
131
-
132
-	if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
133
-		echo $"Unmount encrypted USB"
134
-		cryptsetup luksClose encrypted_usb
135
-	fi
136
-	if [ -f /dev/mapper/encrypted_usb ]; then
137
-		rm -rf /dev/mapper/encrypted_usb
138
-	fi
139 88
 }
140 89
 
141 90
 function check_backup_exists {
142 91
 	if [ ! -d $USB_MOUNT/backup ]; then
143 92
 		echo $"No backup directory found on the USB drive."
144
-		unmount_drive
93
+		set_user_permissions
94
+		backup_unmount_drive
145 95
 		exit 2
146 96
 	fi
147 97
 }
@@ -150,7 +100,8 @@ function check_admin_user {
150 100
 	echo $"Checking that admin user exists"
151 101
 	if [ ! -d /home/$ADMIN_USERNAME ]; then
152 102
 		echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username."
153
-		unmount_drive
103
+		set_user_permissions
104
+		backup_unmount_drive
154 105
 		exit 295
155 106
 	fi
156 107
 }
@@ -176,13 +127,15 @@ function restore_database {
176 127
 		if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
177 128
 			echo $"Unable to restore ${1} database"
178 129
 			rm -rf /root/temp${1}data
179
-			unmount_drive
130
+			set_user_permissions
131
+			backup_unmount_drive
180 132
 			exit 503
181 133
 		fi
182 134
 		mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
183 135
 		if [ ! "$?" = "0" ]; then
184 136
 			echo "$mysqlsuccess"
185
-			unmount_drive
137
+			set_user_permissions
138
+			backup_unmount_drive
186 139
 			exit 964
187 140
 		fi
188 141
 		shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
@@ -201,7 +154,8 @@ function restore_database {
201 154
 						rm -rf /etc/share/tt-rss
202 155
 						mv /root/temp${1}/etc/share/tt-rss /etc/share/
203 156
 						if [ ! "$?" = "0" ]; then
204
-							unmount_drive
157
+							set_user_permissions
158
+							backup_unmount_drive
205 159
 							exit 528
206 160
 						fi
207 161
 						if [ -d /etc/letsencrypt/live/${2} ]; then
@@ -222,7 +176,8 @@ function restore_database {
222 176
 					rm -rf /var/www/${2}/htdocs
223 177
 					mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
224 178
 					if [ ! "$?" = "0" ]; then
225
-						unmount_drive
179
+						set_user_permissions
180
+						backup_unmount_drive
226 181
 						exit 683
227 182
 					fi
228 183
 					if [ -d /etc/letsencrypt/live/${2} ]; then
@@ -278,7 +233,8 @@ function restore_configuration {
278 233
 
279 234
 		cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
280 235
 		if [ ! "$?" = "0" ]; then
281
-			unmount_drive
236
+			set_user_permissions
237
+			backup_unmount_drive
282 238
 			rm -rf /root/tempconfig
283 239
 			exit 5294
284 240
 		fi
@@ -289,7 +245,8 @@ function restore_configuration {
289 245
 
290 246
 		cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
291 247
 		if [ ! "$?" = "0" ]; then
292
-			unmount_drive
248
+			set_user_permissions
249
+			backup_unmount_drive
293 250
 			rm -rf /root/tempconfig
294 251
 			exit 6382
295 252
 		fi
@@ -297,7 +254,8 @@ function restore_configuration {
297 254
 		if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then
298 255
 			cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
299 256
 			if [ ! "$?" = "0" ]; then
300
-				unmount_drive
257
+				set_user_permissions
258
+				backup_unmount_drive
301 259
 				rm -rf /root/tempconfig
302 260
 				exit 62121
303 261
 			fi
@@ -316,7 +274,8 @@ function same_admin_user {
316 274
 	PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
317 275
 	if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then
318 276
 		echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME"
319
-		unmount_drive
277
+		set_user_permissions
278
+		backup_unmount_drive
320 279
 		exit 73265
321 280
 	fi
322 281
 }
@@ -345,7 +304,8 @@ function restore_mariadb {
345 304
 			fi
346 305
 			if [ ! "$?" = "0" ]; then
347 306
 				echo "$mysqlsuccess"
348
-				unmount_drive
307
+				set_user_permissions
308
+				backup_unmount_drive
349 309
 				exit 962
350 310
 			fi
351 311
 			echo $"Restarting database"
@@ -409,7 +369,8 @@ function restore_mutt_settings {
409 369
 				fi
410 370
 				if [ ! "$?" = "0" ]; then
411 371
 					rm -rf /root/tempmutt
412
-					unmount_drive
372
+					set_user_permissions
373
+					backup_unmount_drive
413 374
 					exit 276
414 375
 				fi
415 376
 				rm -rf /root/tempmutt
@@ -436,14 +397,16 @@ function restore_gpg {
436 397
 				cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/
437 398
 				if [ ! "$?" = "0" ]; then
438 399
 					rm -rf /root/tempgnupg
439
-					unmount_drive
400
+					set_user_permissions
401
+					backup_unmount_drive
440 402
 					exit 276
441 403
 				fi
442 404
 				rm -rf /root/tempgnupg
443 405
 				if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
444 406
 					cp -r /home/$USERNAME/.gnupg /root
445 407
 					if [ ! "$?" = "0" ]; then
446
-						unmount_drive
408
+						set_user_permissions
409
+						backup_unmount_drive
447 410
 						exit 283
448 411
 					fi
449 412
 				fi
@@ -470,7 +433,8 @@ function restore_procmail {
470 433
 				cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
471 434
 				if [ ! "$?" = "0" ]; then
472 435
 					rm -rf /root/tempprocmail
473
-					unmount_drive
436
+					set_user_permissions
437
+					backup_unmount_drive
474 438
 					exit 276
475 439
 				fi
476 440
 				rm -rf /root/tempprocmail
@@ -498,7 +462,8 @@ function restore_spamassassin {
498 462
 					cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/
499 463
 					if [ ! "$?" = "0" ]; then
500 464
 						rm -rf /root/tempspamassassin
501
-						unmount_drive
465
+						set_user_permissions
466
+						backup_unmount_drive
502 467
 						exit 276
503 468
 					fi
504 469
 					rm -rf /root/tempspamassassin
@@ -529,7 +494,8 @@ function restore_admin_readme {
529 494
 		cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
530 495
 		if [ ! "$?" = "0" ]; then
531 496
 			rm -rf /root/tempreadme
532
-			unmount_drive
497
+			set_user_permissions
498
+			backup_unmount_drive
533 499
 			exit 276
534 500
 		fi
535 501
 		rm -rf /root/tempreadme
@@ -548,7 +514,8 @@ function restore_ipfs {
548 514
 		cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
549 515
 		if [ ! "$?" = "0" ]; then
550 516
 			rm -rf /root/tempipfs
551
-			unmount_drive
517
+			set_user_permissions
518
+			backup_unmount_drive
552 519
 			exit 276
553 520
 		fi
554 521
 		rm -rf /root/tempipfs
@@ -573,7 +540,8 @@ function restore_user_ssh_keys {
573 540
 				cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/
574 541
 				if [ ! "$?" = "0" ]; then
575 542
 					rm -rf /root/tempssh
576
-					unmount_drive
543
+					set_user_permissions
544
+					backup_unmount_drive
577 545
 					exit 664
578 546
 				fi
579 547
 				rm -rf /root/tempssh
@@ -600,7 +568,8 @@ function restore_user_config {
600 568
 				cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/
601 569
 				if [ ! "$?" = "0" ]; then
602 570
 					rm -rf /root/tempconfig
603
-					unmount_drive
571
+					set_user_permissions
572
+					backup_unmount_drive
604 573
 					exit 664
605 574
 				fi
606 575
 				rm -rf /root/tempconfig
@@ -627,7 +596,8 @@ function restore_user_emacs {
627 596
 				cp -r /root/tempemacs/home/$USERNAME/.emacs.d /home/$USERNAME/
628 597
 				if [ ! "$?" = "0" ]; then
629 598
 					rm -rf /root/tempemacs
630
-					unmount_drive
599
+					set_user_permissions
600
+					backup_unmount_drive
631 601
 					exit 664
632 602
 				fi
633 603
 				cp -f /root/tempemacs/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
@@ -667,7 +637,8 @@ function restore_user_monkeysphere {
667 637
 				cp -r /root/tempmonkeysphere/home/$USERNAME/.monkeysphere /home/$USERNAME/
668 638
 				if [ ! "$?" = "0" ]; then
669 639
 					rm -rf /root/tempmonkeysphere
670
-					unmount_drive
640
+					set_user_permissions
641
+					backup_unmount_drive
671 642
 					exit 664
672 643
 				fi
673 644
 				rm -rf /root/tempmonkeysphere
@@ -704,7 +675,8 @@ function restore_user_fin {
704 675
 				cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/
705 676
 				if [ ! "$?" = "0" ]; then
706 677
 					rm -rf /root/tempfin
707
-					unmount_drive
678
+					set_user_permissions
679
+					backup_unmount_drive
708 680
 					exit 664
709 681
 				fi
710 682
 				rm -rf /root/tempfin
@@ -731,7 +703,8 @@ function restore_user_local {
731 703
 				cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/
732 704
 				if [ ! "$?" = "0" ]; then
733 705
 					rm -rf /root/templocal
734
-					unmount_drive
706
+					set_user_permissions
707
+					backup_unmount_drive
735 708
 					exit 664
736 709
 				fi
737 710
 				rm -rf /root/templocal
@@ -752,7 +725,8 @@ function restore_certs {
752 725
 		restore_directory_from_usb /root/tempssl ssl
753 726
 		cp -r /root/tempssl/etc/ssl/* /etc/ssl
754 727
 		if [ ! "$?" = "0" ]; then
755
-			unmount_drive
728
+			set_user_permissions
729
+			backup_unmount_drive
756 730
 			exit 276
757 731
 		fi
758 732
 		rm -rf /root/tempssl
@@ -804,7 +778,8 @@ function restore_personal_settings {
804 778
 					fi
805 779
 					mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME
806 780
 					if [ ! "$?" = "0" ]; then
807
-						unmount_drive
781
+						set_user_permissions
782
+						backup_unmount_drive
808 783
 						exit 184
809 784
 					fi
810 785
 					rm -rf /root/temppersonal
@@ -825,7 +800,8 @@ function restore_mailing_list {
825 800
 		restore_directory_from_usb /root/tempmailinglist mailinglist
826 801
 		cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj
827 802
 		if [ ! "$?" = "0" ]; then
828
-			unmount_drive
803
+			set_user_permissions
804
+			backup_unmount_drive
829 805
 			exit 526
830 806
 		fi
831 807
 		rm -rf /root/tempmailinglist
@@ -843,7 +819,8 @@ function restore_xmpp {
843 819
 		restore_directory_from_usb /root/tempxmpp xmpp
844 820
 		cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody
845 821
 		if [ ! "$?" = "0" ]; then
846
-			unmount_drive
822
+			set_user_permissions
823
+			backup_unmount_drive
847 824
 			exit 725
848 825
 		fi
849 826
 		rm -rf /root/tempxmpp
@@ -929,7 +906,8 @@ function restore_syncthing {
929 906
 		restore_directory_from_usb /root/tempsyncthingconfig syncthingconfig
930 907
 		cp -r /root/tempsyncthingconfig/* /
931 908
 		if [ ! "$?" = "0" ]; then
932
-			unmount_drive
909
+			set_user_permissions
910
+			backup_unmount_drive
933 911
 			systemctl start syncthing
934 912
 			systemctl start cron
935 913
 			exit 6833
@@ -942,7 +920,8 @@ function restore_syncthing {
942 920
 		restore_directory_from_usb /root/tempsyncthingshared syncthingshared
943 921
 		cp -r /root/tempsyncthingshared/* /
944 922
 		if [ ! "$?" = "0" ]; then
945
-			unmount_drive
923
+			set_user_permissions
924
+			backup_unmount_drive
946 925
 			systemctl start syncthing
947 926
 			systemctl start cron
948 927
 			exit 37904
@@ -962,7 +941,8 @@ function restore_syncthing {
962 941
 				cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/
963 942
 				if [ ! "$?" = "0" ]; then
964 943
 					rm -rf /root/tempsyncthing
965
-					unmount_drive
944
+					set_user_permissions
945
+					backup_unmount_drive
966 946
 					systemctl start syncthing
967 947
 					systemctl start cron
968 948
 					exit 68438
@@ -1002,7 +982,8 @@ function restore_mediagoblin {
1002 982
 		restore_directory_from_usb /root/tempmediagoblin mediagoblin
1003 983
 		cp -r /root/tempmediagoblin/* /
1004 984
 		if [ ! "$?" = "0" ]; then
1005
-			unmount_drive
985
+			set_user_permissions
986
+			backup_unmount_drive
1006 987
 			exit 67843
1007 988
 		fi
1008 989
 		rm -rf /root/tempmediagoblin
@@ -1033,14 +1014,16 @@ function restore_gogs {
1033 1014
 			fi
1034 1015
 			cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
1035 1016
 			if [ ! "$?" = "0" ]; then
1036
-				unmount_drive
1017
+				set_user_permissions
1018
+				backup_unmount_drive
1037 1019
 				exit 981
1038 1020
 			fi
1039 1021
 			echo $"Restoring Gogs repos"
1040 1022
 			restore_directory_from_usb /root/tempgogsrepos gogsrepos
1041 1023
 			cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
1042 1024
 			if [ ! "$?" = "0" ]; then
1043
-				unmount_drive
1025
+				set_user_permissions
1026
+				backup_unmount_drive
1044 1027
 				exit 67574
1045 1028
 			fi
1046 1029
 			echo $"Restoring Gogs authorized_keys"
@@ -1050,7 +1033,8 @@ function restore_gogs {
1050 1033
 			fi
1051 1034
 			cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
1052 1035
 			if [ ! "$?" = "0" ]; then
1053
-				unmount_drive
1036
+				set_user_permissions
1037
+				backup_unmount_drive
1054 1038
 				exit 8463
1055 1039
 			fi
1056 1040
 			rm -rf /root/tempgogs
@@ -1072,13 +1056,15 @@ function restore_wiki {
1072 1056
 		restore_directory_from_usb /root/tempwiki wiki
1073 1057
 		cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
1074 1058
 		if [ ! "$?" = "0" ]; then
1075
-			unmount_drive
1059
+			set_user_permissions
1060
+			backup_unmount_drive
1076 1061
 			exit 868
1077 1062
 		fi
1078 1063
 		restore_directory_from_usb /root/tempwiki2 wiki2
1079 1064
 		cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
1080 1065
 		if [ ! "$?" = "0" ]; then
1081
-			unmount_drive
1066
+			set_user_permissions
1067
+			backup_unmount_drive
1082 1068
 			exit 869
1083 1069
 		fi
1084 1070
 		rm -rf /root/tempwiki
@@ -1107,13 +1093,15 @@ function restore_blog {
1107 1093
 		rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
1108 1094
 		cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
1109 1095
 		if [ ! "$?" = "0" ]; then
1110
-			unmount_drive
1096
+			set_user_permissions
1097
+			backup_unmount_drive
1111 1098
 			exit 593
1112 1099
 		fi
1113 1100
 		rm -rf /root/tempblog
1114 1101
 		if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
1115 1102
 			echo $"No content directory found after restoring blog"
1116
-			unmount_drive
1103
+			set_user_permissions
1104
+			backup_unmount_drive
1117 1105
 			exit 287
1118 1106
 		fi
1119 1107
 		chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
@@ -1148,7 +1136,8 @@ function restore_cjdns {
1148 1136
 		rm -rf /etc/cjdns
1149 1137
 		cp -r /root/tempcjdns/etc/cjdns /etc/
1150 1138
 		if [ ! "$?" = "0" ]; then
1151
-			unmount_drive
1139
+			set_user_permissions
1140
+			backup_unmount_drive
1152 1141
 			exit 8472
1153 1142
 		fi
1154 1143
 		rm -rf /root/tempcjdns
@@ -1175,7 +1164,8 @@ function restore_email {
1175 1164
 				fi
1176 1165
 				tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
1177 1166
 				if [ ! "$?" = "0" ]; then
1178
-					unmount_drive
1167
+					set_user_permissions
1168
+					backup_unmount_drive
1179 1169
 					exit 927
1180 1170
 				fi
1181 1171
 				rm -rf /root/tempmail
@@ -1197,7 +1187,8 @@ function restore_dlna {
1197 1187
 			cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/
1198 1188
 			if [ ! "$?" = "0" ]; then
1199 1189
 				rm -rf /root/tempdlna
1200
-				unmount_drive
1190
+				set_user_permissions
1191
+				backup_unmount_drive
1201 1192
 				exit 982
1202 1193
 			fi
1203 1194
 			rm -rf /root/tempdlna
@@ -1217,19 +1208,22 @@ function restore_voip {
1217 1208
 		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
1218 1209
 		if [ ! "$?" = "0" ]; then
1219 1210
 			rm -rf /root/tempvoip
1220
-			unmount_drive
1211
+			set_user_permissions
1212
+			backup_unmount_drive
1221 1213
 			exit 3679
1222 1214
 		fi
1223 1215
 		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
1224 1216
 		if [ ! "$?" = "0" ]; then
1225 1217
 			rm -rf /root/tempvoip
1226
-			unmount_drive
1218
+			set_user_permissions
1219
+			backup_unmount_drive
1227 1220
 			exit 3679
1228 1221
 		fi
1229 1222
 		cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
1230 1223
 		if [ ! "$?" = "0" ]; then
1231 1224
 			rm -rf /root/tempvoip
1232
-			unmount_drive
1225
+			set_user_permissions
1226
+			backup_unmount_drive
1233 1227
 			exit 276
1234 1228
 		fi
1235 1229
 		rm -rf /root/tempvoip
@@ -1251,14 +1245,16 @@ function restore_tox {
1251 1245
 		echo $"Restoring Tox node settings"
1252 1246
 		restore_directory_from_usb / tox
1253 1247
 		if [ ! "$?" = "0" ]; then
1254
-			unmount_drive
1248
+			set_user_permissions
1249
+			backup_unmount_drive
1255 1250
 			exit 6393
1256 1251
 		fi
1257 1252
 		cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
1258 1253
 		systemctl restart tox-bootstrapd.service
1259 1254
 		if [ ! "$?" = "0" ]; then
1260 1255
 			systemctl status tox-bootstrapd.service
1261
-			unmount_drive
1256
+			set_user_permissions
1257
+			backup_unmount_drive
1262 1258
 			exit 59369
1263 1259
 		fi
1264 1260
 	fi
@@ -1274,7 +1270,7 @@ function get_restore_app {
1274 1270
 }
1275 1271
 
1276 1272
 get_restore_app ${2}
1277
-mount_drive ${1} ${2}
1273
+backup_mount_drive ${1} ${ADMIN_USERNAME} ${2}
1278 1274
 check_backup_exists
1279 1275
 check_admin_user
1280 1276
 copy_gpg_keys
@@ -1313,7 +1309,8 @@ restore_email
1313 1309
 restore_dlna
1314 1310
 restore_voip
1315 1311
 restore_tox
1316
-unmount_drive
1312
+set_user_permissions
1313
+backup_unmount_drive
1317 1314
 
1318 1315
 echo $"Restore from USB drive is complete. You can now unplug it."
1319 1316
 

+ 5
- 2
src/freedombone-utils-backup 파일 보기

@@ -128,6 +128,10 @@ function backup_mount_drive {
128 128
 	fi
129 129
 	ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
130 130
 
131
+	if [ $3 ]; then
132
+		RESTORE_APP=$3
133
+	fi
134
+	
131 135
 	# check that the backup destination is available
132 136
 	if [ ! -b $USB_DRIVE ]; then
133 137
 		echo $"Please attach a USB drive"
@@ -167,7 +171,7 @@ function backup_unmount_drive {
167 171
 	sync
168 172
 	umount $USB_MOUNT
169 173
 	if [ ! "$?" = "0" ]; then
170
-		echo $"Unable to unmount the drive. This means that the backup did not work"
174
+		echo $"Unable to unmount the drive."
171 175
 		rm -rf $USB_MOUNT
172 176
 		exit 9
173 177
 	fi
@@ -179,7 +183,6 @@ function backup_unmount_drive {
179 183
 	if [ -f /dev/mapper/encrypted_usb ]; then
180 184
 		rm -rf /dev/mapper/encrypted_usb
181 185
 	fi
182
-	echo $"Backup to USB drive is complete. You can now unplug it."
183 186
 }
184 187
 
185 188
 function backup_database_local {