-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions
212 lines (171 loc) · 3.61 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
### openspace bash installer v0.1.0 [https://github.com/openspace42/bash_installer]
os_bash_functions_version=0.1.2
################################################################################
define_vars() {
proj_name="EasyEngine-SFTP"
short_name="ee-sftp"
author_name="openspace42"
ssh_config_file="/etc/ssh/sshd_config"
sftp_group="sftp_access"
os-define_vars
}
################################################################################
check_root() {
if [[ $EUID -ne 0 ]]
then
echo "${r}${b}This script must be run as root${x}"
echo
echo "${b}Exiting...${x}"
echo
exit 1
fi
}
download_os_functions() {
clone_author=openspace42
clone_name=bash_functions
base_dir=/root/$clone_author
clone_dir=$base_dir/$clone_name
if [ -d $clone_dir ]
then
rm -r ${clone_dir:?}
fi
mkdir -p $base_dir
( cd $base_dir && git clone https://github.com/$clone_author/$clone_name && cd $clone_name && if [ ! ${bleeding_edge-null} = "-b" ]; then git checkout tags/v$os_bash_functions_version; fi &> /dev/null )
}
source_os_functions() {
for f in /root/openspace42/bash_functions/*
do
. $f
done
}
################################################################################
choose_local_user() {
currusers="$(cat /etc/passwd | cut -d: -f 1,3,6 | grep "[1-9][0-9][0-9][0-9]" | grep "/home" | cut -d: -f1)"
declare -a options=( $currusers )
if [ -z "$currusers" ]
then
echo "${r}${b}No NON-system users found.${x}"
echo
echo "${b}Please run the | add-user | command first.${x}"
echo
os-exit_function
fi
accept=n
until [ $accept = "y" ]
do
select sel_user in "${options[@]}"
do
echo
IFS=' ' read name ip <<< $sel_user
test -n "$sel_user" && break
echo ">>> Invalid Selection"
done
echo "${b}User $sel_user selected.${x}"
echo
valid=n
until [ $valid = "y" ]
do
read -n 1 -rp "${b}Is this the correct user?${x} (${b}Y${x}[es]/${b}n${x}[o]/${b}e${x}[xit]) " answer;
case $answer in
"")
echo
valid=y
accept=y
;;
y)
echo -e "\\n"
valid=y
accept=y
;;
n)
echo -e "\\n"
echo "${b}No problem, please select your desired user again now...${x}"
echo
valid=y
accept=n
;;
e)
echo -e "\\n"
echo "${b}Exiting...${x}"
echo
exit
;;
*)
echo -e "\\n"
echo "${b}Invalid option. Retry...${x}"
echo
valid=n
accept=n
;;
esac
done
done
}
choose_local_site() {
if [ ! -d $www_dir ]
then
echo "${r}${b}Local backups directory [$www_dir] not found.${x}"
echo
os-exit_function
fi
if [ -z "$(ls -A $www_dir)" ]
then
echo "${r}${b}No sites found in | $www_dir |..${x}"
echo
os-exit_function
fi
choice="${b}Now choose the site you'd like to provide access to: ${x}"
echo "$choice"
echo
accept=n
until [ $accept = "y" ]
do
select sel_site in $www_dir/*
do
echo
test -n "$sel_site" && break
echo ">>> Invalid Selection"
done
echo "${b}Site $sel_site selected.${x}"
echo
valid=n
until [ $valid = "y" ]
do
read -n 1 -rp "${b}Is this the correct site?${x} (${b}Y${x}[es]/${b}n${x}[o]/${b}e${x}[xit]) " answer;
case $answer in
"")
echo
valid=y
accept=y
;;
y)
echo -e "\\n"
valid=y
accept=y
;;
n)
echo -e "\\n"
echo "${b}No problem, please select your desired site again now...${x}"
echo
valid=y
accept=n
;;
e)
echo -e "\\n"
echo "${b}Exiting...${x}"
echo
exit
;;
*)
echo -e "\\n"
echo "${b}Invalid option. Retry...${x}"
echo
valid=n
accept=n
;;
esac
done
done
sel_site_name=${sel_site#/var/www/}
}