2021-08-05 18:06:43 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-08-05 23:23:48 +02:00
|
|
|
# PhotoPrism Cloud Setup Script
|
|
|
|
# =============================
|
|
|
|
|
2021-08-05 18:06:43 +02:00
|
|
|
# check if user is root
|
|
|
|
if [[ $(id -u) != "0" ]]; then
|
|
|
|
echo "You need to be root to run this script." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# fail on errors
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# disable user interactions
|
|
|
|
export DEBIAN_FRONTEND="noninteractive"
|
|
|
|
export TMPDIR="/tmp"
|
|
|
|
|
|
|
|
# add 4 GB of swap if no swap was configured yet
|
|
|
|
if [[ -z $(swapon --show) ]]; then
|
|
|
|
fallocate -l 4G /swapfile
|
|
|
|
chmod 600 /swapfile
|
|
|
|
mkswap /swapfile
|
|
|
|
swapon /swapfile
|
|
|
|
swapon --show
|
|
|
|
free -h
|
|
|
|
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set apt defaults
|
|
|
|
echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80retry && \
|
|
|
|
echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/80recommends && \
|
|
|
|
echo 'APT::Install-Suggests "false";' > /etc/apt/apt.conf.d/80suggests && \
|
|
|
|
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/80forceyes && \
|
|
|
|
echo 'APT::Get::Fix-Missing "true";' > /etc/apt/apt.conf.d/80fixmissing
|
|
|
|
|
|
|
|
# update operating system
|
2021-08-06 00:06:17 +02:00
|
|
|
apt-get update
|
2021-08-31 18:08:37 +02:00
|
|
|
apt dist-upgrade 2>/dev/null
|
2021-08-05 18:06:43 +02:00
|
|
|
|
|
|
|
# install dependencies
|
2021-08-06 00:06:17 +02:00
|
|
|
apt-get -qq install --no-install-recommends apt-transport-https ca-certificates \
|
2021-08-05 20:18:08 +02:00
|
|
|
curl software-properties-common openssl
|
2021-08-05 18:06:43 +02:00
|
|
|
|
|
|
|
# install docker if needed
|
2021-08-05 23:10:53 +02:00
|
|
|
if ! command -v docker &> /dev/null; then
|
2021-08-05 18:06:43 +02:00
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
|
|
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
|
|
|
|
apt-get update
|
2021-08-06 00:06:17 +02:00
|
|
|
apt-get -qq install docker-ce
|
2021-08-05 18:06:43 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# install docker-compose if needed
|
2021-08-05 23:10:53 +02:00
|
|
|
if ! command -v docker-compose &> /dev/null; then
|
2021-08-05 18:06:43 +02:00
|
|
|
apt-get update
|
2021-08-06 00:06:17 +02:00
|
|
|
apt-get -qq install docker-compose
|
2021-08-05 18:06:43 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create user
|
2021-09-28 18:51:23 +02:00
|
|
|
useradd -o -m -U -u 1000 -G docker -d /opt/photoprism photoprism || echo "User 'photoprism' already exists. Proceeding."
|
2021-08-05 22:41:53 +02:00
|
|
|
mkdir -p /opt/photoprism/originals /opt/photoprism/import /opt/photoprism/storage /opt/photoprism/backup \
|
|
|
|
/opt/photoprism/database /opt/photoprism/traefik /opt/photoprism/certs
|
2021-08-05 20:18:08 +02:00
|
|
|
|
|
|
|
# download ssl config
|
2021-08-05 22:41:53 +02:00
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/certs/ca.conf > /opt/photoprism/certs/ca.conf
|
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/certs/cert.conf > /opt/photoprism/certs/cert.conf
|
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/certs/config.yml > /opt/photoprism/certs/config.yml
|
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/certs/openssl.conf > /opt/photoprism/certs/openssl.conf
|
2021-08-05 20:18:08 +02:00
|
|
|
|
|
|
|
# create ca
|
2021-08-05 22:41:53 +02:00
|
|
|
openssl genrsa -out /opt/photoprism/certs/ca.key 4096
|
|
|
|
openssl req -x509 -new -nodes -key /opt/photoprism/certs/ca.key -sha256 -days 365 \
|
|
|
|
-out /opt/photoprism/certs/ca.pem -config /opt/photoprism/certs/ca.conf
|
|
|
|
openssl x509 -outform der -in /opt/photoprism/certs/ca.pem -out /opt/photoprism/certs/ca.crt
|
2021-08-05 20:18:08 +02:00
|
|
|
|
|
|
|
# create certs
|
2021-08-05 22:41:53 +02:00
|
|
|
openssl genrsa -out /opt/photoprism/certs/cert.key 4096
|
|
|
|
openssl req -new -config /opt/photoprism/certs/openssl.conf -key /opt/photoprism/certs/cert.key \
|
|
|
|
-out /opt/photoprism/certs/cert.csr
|
|
|
|
openssl x509 -req -in /opt/photoprism/certs/cert.csr -CA /opt/photoprism/certs/ca.pem \
|
|
|
|
-CAkey /opt/photoprism/certs/ca.key -CAcreateserial \
|
|
|
|
-out /opt/photoprism/certs/cert.crt -days 365 -sha256 -extfile /opt/photoprism/certs/cert.conf
|
|
|
|
openssl pkcs12 -export -in /opt/photoprism/certs/cert.crt -inkey /opt/photoprism/certs/cert.key \
|
|
|
|
-out /opt/photoprism/certs/cert.pfx -passout pass:
|
2021-08-05 18:06:43 +02:00
|
|
|
|
2021-08-05 21:05:59 +02:00
|
|
|
# generate random password
|
|
|
|
PASSWORD_PLACEHOLDER="_admin_password_"
|
|
|
|
ADMIN_PASSWORD=$(gpg --gen-random --armor 2 6)
|
2021-08-05 21:25:32 +02:00
|
|
|
echo "${ADMIN_PASSWORD}" > /root/.initial-password.txt
|
2021-08-05 21:37:41 +02:00
|
|
|
chmod 600 /root/.initial-password.txt
|
2021-08-05 21:05:59 +02:00
|
|
|
|
|
|
|
# detect public server ip address
|
|
|
|
PUBLIC_IP=$(curl -sfSL ifconfig.me)
|
|
|
|
|
2021-08-05 18:06:43 +02:00
|
|
|
# download service config
|
2021-08-05 22:41:53 +02:00
|
|
|
COMPOSE_CONFIG=$(curl -fsSL https://dl.photoprism.org/docker/cloud/docker-compose.yml)
|
2021-08-05 21:05:59 +02:00
|
|
|
COMPOSE_CONFIG=${COMPOSE_CONFIG//_public_ip_/$PUBLIC_IP}
|
|
|
|
COMPOSE_CONFIG=${COMPOSE_CONFIG//$PASSWORD_PLACEHOLDER/$ADMIN_PASSWORD}
|
2021-08-05 22:41:53 +02:00
|
|
|
echo "${COMPOSE_CONFIG}" > /opt/photoprism/docker-compose.yml
|
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/jobs.ini > /opt/photoprism/jobs.ini
|
|
|
|
curl -fsSL https://dl.photoprism.org/docker/cloud/traefik.yaml > /opt/photoprism/traefik.yaml
|
2021-08-05 21:05:59 +02:00
|
|
|
|
|
|
|
# change permissions
|
2021-08-05 22:41:53 +02:00
|
|
|
chown -Rf photoprism:photoprism /opt/photoprism
|
2021-08-05 18:06:43 +02:00
|
|
|
|
2021-08-06 00:06:17 +02:00
|
|
|
# clear package cache
|
|
|
|
apt-get autoclean
|
|
|
|
apt-get autoremove
|
2021-08-05 21:47:06 +02:00
|
|
|
|
2021-08-05 18:06:43 +02:00
|
|
|
# start services using docker-compose
|
2021-08-05 22:41:53 +02:00
|
|
|
(cd /opt/photoprism && docker-compose pull && docker-compose stop && docker-compose up --remove-orphans -d)
|
2021-08-05 21:25:32 +02:00
|
|
|
|
|
|
|
# show public server URL and initial admin password
|
|
|
|
printf "\nServer URL:\n\n https://%s/\n\nInitial admin password:\n\n %s\n\n" "${PUBLIC_IP}" "${ADMIN_PASSWORD}"
|