|
@@ -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
|