seafile-containerized/seafile-server-setup

108 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/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