Преглед на файлове

Improved handling of Go version

Bob Mottram преди 8 години
родител
ревизия
81ed974d4b
No account linked to committer's email
променени са 5 файла, в които са добавени 2350 реда и са изтрити 2286 реда
  1. 42
    36
      src/freedombone
  2. 243
    224
      src/freedombone-backup-local
  3. 513
    500
      src/freedombone-backup-remote
  4. 698
    685
      src/freedombone-restore-local
  5. 854
    841
      src/freedombone-restore-remote

+ 42
- 36
src/freedombone Целия файл

@@ -89,6 +89,8 @@ SSH_PORT=2222
89 89
 IRC_PORT=6697
90 90
 IRC_ONION_PORT=6697
91 91
 
92
+GO_VERSION=1.5
93
+
92 94
 # password used for accessing your repo mirrors
93 95
 MY_MIRRORS_PASSWORD=
94 96
 # friend's repo mirrors
@@ -2635,6 +2637,16 @@ function create_mirrors {
2635 2637
     echo 'create_mirrors' >> $COMPLETION_FILE
2636 2638
 }
2637 2639
 
2640
+function select_go_version {
2641
+	if [ ! -d $HOME/.gvm/scripts ]; then
2642
+		echo $'GVM was not installed'
2643
+		exit 629532
2644
+	fi
2645
+    cd $HOME/.gvm/scripts
2646
+    gvm use go${GO_VERSION} --default
2647
+    systemctl set-environment GOPATH=$GOPATH	
2648
+}
2649
+
2638 2650
 function mesh_cjdns_tools {
2639 2651
     if grep -Fxq "mesh_cjdns_tools" $COMPLETION_FILE; then
2640 2652
         return
@@ -2646,31 +2658,30 @@ function mesh_cjdns_tools {
2646 2658
         mesh_cjdns
2647 2659
     fi
2648 2660
 
2661
+	select_go_version
2662
+
2649 2663
     apt-get -y install golang mercurial
2650 2664
     if [ ! -f ~/.bashrc ]; then
2651 2665
         touch ~/.bashrc
2652 2666
     fi
2653
-
2654
-    export GOPATH=/home/git/go
2667
+	
2655 2668
     if [ ! -d /home/git ]; then
2656 2669
         # add a gogs user account
2657 2670
         adduser --disabled-login --gecos 'Gogs' git
2658 2671
 
2659 2672
         # install Go
2660
-        export GOPATH=/home/git/go
2661
-        if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then
2662
-            echo 'export GOPATH=/home/git/go' >> ~/.bashrc
2673
+        if ! grep -q "export GOPATH=" ~/.bashrc; then
2674
+            echo "export GOPATH=$GOPATH" >> ~/.bashrc
2663 2675
         fi
2664
-        systemctl set-environment GOPATH=/home/git/go
2665
-        if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then
2666
-            echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc
2676
+        systemctl set-environment GOPATH=$GOPATH
2677
+        if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
2678
+            echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
2667 2679
         fi
2668 2680
         if [ ! -d $GOPATH ]; then
2669 2681
             mkdir -p $GOPATH
2670 2682
         fi
2671 2683
     fi
2672 2684
 
2673
-    export GOPATH=$GOPATH
2674 2685
     if ! grep -q "export GOPATH=" ~/.bashrc; then
2675 2686
         echo "export GOPATH=$GOPATH" >> ~/.bashrc
2676 2687
     fi
@@ -6309,12 +6320,12 @@ function upgrade_golang {
6309 6320
     gvm install go1.4
6310 6321
     gvm use go1.4
6311 6322
     export GOROOT_BOOTSTRAP=$GOROOT
6312
-    gvm install go1.5
6323
+    gvm install go${GO_VERSION}
6313 6324
     if [ ! "$?" = "0" ]; then
6314 6325
         echo $'Unable to upgrade golang'
6315 6326
         exit 529252
6316 6327
     fi
6317
-    gvm use go1.5 --default
6328
+    gvm use go${GO_VERSION} --default
6318 6329
 
6319 6330
     if ! grep -q "gvm commit" $COMPLETION_FILE; then
6320 6331
         echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE
@@ -6333,8 +6344,7 @@ function install_gogs {
6333 6344
         return
6334 6345
     fi
6335 6346
 
6336
-    export GOPATH=/home/git/go
6337
-    systemctl set-environment GOPATH=/home/git/go
6347
+    select_go_version
6338 6348
 
6339 6349
     # update to the next commit
6340 6350
     set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO
@@ -6354,13 +6364,12 @@ function install_gogs {
6354 6364
 
6355 6365
     # install Go
6356 6366
     apt-get -y install golang libpam0g-dev
6357
-    export GOPATH=/home/git/go
6358
-    if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then
6359
-        echo 'export GOPATH=/home/git/go' >> ~/.bashrc
6367
+    if ! grep -q "export GOPATH=" ~/.bashrc; then
6368
+        echo "export GOPATH=$GOPATH" >> ~/.bashrc
6360 6369
     fi
6361
-    systemctl set-environment GOPATH=/home/git/go
6362
-    if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then
6363
-        echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc
6370
+    systemctl set-environment GOPATH=$GOPATH
6371
+    if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
6372
+        echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
6364 6373
     fi
6365 6374
     if [ ! -d $GOPATH ]; then
6366 6375
         mkdir -p $GOPATH
@@ -6430,7 +6439,7 @@ function install_gogs {
6430 6439
         echo $'Check "Enable Register Confirmation"' >> /home/$MY_USERNAME/README
6431 6440
         echo $'Check "Enable Mail Notification"' >> /home/$MY_USERNAME/README
6432 6441
         echo '' >> /home/$MY_USERNAME/README
6433
-        echo $'After the initial install edit /home/git/go/src/github.com/gogits/gogs/custom/conf/app.ini' >> /home/$MY_USERNAME/README
6442
+        echo $"After the initial install edit ${GOPATH}/src/github.com/gogits/gogs/custom/conf/app.ini" >> /home/$MY_USERNAME/README
6434 6443
         echo $'and within the [server] section set:' >> /home/$MY_USERNAME/README
6435 6444
         echo "  DOMAIN = $GIT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
6436 6445
         echo "  ROOT_URL = http://$GIT_DOMAIN_NAME/" >> /home/$MY_USERNAME/README
@@ -6456,14 +6465,14 @@ function install_gogs {
6456 6465
 
6457 6466
     create_database gogs "$GOGS_ADMIN_PASSWORD"
6458 6467
 
6459
-    chmod 600 /home/git/go/src/github.com/gogits/gogs/custom/conf/app.ini
6468
+    chmod 600 $GOPATH/src/github.com/gogits/gogs/custom/conf/app.ini
6460 6469
 
6461 6470
     chown -R git:git /home/git
6462 6471
     cp $GOPATH/src/github.com/gogits/gogs/scripts/systemd/gogs.service /etc/systemd/system
6463 6472
     sed -i 's|#After=mysqld.service|After=mysqld.service|g' /etc/systemd/system/gogs.service
6464 6473
     sed -i "s|WorkingDirectory=.*|WorkingDirectory=$GOPATH/src/github.com/gogits/gogs|g" /etc/systemd/system/gogs.service
6465 6474
     sed -i "s|ExecStart=.*|ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web|g" /etc/systemd/system/gogs.service
6466
-    sed -i "s|Environment.*|Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=/home/git/go\"|g" /etc/systemd/system/gogs.service
6475
+    sed -i "s|Environment.*|Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=$GOPATH\"|g" /etc/systemd/system/gogs.service
6467 6476
     systemctl enable gogs
6468 6477
     systemctl daemon-reload
6469 6478
     systemctl restart gogs
@@ -10079,11 +10088,10 @@ function install_ipfs {
10079 10088
         return
10080 10089
     fi
10081 10090
 
10082
-    export GOPATH=/home/git/go
10083
-    systemctl set-environment GOPATH=/home/git/go
10091
+    select_go_version
10084 10092
 
10085 10093
     # update to the next commit
10086
-    set_repo_commit /home/git/go/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
10094
+    set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
10087 10095
 
10088 10096
     if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
10089 10097
         return
@@ -10096,21 +10104,19 @@ function install_ipfs {
10096 10104
         adduser --disabled-login --gecos 'Gogs' git
10097 10105
 
10098 10106
         # install Go
10099
-        export GOPATH=/home/git/go
10100
-        if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then
10101
-            echo 'export GOPATH=/home/git/go' >> ~/.bashrc
10107
+        if ! grep -q "export GOPATH=" ~/.bashrc; then
10108
+            echo "export GOPATH=$GOPATH" >> ~/.bashrc
10102 10109
         fi
10103
-        systemctl set-environment GOPATH=/home/git/go
10104
-        if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then
10105
-            echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc
10110
+        systemctl set-environment GOPATH=$GOPATH
10111
+        if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
10112
+            echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
10106 10113
         fi
10107
-        export GOPATH=/home/git/go
10108 10114
         if [ ! -d $GOPATH ]; then
10109 10115
             mkdir -p $GOPATH
10110 10116
         fi
10111 10117
     fi
10112 10118
 
10113
-    IPFS_PATH=/home/git/go/bin
10119
+    IPFS_PATH=$GOPATH/bin
10114 10120
     export PATH="$GOPATH/bin:$PATH:"
10115 10121
     if ! grep -q 'GOPATH/bin' ~/.bashrc; then
10116 10122
         echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
@@ -10118,7 +10124,7 @@ function install_ipfs {
10118 10124
 
10119 10125
     # set gopath for the user
10120 10126
     if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
10121
-        echo 'export GOPATH=/home/git/go' >> /home/$MY_USERNAME/.bashrc
10127
+        echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
10122 10128
         echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
10123 10129
         chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
10124 10130
     fi
@@ -10129,7 +10135,7 @@ function install_ipfs {
10129 10135
         exit 8242
10130 10136
     fi
10131 10137
 
10132
-    cd /home/git/go/src/$IPFS_GO_REPO2
10138
+    cd $GOPATH/src/$IPFS_GO_REPO2
10133 10139
     git checkout $IPFS_COMMIT -b $IPFS_COMMIT
10134 10140
     if ! grep -q "ipfs commit" $COMPLETION_FILE; then
10135 10141
         echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
@@ -10171,7 +10177,7 @@ function install_ipfs {
10171 10177
     echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
10172 10178
     echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
10173 10179
     echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
10174
-    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=/home/git/go\"" >> /etc/systemd/system/ipfs.service
10180
+    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\"" >> /etc/systemd/system/ipfs.service
10175 10181
     echo '' >> /etc/systemd/system/ipfs.service
10176 10182
     echo '[Install]' >> /etc/systemd/system/ipfs.service
10177 10183
     echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service

+ 243
- 224
src/freedombone-backup-local Целия файл

@@ -42,9 +42,16 @@ USB_MOUNT=/mnt/usb
42 42
 # get default USB from config file
43 43
 CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
44 44
 if [ -f $CONFIG_FILE ]; then
45
-    if grep -q "USB_DRIVE=" $CONFIG_FILE; then
46
-        USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
47
-    fi
45
+	if grep -q "USB_DRIVE=" $CONFIG_FILE; then
46
+		USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
47
+	fi
48
+fi
49
+
50
+# get the version of Go being used
51
+if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
52
+	GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
53
+else
54
+	GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
48 55
 fi
49 56
 
50 57
 ADMIN_USERNAME=
@@ -56,270 +63,270 @@ SUSPENDED_SITE=
56 63
 
57 64
 DATABASE_PASSWORD=''
58 65
 if [ -f /root/dbpass ]; then
59
-    DATABASE_PASSWORD=$(cat /root/dbpass)
66
+	DATABASE_PASSWORD=$(cat /root/dbpass)
60 67
 fi
61 68
 
62 69
 function suspend_site {
63
-    # suspends a given website
64
-    if [[ $ENABLE_VERIFICATION != "yes" ]]; then
65
-        return
66
-    fi
67
-    SUSPENDED_SITE="$1"
68
-    nginx_dissite $SUSPENDED_SITE
69
-    service nginx reload
70
+	# suspends a given website
71
+	if [[ $ENABLE_VERIFICATION != "yes" ]]; then
72
+		return
73
+	fi
74
+	SUSPENDED_SITE="$1"
75
+	nginx_dissite $SUSPENDED_SITE
76
+	service nginx reload
70 77
 }
71 78
 
72 79
 function restart_site {
73
-    # restarts a given website
74
-    if [ ! $SUSPENDED_SITE ]; then
75
-        return
76
-    fi
77
-    nginx_ensite $SUSPENDED_SITE
78
-    service nginx reload
79
-    SUSPENDED_SITE=
80
+	# restarts a given website
81
+	if [ ! $SUSPENDED_SITE ]; then
82
+		return
83
+	fi
84
+	nginx_ensite $SUSPENDED_SITE
85
+	service nginx reload
86
+	SUSPENDED_SITE=
80 87
 }
81 88
 
82 89
 function update_domains {
83
-    RSS_READER_DOMAIN_NAME='ttrss'
84
-    if grep -q "RSS reader domain" $COMPLETION_FILE; then
85
-        RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
86
-    fi
87
-    GIT_DOMAIN_NAME='gogs'
88
-    if grep -q "Gogs domain" $COMPLETION_FILE; then
89
-        GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
90
-    fi
91
-    MICROBLOG_DOMAIN_NAME='microblog'
92
-    if grep -q "GNU Social domain" $COMPLETION_FILE; then
93
-        MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
94
-    fi
95
-    HUBZILLA_DOMAIN_NAME='hubzilla'
96
-    if grep -q "Hubzilla domain" $COMPLETION_FILE; then
97
-        HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
98
-    fi
99
-    FULLBLOG_DOMAIN_NAME='blog'
100
-    if grep -q "Blog domain" $COMPLETION_FILE; then
101
-        FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
102
-    fi
103
-    MEDIAGOBLIN_DOMAIN_NAME='mediagoblin'
104
-    if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
105
-        MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
106
-    fi
90
+	RSS_READER_DOMAIN_NAME='ttrss'
91
+	if grep -q "RSS reader domain" $COMPLETION_FILE; then
92
+		RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
93
+	fi
94
+	GIT_DOMAIN_NAME='gogs'
95
+	if grep -q "Gogs domain" $COMPLETION_FILE; then
96
+		GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
97
+	fi
98
+	MICROBLOG_DOMAIN_NAME='microblog'
99
+	if grep -q "GNU Social domain" $COMPLETION_FILE; then
100
+		MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
101
+	fi
102
+	HUBZILLA_DOMAIN_NAME='hubzilla'
103
+	if grep -q "Hubzilla domain" $COMPLETION_FILE; then
104
+		HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
105
+	fi
106
+	FULLBLOG_DOMAIN_NAME='blog'
107
+	if grep -q "Blog domain" $COMPLETION_FILE; then
108
+		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
109
+	fi
110
+	MEDIAGOBLIN_DOMAIN_NAME='mediagoblin'
111
+	if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
112
+		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
113
+	fi
107 114
 }
108 115
 
109 116
 function mount_drive {
110
-    if [ $1 ]; then
111
-        USB_DRIVE=/dev/${1}1
112
-    fi
113
-
114
-    # get the admin user
115
-    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
116
-    if [ $2 ]; then
117
-        ADMIN_USERNAME=$2
118
-    fi
119
-    ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
120
-
121
-    # check that the backup destination is available
122
-    if [ ! -b $USB_DRIVE ]; then
123
-        echo $"Please attach a USB drive"
124
-        exit 1
125
-    fi
126
-
127
-    # unmount if already mounted
128
-    umount -f $USB_MOUNT
129
-    if [ ! -d $USB_MOUNT ]; then
130
-        mkdir $USB_MOUNT
131
-    fi
132
-    if [ -f /dev/mapper/encrypted_usb ]; then
133
-        rm -rf /dev/mapper/encrypted_usb
134
-    fi
135
-    cryptsetup luksClose encrypted_usb
136
-
137
-    # mount the encrypted backup drive
138
-    cryptsetup luksOpen $USB_DRIVE encrypted_usb
139
-    if [ "$?" = "0" ]; then
140
-        USB_DRIVE=/dev/mapper/encrypted_usb
141
-    fi
142
-    mount $USB_DRIVE $USB_MOUNT
143
-    if [ ! "$?" = "0" ]; then
144
-        echo $"There was a problem mounting the USB drive to $USB_MOUNT"
145
-        rm -rf $USB_MOUNT
146
-        exit 2
147
-    fi
117
+	if [ $1 ]; then
118
+		USB_DRIVE=/dev/${1}1
119
+	fi
120
+
121
+	# get the admin user
122
+	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
123
+	if [ $2 ]; then
124
+		ADMIN_USERNAME=$2
125
+	fi
126
+	ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
127
+
128
+	# check that the backup destination is available
129
+	if [ ! -b $USB_DRIVE ]; then
130
+		echo $"Please attach a USB drive"
131
+		exit 1
132
+	fi
133
+
134
+	# unmount if already mounted
135
+	umount -f $USB_MOUNT
136
+	if [ ! -d $USB_MOUNT ]; then
137
+		mkdir $USB_MOUNT
138
+	fi
139
+	if [ -f /dev/mapper/encrypted_usb ]; then
140
+		rm -rf /dev/mapper/encrypted_usb
141
+	fi
142
+	cryptsetup luksClose encrypted_usb
143
+
144
+	# mount the encrypted backup drive
145
+	cryptsetup luksOpen $USB_DRIVE encrypted_usb
146
+	if [ "$?" = "0" ]; then
147
+		USB_DRIVE=/dev/mapper/encrypted_usb
148
+	fi
149
+	mount $USB_DRIVE $USB_MOUNT
150
+	if [ ! "$?" = "0" ]; then
151
+		echo $"There was a problem mounting the USB drive to $USB_MOUNT"
152
+		rm -rf $USB_MOUNT
153
+		exit 2
154
+	fi
148 155
 }
149 156
 
150 157
 function unmount_drive {
151
-    sync
152
-    umount $USB_MOUNT
153
-    if [ ! "$?" = "0" ]; then
154
-        echo $"Unable to unmount the drive. This means that the backup did not work"
155
-        rm -rf $USB_MOUNT
156
-        exit 9
157
-    fi
158
-    rm -rf $USB_MOUNT
159
-    if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
160
-        echo $"Unmount encrypted USB"
161
-        cryptsetup luksClose encrypted_usb
162
-    fi
163
-    if [ -f /dev/mapper/encrypted_usb ]; then
164
-        rm -rf /dev/mapper/encrypted_usb
165
-    fi
166
-    echo $"Backup to USB drive is complete. You can now unplug it."
158
+	sync
159
+	umount $USB_MOUNT
160
+	if [ ! "$?" = "0" ]; then
161
+		echo $"Unable to unmount the drive. This means that the backup did not work"
162
+		rm -rf $USB_MOUNT
163
+		exit 9
164
+	fi
165
+	rm -rf $USB_MOUNT
166
+	if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
167
+		echo $"Unmount encrypted USB"
168
+		cryptsetup luksClose encrypted_usb
169
+	fi
170
+	if [ -f /dev/mapper/encrypted_usb ]; then
171
+		rm -rf /dev/mapper/encrypted_usb
172
+	fi
173
+	echo $"Backup to USB drive is complete. You can now unplug it."
167 174
 }
168 175
 
169 176
 function backup_database {
170
-    if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
171
-        echo $"No MariaDB password was given"
172
-        restart_site
173
-        exit 10
174
-    fi
175
-    if [ ! -d $USB_MOUNT/backup/${1} ]; then
176
-        mkdir -p $USB_MOUNT/backup/${1}
177
-    fi
178
-    if [ ! -d $USB_MOUNT/backup/${1}data ]; then
179
-        mkdir -p $USB_MOUNT/backup/${1}data
180
-    fi
181
-    if [ ! -d /root/temp${1}data ]; then
182
-        mkdir -p /root/temp${1}data
183
-    fi
184
-    echo $"Obtaining ${1} database backup"
185
-    mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
186
-    if [ ! -s /root/temp${1}data/${1}.sql ]; then
187
-        echo $"${1} database could not be saved"
188
-        shred -zu /root/temp${1}data/*
189
-        rm -rf /root/temp${1}data
190
-        umount $USB_MOUNT
191
-        rm -rf $USB_MOUNT
192
-        restart_site
193
-        exit 5
194
-    fi
177
+	if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
178
+		echo $"No MariaDB password was given"
179
+		restart_site
180
+		exit 10
181
+	fi
182
+	if [ ! -d $USB_MOUNT/backup/${1} ]; then
183
+		mkdir -p $USB_MOUNT/backup/${1}
184
+	fi
185
+	if [ ! -d $USB_MOUNT/backup/${1}data ]; then
186
+		mkdir -p $USB_MOUNT/backup/${1}data
187
+	fi
188
+	if [ ! -d /root/temp${1}data ]; then
189
+		mkdir -p /root/temp${1}data
190
+	fi
191
+	echo $"Obtaining ${1} database backup"
192
+	mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
193
+	if [ ! -s /root/temp${1}data/${1}.sql ]; then
194
+		echo $"${1} database could not be saved"
195
+		shred -zu /root/temp${1}data/*
196
+		rm -rf /root/temp${1}data
197
+		umount $USB_MOUNT
198
+		rm -rf $USB_MOUNT
199
+		restart_site
200
+		exit 5
201
+	fi
195 202
 }
196 203
 
197 204
 function backup_directory_to_usb {
198
-    if [ ! -d ${1} ]; then
199
-        echo $"WARNING: directory does not exist: ${1}"
200
-    else
201
-        BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
202
-        if [ ! "$?" = "0" ]; then
203
-            echo $"Backup key could not be found"
204
-            restart_site
205
-            exit 6
206
-        fi
207
-        MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
208
-        if [ ! -d $USB_MOUNT/backup/${2} ]; then
209
-            mkdir -p $USB_MOUNT/backup/${2}
210
-        fi
211
-        obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
212
-        obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
213
-        if [[ $ENABLE_VERIFICATION == "yes" ]]; then
214
-            obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
215
-            if [ ! "$?" = "0" ]; then
216
-                umount $USB_MOUNT
217
-                rm -rf $USB_MOUNT
218
-                if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
219
-                    shred -zu ${1}/*
220
-                    rm -rf ${1}
221
-                fi
222
-                restart_site
223
-                exit 71
224
-            fi
225
-        fi
226
-        obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
227
-        if [ ! "$?" = "0" ]; then
228
-            umount $USB_MOUNT
229
-            rm -rf $USB_MOUNT
230
-            if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
231
-                shred -zu ${1}/*
232
-                rm -rf ${1}
233
-            fi
234
-            restart_site
235
-            exit 7
236
-        fi
237
-        if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
238
-            shred -zu ${1}/*
239
-            rm -rf ${1}
240
-        fi
241
-    fi
205
+	if [ ! -d ${1} ]; then
206
+		echo $"WARNING: directory does not exist: ${1}"
207
+	else
208
+		BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
209
+		if [ ! "$?" = "0" ]; then
210
+			echo $"Backup key could not be found"
211
+			restart_site
212
+			exit 6
213
+		fi
214
+		MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
215
+		if [ ! -d $USB_MOUNT/backup/${2} ]; then
216
+			mkdir -p $USB_MOUNT/backup/${2}
217
+		fi
218
+		obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
219
+		obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
220
+		if [[ $ENABLE_VERIFICATION == "yes" ]]; then
221
+			obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
222
+			if [ ! "$?" = "0" ]; then
223
+				umount $USB_MOUNT
224
+				rm -rf $USB_MOUNT
225
+				if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
226
+					shred -zu ${1}/*
227
+					rm -rf ${1}
228
+				fi
229
+				restart_site
230
+				exit 71
231
+			fi
232
+		fi
233
+		obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
234
+		if [ ! "$?" = "0" ]; then
235
+			umount $USB_MOUNT
236
+			rm -rf $USB_MOUNT
237
+			if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
238
+				shred -zu ${1}/*
239
+				rm -rf ${1}
240
+			fi
241
+			restart_site
242
+			exit 7
243
+		fi
244
+		if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
245
+			shred -zu ${1}/*
246
+			rm -rf ${1}
247
+		fi
248
+	fi
242 249
 }
243 250
 
244 251
 function make_backup_directory {
245
-    # make a backup directory on the drive
246
-    if [ ! -d $USB_MOUNT/backup ]; then
247
-        mkdir $USB_MOUNT/backup
248
-    fi
249
-    if [ ! -d $USB_MOUNT/backup ]; then
250
-        echo $"There was a problem making the directory $USB_MOUNT/backup."
251
-        umount $USB_MOUNT
252
-        rm -rf $USB_MOUNT
253
-        exit 3
254
-    fi
252
+	# make a backup directory on the drive
253
+	if [ ! -d $USB_MOUNT/backup ]; then
254
+		mkdir $USB_MOUNT/backup
255
+	fi
256
+	if [ ! -d $USB_MOUNT/backup ]; then
257
+		echo $"There was a problem making the directory $USB_MOUNT/backup."
258
+		umount $USB_MOUNT
259
+		rm -rf $USB_MOUNT
260
+		exit 3
261
+	fi
255 262
 }
256 263
 
257 264
 function check_storage_space_remaining {
258
-    # Check space remaining on the usb drive
259
-    used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
260
-    if [ $used_percent -gt 95 ]; then
261
-        echo $"Less than 5% of space remaining on backup drive"
262
-        umount $USB_MOUNT
263
-        rm -rf $USB_MOUNT
264
-        exit 4
265
-    fi
265
+	# Check space remaining on the usb drive
266
+	used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
267
+	if [ $used_percent -gt 95 ]; then
268
+		echo $"Less than 5% of space remaining on backup drive"
269
+		umount $USB_MOUNT
270
+		rm -rf $USB_MOUNT
271
+		exit 4
272
+	fi
266 273
 }
267 274
 
268 275
 function backup_users {
269
-    # Backup user files
270
-    for d in /home/*/ ; do
271
-        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
272
-        if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
273
-
274
-            # Backup any gpg keys
275
-            if [ -d /home/$USERNAME/.gnupg ]; then
276
-                echo $"Backing up gpg keys for $USERNAME"
277
-                backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
278
-            fi
279
-
280
-            # Backup any personal settings
281
-            if [ -d /home/$USERNAME/personal ]; then
282
-                echo $"Backing up personal settings for $USERNAME"
283
-                backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
284
-            fi
285
-
286
-            # Backup ssh keys
287
-            if [ -d /home/$USERNAME/.ssh ]; then
288
-                echo $"Backing up ssh keys for $USERNAME"
289
-                backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
290
-            fi
291
-
292
-            # Backup fin database if it exists
293
-            if [ -d /home/$USERNAME/.fin ]; then
294
-                echo $"Backing up fin files for $USERNAME"
295
-                backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
296
-            fi
297
-
298
-            # Backup syncthing
299
-            if [ -d /home/$USERNAME/Sync ]; then
300
-                echo $"Backing up syncthing files for $USERNAME"
301
-                backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
276
+	# Backup user files
277
+	for d in /home/*/ ; do
278
+		USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
279
+		if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
280
+
281
+			# Backup any gpg keys
282
+			if [ -d /home/$USERNAME/.gnupg ]; then
283
+				echo $"Backing up gpg keys for $USERNAME"
284
+				backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
285
+			fi
286
+
287
+			# Backup any personal settings
288
+			if [ -d /home/$USERNAME/personal ]; then
289
+				echo $"Backing up personal settings for $USERNAME"
290
+				backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
291
+			fi
292
+
293
+			# Backup ssh keys
294
+			if [ -d /home/$USERNAME/.ssh ]; then
295
+				echo $"Backing up ssh keys for $USERNAME"
296
+				backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
297
+			fi
298
+
299
+			# Backup fin database if it exists
300
+			if [ -d /home/$USERNAME/.fin ]; then
301
+				echo $"Backing up fin files for $USERNAME"
302
+				backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
303
+			fi
304
+
305
+			# Backup syncthing
306
+			if [ -d /home/$USERNAME/Sync ]; then
307
+				echo $"Backing up syncthing files for $USERNAME"
308
+				backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
302 309
 				# ensure that device IDs will be backed up as part of user config settings
303 310
 				if [ ! -d /home/$USERNAME/.config/syncthing ]; then
304 311
 					mkdir -p /home/$USERNAME/.config/syncthing
305 312
 					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
306
-				fi					
313
+				fi
307 314
 				if [ -f /home/$USERNAME/.syncthing-server-id ]; then
308 315
 					cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
309 316
 					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
310
-				fi				
317
+				fi
311 318
 				if [ -f /home/$USERNAME/.syncthingids ]; then
312 319
 					cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
313 320
 					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
314
-				fi				
321
+				fi
315 322
 			fi
316
-			
323
+
317 324
 			# Backup user configs
318 325
 			if [ -d /home/$USERNAME/.config ]; then
319 326
 				echo $"Backing up config files for $USERNAME"
320 327
 				backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
321 328
 			fi
322
-			
329
+
323 330
 			# Backup user local
324 331
 			if [ -d /home/$USERNAME/.local ]; then
325 332
 				echo $"Backing up local files for $USERNAME"
@@ -370,6 +377,12 @@ function backup_users {
370 377
 }
371 378
 
372 379
 function backup_directories {
380
+	if [ -d $HOME/.gvm/scripts ]; then
381
+		cd $HOME/.gvm/scripts
382
+		gvm use go${GO_VERSION} --default
383
+		systemctl set-environment GOPATH=$GOPATH
384
+	fi
385
+
373 386
 	# directories to be backed up (source,dest)
374 387
 	backup_dirs=(
375 388
 		"none,                               none,       /etc/letsencrypt,                                letsencrypt"
@@ -382,8 +395,8 @@ function backup_directories {
382 395
 		"none,                               none,       /etc/nginx/sites-available,                      web"
383 396
 		"none,                               none,       /home/$ADMIN_USERNAME/.ipfs,                     ipfs"
384 397
 		"none,                               none,       /var/cache/minidlna,                             dlna"
385
-		"/home/git/go/src/github.com/gogits, gogs,       /root/tempgogsdata,                              gogsdata"
386
-		"none,                               none,       /home/git/go/src/github.com/gogits/gogs/custom,  gogs"
398
+		"$GOPATH/src/github.com/gogits, gogs,       /root/tempgogsdata,                              gogsdata"
399
+		"none,                               none,       $GOPATH/src/github.com/gogits/gogs/custom,  gogs"
387 400
 		"none,                               none,       /home/git/gogs-repositories,                     gogsrepos"
388 401
 		"none,                               none,       /home/git/.ssh,                                  gogsssh"
389 402
 		"none,                               none,       /var/lib/tox-bootstrapd,                         tox"
@@ -451,8 +464,14 @@ function remove_backup_directory {
451 464
 }
452 465
 
453 466
 function prepare_directories {
467
+	if [ -d $HOME/.gvm/scripts ]; then
468
+		cd $HOME/.gvm/scripts
469
+		gvm use go${GO_VERSION} --default
470
+		systemctl set-environment GOPATH=$GOPATH
471
+	fi
472
+
454 473
 	# Some miscellaneous preparation for backing up directories
455
-	if [ -d /home/git/go/src/github.com/gogits ]; then
474
+	if [ -d $GOPATH/src/github.com/gogits ]; then
456 475
 		mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
457 476
 	fi
458 477
 	if [ -d /var/lib/tox-bootstrapd ]; then

+ 513
- 500
src/freedombone-backup-remote
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 698
- 685
src/freedombone-restore-local
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 854
- 841
src/freedombone-restore-remote
Файловите разлики са ограничени, защото са твърде много
Целия файл