Files
fotky-docker/setup.sh

57 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# setup photoview
# run as root
if [[ $(id -u) != "0" ]]; then
echo RUN AS ROOT!!
exit 1
fi
# install docker
apt-get update
apt-get install ca-certificates curl gnupg -y
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
# where to store photos
read -p "Kde chcete mít fotky? [/mnt/fotky]"
PHOTOS=${REPLY:-/mnt/fotky}
echo $PHOTOS
# serve at what domain
read -p "Na jaké doméně budou stránky? "
DOMAIN=${REPLY?Musíte mít doménu}
echo $DOMAIN
# make config files
home=/home/ubuntu
sudo -u ubuntu mkdir -p $home/etc/caddy
sed -e "s:__DOMAIN__:$DOMAIN:" Caddyfile | sudo -u ubuntu tee $home/etc/caddy/Caddyfile >/dev/null
sed -e "s:__PHOTO__:$PHOTOS:" docker-compose.yml | sudo -u ubuntu tee $home/etc/docker-compose.yml > /dev/null
# install
cd $home/etc
docker compose up -d
# add user ubuntu to docker group
usermod -a -G docker ubuntu
# SSH
cat >> /etc/ssh/sshd_config <<EOF
LoginGraceTime 42
MaxStartups 3
PermitRootLogin no
StrictModes yes
MaxAuthTries 6
MaxSessions 10
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers ubuntu
EOF