seafile-containerized/launcher
2016-11-12 15:15:26 +08:00

90 lines
2 KiB
Bash
Executable file

#!/bin/bash
set -e
set -o pipefail
version=6.0.5
image=seafileorg/server:$version
dockerdir=$(cd "$(dirname $0)"; pwd -P)
sharedir=$dockerdir/shared
installdir=/opt/seafile/seafile-server-$version
cd $dockerdir
dbg() {
if [[ $debug == "true" ]]; then
echo "dbg: $1"
fi
}
err_and_quit () {
printf "\n\n\033[33mError: %s\033[m\n\n" "$1"
exit 1
}
init_shared() {
mkdir -p $sharedir/seafile/
mkdir -p $sharedir/logs/{seafile,var-log}
mkdir -p $sharedir/logs/var-log/nginx
touch $sharedir/logs/var-log/syslog
local bash_history=$sharedir/.bash_history
if [[ ! -e $bash_history ]]; then
touch $bash_history
fi
}
set_volumes() {
local mounts
init_shared
mounts=(
$sharedir:/shared
$sharedir/logs/var-log:/var/log
$dockerdir/bootstrap:/bootstrap:ro
$dockerdir/scripts:/scripts:ro
$dockerdir/scripts/tmp/check_init_admin.py:$installdir/check_init_admin.py:ro
$sharedir/.bash_history:/root/.bash_history
)
volumes=""
local m
for m in ${mounts[*]}; do
volumes="$volumes -v $m"
done
}
bootstrap() {
local bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf
if [[ ! -e $bootstrap_conf ]]; then
err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?"
fi
set_volumes
docker run --rm -it -e SEAFILE_BOOTSRAP=1 $volumes $image /scripts/bootstrap.py
}
start() {
set_volumes
docker run --rm -it --name seafile $volumes $image # /scripts/start.py
}
enter() {
err_and_quit "Not implemented yet"
}
function main {
local action
while [[ $# -gt 0 ]]
do
case "$1" in
bootstrap|start|enter) action=$1 ; shift 1 ;;
--debug) debug=true ; shift 1 ;;
--dummy) dummy=$2 ; shift 2 ;;
*) err_and_quit "Argument error. Please see help." ;;
esac
done
"$action"
}
main "$@"