瀏覽代碼

Make configuration of remote backup locations a separate command

Bob Mottram 10 年之前
父節點
當前提交
b22c3b798a
共有 5 個檔案被更改,包括 203 行新增46 行删除
  1. 6
    0
      Makefile
  2. 1
    0
      debian/source/include-binaries
  3. 二進制
      man/freedombone-remote.1.gz
  4. 12
    46
      src/freedombone
  5. 184
    0
      src/freedombone-remote

+ 6
- 0
Makefile 查看文件

@@ -13,20 +13,26 @@ install:
13 13
 	install -m 755 src/${APP} ${DESTDIR}${PREFIX}/bin
14 14
 	install -m 755 src/${APP}-prep ${DESTDIR}${PREFIX}/bin
15 15
 	install -m 755 src/${APP}-tordongle ${DESTDIR}${PREFIX}/bin
16
+	install -m 755 src/${APP}-client ${DESTDIR}${PREFIX}/bin
17
+	install -m 755 src/${APP}-remote ${DESTDIR}${PREFIX}/bin
16 18
 	mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1
17 19
 	install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1
18 20
 	install -m 644 man/${APP}-prep.1.gz ${DESTDIR}${PREFIX}/share/man/man1
19 21
 	install -m 644 man/${APP}-tordongle.1.gz ${DESTDIR}${PREFIX}/share/man/man1
20 22
 	install -m 644 man/${APP}-client.1.gz ${DESTDIR}${PREFIX}/share/man/man1
23
+	install -m 644 man/${APP}-remote.1.gz ${DESTDIR}${PREFIX}/share/man/man1
21 24
 uninstall:
22 25
 	rm -f ${PREFIX}/share/man/man1/${APP}.1.gz
23 26
 	rm -f ${PREFIX}/share/man/man1/${APP}-prep.1.gz
24 27
 	rm -f ${PREFIX}/share/man/man1/${APP}-tordongle.1.gz
25 28
 	rm -f ${PREFIX}/share/man/man1/${APP}-client.1.gz
29
+	rm -f ${PREFIX}/share/man/man1/${APP}-remote.1.gz
26 30
 	rm -rf ${PREFIX}/share/${APP}
27 31
 	rm -f ${PREFIX}/bin/${APP}
28 32
 	rm -f ${PREFIX}/bin/${APP}-prep
29 33
 	rm -f ${PREFIX}/bin/${APP}-tordongle
34
+	rm -f ${PREFIX}/bin/${APP}-client
35
+	rm -f ${PREFIX}/bin/${APP}-remote
30 36
 clean:
31 37
 	rm -f \#* \.#* debian/*.substvars debian/*.log
32 38
 	rm -fr deb.* debian/${APP}

+ 1
- 0
debian/source/include-binaries 查看文件

@@ -2,3 +2,4 @@ man/freedombone.1.gz
2 2
 man/freedombone-prep.1.gz
3 3
 man/freedombone-tordongle.1.gz
4 4
 man/freedombone-client.1.gz
5
+man/freedombone-remote.1.gz

二進制
man/freedombone-remote.1.gz 查看文件


+ 12
- 46
src/freedombone 查看文件

@@ -395,53 +395,19 @@ function show_help {
395 395
 
396 396
 
397 397
 function interactive_configuration_remote_backups {
398
-  # clear any existing list
399
-  if [ -f $FRIENDS_SERVERS_LIST ]; then
400
-      rm -f $FRIENDS_SERVERS_LIST
401
-      touch $FRIENDS_SERVERS_LIST
402
-  fi
403
-  # number of entries made
404
-  entering_remote_backups_ctr=1
405
-
406
-  entering_remote_backups_done="no"
407
-  while [[ $entering_remote_backups_done == "no" ]]
408
-  do
409
-      data=$(tempfile 2>/dev/null)
410
-      trap "rm -f $data" 0 1 2 5 15
411
-      dialog --backtitle "Freedombone Configuration" \
412
-          --title "Remote Backup ${entering_remote_backups_ctr}" \
413
-          --form "\nPlease specify the SSH login details:" 11 55 4 \
414
-          "Username:" 1 1 "" 1 16 16 15 \
415
-          "Domain:" 2 1 "" 2 16 16 15 \
416
-          "SSH port:" 3 1 "22" 3 16 5 4 \
417
-          "Password:" 4 1 "" 4 16 20 100 \
418
-          2> $data
419
-      sel=$?
420
-      case $sel in
421
-          1) entering_remote_backups_done="yes";;
422
-          255) entering_remote_backups_done="yes";;
423
-      esac
424
-      remote_ssh_username=$(cat $data | sed -n 1p)
425
-      remote_ssh_domain=$(cat $data | sed -n 2p)
426
-      remote_ssh_port=$(cat $data | sed -n 3p)
427
-      remote_ssh_password=$(cat $data | sed -n 4p)
428
-      if [[ $remote_ssh_username != "" && \
429
-          $remote_ssh_domain != "" && \
430
-          $remote_ssh_port != "" && \
431
-          $remote_ssh_password != "" ]]; then
432
-
433
-          if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
434
-              dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
435
-          else
436
-              echo "$remote_ssh_username@$remote_ssh_domain:$remote_ssh_port//home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
437
-              entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
438
-          fi
439
-      else
440
-          entering_remote_backups_done="yes"
398
+  if [ ! -f /usr/local/bin/freedombone-remote ]; then
399
+      if [ ! -f /usr/bin/freedombone-remote ]; then
400
+          echo 'The command /usr/bin/freedombone-remote was not found'
401
+          exit 87354
441 402
       fi
442
-  done
443
-  if [ -f $FRIENDS_SERVERS_LIST ]; then
444
-      chown $MY_USERNAME:$MY_USERNAME $FRIENDS_SERVERS_LIST
403
+  fi
404
+  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH
405
+  if [ ! "$?" = "0" ]; then
406
+      echo 'Command failed:'
407
+      echo ''
408
+      echo "  freedombone-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH"
409
+      echo ''
410
+      exit 65892
445 411
   fi
446 412
 }
447 413
 

+ 184
- 0
src/freedombone-remote 查看文件

@@ -0,0 +1,184 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Creates an inventory of remote backup locations
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+# GNU General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+
31
+NO_OF_ARGS=$#
32
+
33
+# User to create the list for
34
+MY_USERNAME=
35
+
36
+# Filename of the remote backups list
37
+FRIENDS_SERVERS_LIST=
38
+
39
+# Minimum password length in characters
40
+MINIMUM_PASSWORD_LENGTH=10
41
+
42
+# How many remote locations were specified
43
+entering_remote_backups_ctr=0
44
+
45
+function show_help {
46
+  echo ''
47
+  echo 'freedombone-remote -u [username] -l [backup list filename] -m [min password length]'
48
+  echo ''
49
+  echo 'Creates an inventory of remote backup locations'
50
+  echo ''
51
+  echo ''
52
+  echo '  -h --help             Show help'
53
+  echo '  -l --list             Remote backup list (usually /home/$USER/backup.list)'
54
+  echo '  -m --min              Minimum password length (characters)'
55
+  echo ''
56
+  exit 0
57
+}
58
+
59
+# If there are no options specified
60
+if [[ $NO_OF_ARGS == 0 ]]; then
61
+  show_help
62
+  exit 0
63
+fi
64
+
65
+# Get the commandline options
66
+while [[ $# > 1 ]]
67
+do
68
+key="$1"
69
+
70
+case $key in
71
+    -h|--help)
72
+    show_help
73
+    ;;
74
+    # backup list filename
75
+    # typically /home/$USER/backup.list
76
+    -l|--list)
77
+    shift
78
+    FRIENDS_SERVERS_LIST="$1"
79
+    ;;
80
+    # username within /home
81
+    -u|--user)
82
+    shift
83
+    MY_USERNAME="$1"
84
+    ;;
85
+    # Minimum password length
86
+    -m|--min)
87
+    shift
88
+    MINIMUM_PASSWORD_LENGTH="$1"
89
+    ;;
90
+    *)
91
+    # unknown option
92
+    ;;
93
+esac
94
+shift
95
+done
96
+
97
+
98
+function interactive_configuration_remote_backups {
99
+  if [ ! $MY_USERNAME ]; then
100
+      echo 'Please specify a username with the -u option'
101
+      exit 7356
102
+  fi
103
+
104
+  if [ ! /home/$MY_USERNAME ]; then
105
+      echo "The user /home/$MY_USERNAME does not exist on the system"
106
+      exit 3689
107
+  fi
108
+
109
+  if [ ! $FRIENDS_SERVERS_LIST ]; then
110
+      FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
111
+  fi
112
+
113
+  # clear any existing list
114
+  if [ -f $FRIENDS_SERVERS_LIST ]; then
115
+      rm -f $FRIENDS_SERVERS_LIST
116
+      touch $FRIENDS_SERVERS_LIST
117
+  fi
118
+  # number of entries made
119
+  entering_remote_backups_ctr=1
120
+
121
+  entering_remote_backups_done="no"
122
+  while [[ $entering_remote_backups_done == "no" ]]
123
+  do
124
+      data=$(tempfile 2>/dev/null)
125
+      trap "rm -f $data" 0 1 2 5 15
126
+      dialog --backtitle "Freedombone Configuration" \
127
+          --title "Remote Backup ${entering_remote_backups_ctr}" \
128
+          --form "\nPlease specify the SSH login details:" 11 55 4 \
129
+          "Username:" 1 1 "" 1 16 16 15 \
130
+          "Domain:" 2 1 "" 2 16 16 15 \
131
+          "SSH port:" 3 1 "22" 3 16 5 4 \
132
+          "Password:" 4 1 "" 4 16 20 100 \
133
+          2> $data
134
+      sel=$?
135
+      case $sel in
136
+          1) entering_remote_backups_done="yes";;
137
+          255) entering_remote_backups_done="yes";;
138
+      esac
139
+      remote_ssh_username=$(cat $data | sed -n 1p)
140
+      remote_ssh_domain=$(cat $data | sed -n 2p)
141
+      remote_ssh_port=$(cat $data | sed -n 3p)
142
+      remote_ssh_password=$(cat $data | sed -n 4p)
143
+      if [[ $remote_ssh_username != "" && \
144
+          $remote_ssh_domain != "" && \
145
+          $remote_ssh_port != "" && \
146
+          $remote_ssh_password != "" ]]; then
147
+
148
+          if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
149
+              dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
150
+          else
151
+              echo "$remote_ssh_username@$remote_ssh_domain:$remote_ssh_port//home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
152
+              entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
153
+          fi
154
+      else
155
+          entering_remote_backups_done="yes"
156
+      fi
157
+  done
158
+  if [ -f $FRIENDS_SERVERS_LIST ]; then
159
+      chown $MY_USERNAME:$MY_USERNAME $FRIENDS_SERVERS_LIST
160
+  fi
161
+}
162
+
163
+function show_result {
164
+  clear
165
+  if (( $entering_remote_backups_ctr < 2 )); then
166
+      echo 'No remote backup locations were specified'
167
+      exit 0
168
+  fi
169
+  if [ ! -f $FRIENDS_SERVERS_LIST ]; then
170
+      echo "No remote backups list found: $FRIENDS_SERVERS_LIST"
171
+      exit 7358
172
+  fi
173
+  echo ''
174
+  echo "Remote backups list: $FRIENDS_SERVERS_LIST"
175
+  echo ''
176
+  echo 'Contents:'
177
+  echo ''
178
+  cat $FRIENDS_SERVERS_LIST
179
+  echo ''
180
+}
181
+
182
+interactive_configuration_remote_backups
183
+show_result
184
+exit 0