|
#!/usr/bin/env sh |
|
|
|
{ |
|
# function to test if a program is installed |
|
has() { |
|
type "$1" > /dev/null 2>&1 |
|
} |
|
|
|
echo >&2 "> Get latest docker-compose setup for production into $HOME/peertube <" |
|
|
|
echo >&2 "Create ~/peertube and ~/peertube/docker-volume/traefik if non-exists" |
|
|
|
# init peertube and docker-volume directory |
|
mkdir -p ~/peertube/docker-volume/traefik |
|
|
|
# go workdir |
|
cd ~/peertube |
|
|
|
# create traefik acme config |
|
echo >&2 "Create ~/peertube/docker-volume/traefik/acme.json if non-exists" |
|
touch docker-volume/traefik/acme.json |
|
chmod 600 docker-volume/traefik/acme.json |
|
|
|
# define peertube git repository master http url |
|
GIT_URL="https://raw.githubusercontent.com/chocobozzz/PeerTube/master/support/docker/production" |
|
|
|
# if .env does not exist admin email and domain name are asked |
|
if [ ! -f ./.env ] |
|
then |
|
echo >&2 "Get latest environment variables ~/peertube/.env" |
|
|
|
# prompt PEERTUBE_ADMIN_EMAIL |
|
read -p "Enter PEERTUBE_ADMIN_EMAIL [admin@domain.tld]: " "$@" PEERTUBE_ADMIN_EMAIL <&1 |
|
PEERTUBE_ADMIN_EMAIL=${PEERTUBE_ADMIN_EMAIL:-admin@domain.tld} |
|
|
|
# prompt PEERTUBE_WEBSERVER_HOSTNAME |
|
read -p "Enter PEERTUBE_WEBSERVER_HOSTNAME [domain.tld]: " "$@" PEERTUBE_WEBSERVER_HOSTNAME <&1 |
|
PEERTUBE_WEBSERVER_HOSTNAME=${PEERTUBE_WEBSERVER_HOSTNAME:-domain.tld} |
|
|
|
# randomize peertube db username and password |
|
PEERTUBE_DB_USERNAME="peertube-`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5`" |
|
PEERTUBE_DB_PASSWORD=`date +%s | sha256sum | base64 | head -c 32` |
|
|
|
# copy .env |
|
if has "curl" |
|
then |
|
curl -s "$GIT_URL/.env" > .env |
|
elif has "wget" |
|
then |
|
wget -q "$GIT_URL/.env" -O .env |
|
fi |
|
|
|
# edit .env with PEERTUBE_ADMIN_EMAIL, PEERTUBE_WEBSERVER_HOSTNAME, PEERTUBE_DB_USERNAME and PEERTUBE_DB_PASSWORD |
|
sed -in "s/PEERTUBE_ADMIN_EMAIL=.*/PEERTUBE_ADMIN_EMAIL=$PEERTUBE_ADMIN_EMAIL/g" .env |
|
sed -in "s/PEERTUBE_WEBSERVER_HOSTNAME=.*/PEERTUBE_WEBSERVER_HOSTNAME=$PEERTUBE_WEBSERVER_HOSTNAME/g" .env |
|
sed -in "s/PEERTUBE_SMTP_FROM=.*/PEERTUBE_SMTP_FROM=noreply@$PEERTUBE_WEBSERVER_HOSTNAME/g" .env |
|
sed -in "s/PEERTUBE_DB_USERNAME=.*/PEERTUBE_DB_USERNAME=$PEERTUBE_DB_USERNAME/g" .env |
|
sed -in "s/PEERTUBE_DB_PASSWORD=.*/PEERTUBE_DB_PASSWORD=$PEERTUBE_DB_PASSWORD/g" .env |
|
else |
|
echo >&2 "Use existing environment variables ~/peertube/.env" |
|
|
|
# if .env exists admin email and domain name are retrieved from it |
|
PEERTUBE_ADMIN_EMAIL=`grep -Po "PEERTUBE_ADMIN_EMAIL=.+" .env | sed -ne "s/PEERTUBE_ADMIN_EMAIL=//g"` |
|
PEERTUBE_WEBSERVER_HOSTNAME=`grep -Po "PEERTUBE_WEBSERVER_HOSTNAME=.+" .env | sed -ne "s/PEERTUBE_WEBSERVER_HOSTNAME=//g"` |
|
fi |
|
|
|
echo >&2 "Get latest reverse proxy ~/peertube/docker-volume/traefik/traefik.toml" |
|
|
|
# copy traefik config |
|
if has "curl" |
|
then |
|
curl -s "$GIT_URL/config/traefik.toml" > docker-volume/traefik/traefik.toml |
|
elif has "wget" |
|
then |
|
wget -q "$GIT_URL/config/traefik.toml" -O docker-volume/traefik/traefik.toml |
|
fi |
|
|
|
echo >&2 "Set ~/peertube/docker-volume/traefik/traefik.toml with PEERTUBE_ADMIN_EMAIL and PEERTUBE_WEBSERVER_HOSTNAME" |
|
|
|
# edit traefik.toml with adminEmail and domainName |
|
sed -in "s/<MY EMAIL ADDRESS>/$PEERTUBE_ADMIN_EMAIL/g" docker-volume/traefik/traefik.toml |
|
sed -in "s/<MY DOMAIN>/$PEERTUBE_WEBSERVER_HOSTNAME/g" docker-volume/traefik/traefik.toml |
|
|
|
echo >&2 "Get latest ~/peertube/docker-compose.yml" |
|
|
|
# copy docker-compose |
|
if has "curl" |
|
then |
|
curl -s "$GIT_URL/docker-compose.yml" > docker-compose.yml |
|
elif has "wget" |
|
then |
|
wget -q "$GIT_URL/docker-compose.yml" -O docker-compose.yml |
|
fi |
|
|
|
# peertube docker image |
|
read -p "Enter custom peertube image to set in docker-compose.yml [chocobozzz/peertube*]: " "$@" PEERTUBE_DOCKER_IMAGE <&1 |
|
if [ -n "$PEERTUBE_DOCKER_IMAGE" ] |
|
then |
|
sed -ien "s#image: chocobozzz/peertube.+#image: $PEERTUBE_DOCKER_IMAGE#g" docker-compose.yml |
|
fi |
|
|
|
if [ ! $USER = 'root' ] |
|
then |
|
echo >&2 "Skipping install peertube locally into systemd: can be done only as root" |
|
else |
|
# create systemd service |
|
read -r -p "Install/Upgrade peertube locally into systemd? [Y/n] " "$@" input <&1 |
|
input=${input:-'y'} |
|
|
|
regexp=`echo $input | grep -E "^[Yy][Ee]?[Ss]?"` |
|
if [ ! -z $regexp ] |
|
then |
|
cat <<EOT > /etc/systemd/system/peertube.service |
|
[Unit] |
|
Description=PeerTube daemon |
|
Requires=docker.service |
|
After=docker.service |
|
|
|
[Service] |
|
Type=oneshot |
|
RemainAfterExit=yes |
|
WorkingDirectory=~/peertube |
|
ExecStart=docker-compose up -d |
|
ExecStop=docker-compose down |
|
TimeoutStartSec=0 |
|
|
|
[Install] |
|
WantedBy=multi-user.target |
|
EOT |
|
final_command=true |
|
fi |
|
fi |
|
|
|
echo >&2 "Edit ~/peertube.env ..." |
|
sleep 1 |
|
|
|
if has "edit" |
|
then |
|
exec edit < /dev/tty "$@" ./.env & wait |
|
elif has "nano" |
|
then |
|
exec nano < /dev/tty "$@" ./.env & wait |
|
elif has "vim" |
|
then |
|
exec vim < /dev/tty "$@" ./.env & wait |
|
elif has "vi" |
|
then |
|
exec vi < /dev/tty "$@" ./.env & wait |
|
fi |
|
|
|
if [ ! -z $final_command ] |
|
then |
|
echo >&2 "Peertube systemd service is installed / upgraded, now you can run : \\n$ systemd dameon-reload && systemd enable peertube" |
|
fi |
|
} |