forked from haiwen/seafile-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seafile-server-setup
executable file
·107 lines (93 loc) · 2.71 KB
/
seafile-server-setup
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
#!/bin/bash
set -e
set -o pipefail
err_and_quit () {
printf "\n\n\033[33mError occured during setup. \nPlease fix possible issues and run the script again.\033[m\n\n"
exit 1
}
on_ctrl_c_pressed () {
printf "\n\n\033[33mYou have pressed Ctrl-C. Setup is interrupted.\033[m\n\n"
exit 1
}
# clean newly created ccnet/seafile configs when exit on SIGINT
trap on_ctrl_c_pressed 2
read_yes_no () {
printf "[yes|no] "
read yesno
while [[ "$yesno" != "yes" && "$yesno" != "no" ]]
do
printf "please answer [yes|no] "
read yesno
done
if [[ "$yesno" == "no" ]]; then
return 1
else
return 0
fi
}
ask_question () {
local question default key
question=$1
default=$2
key=$3
printf "$question"
printf "\n"
if [[ "$default" != "" && "$default" != "nodefault" ]]; then
printf "[default: $default] "
elif [[ "$key" != "" ]]; then
printf "[$key]: "
fi
}
get_server_name () {
local question="Host name for your seafile server?" default="seafile.example.com"
ask_question "$question" "seafile.example.com"
read server_name
if [[ "$server_name" == "" ]]; then
server_name=$default
elif [[ ! $server_name =~ ^[a-zA-Z0-9_-.]+$ ]]; then
printf "\n\033[33m${server_name}\033[m is not a valid name.\n"
get_server_name
fi
echo
}
# echo "Please specify the email address and password for the seahub administrator."
# echo "You can use them to login as admin on your seahub website."
# echo
get_admin_email () {
local question="Admin email address for your seafile server?" default="me@example.com"
ask_question "$question" "$default"
read admin_email
if [[ "$admin_email" == "" ]]; then
admin_email=$default
elif [[ ! $admin_email =~ ^.+@.*\..+$ ]]; then
echo "$admin_email is not a valid email address"
get_admin_email
fi
}
get_admin_passwd () {
local question="Admin password for your seafile server?"
ask_question "$question" "nodefault" "seahub admin password"
read -s admin_passwd
echo
question="Please enter the password again:"
ask_question "$question" "nodefault" "seahub admin password again"
read -s admin_passwd_again
echo
if [[ "$admin_passwd" != "$admin_passwd_again" ]]; then
printf "\033[33mThe passwords didn't match.\033[m"
get_admin_passwd
elif [[ "$admin_passwd" == "" ]]; then
echo "Password cannot be empty."
get_admin_passwd
fi
}
get_server_name
get_admin_email
get_admin_passwd
cat >bootstrap/bootstrap.conf<<EOF
[server]
server.hostname = $server_name
admin.email = $admin_email
admin.password = $admin_passwd
EOF
./launcher bootstrap && ./launcher start