#!/bin/bash
###########################################################
#
# Vaultwarden 설치 스크립트
# https://github.com/dani-garcia/vaultwarden
# 설치 후 http://<IP>:5443 으로 접속 확인
#
###########################################################
CURRENT_DIR=$(pwd)
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
USE_BITWARDEN=1
install_docker() {
echo "###########################################################"
echo "#"
echo "# docker"
echo "#"
echo "###########################################################"
systemctl stop docker.service
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
rm -rf /var/lib/docker
apt update -y
apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable docker.service
}
install_vaultwarden() {
echo "###########################################################"
echo "#"
echo "# vaultwarden(bitwarden unofficial 버전) 설치"
echo "# https://github.com/dani-garcia/vaultwarden"
echo "#"
echo "###########################################################"
if [ ${USE_BITWARDEN} = 1 ]
then
# docker 이미지 정리 및 제거
docker stop $(docker ps -a -q)
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -a -q)
# vaultwarden 설치 이미지 정리
docker pull vaultwarden/server:latest
mkdir -p /var/lib/vaultwarden
rm -rf /var/lib/vaultwarden/*
docker run --detach --name vaultwarden \
--env DOMAIN="https://hasu0707.duckdns.org:5443" \
--volume /etc/letsencrypt/:/ssl/ \
--volume /var/lib/vaultwarden/:/data/ \
--restart unless-stopped \
--publish 5443:80 \
vaultwarden/server:latest
# systemd 서비스 등록
echo "[Unit]" > /lib/systemd/system/docker-vaultwarden.service
echo "Wants=docker.service" >> /lib/systemd/system/docker-vaultwarden.service
echo "After=docker.service" >> /lib/systemd/system/docker-vaultwarden.service
echo "" >> /lib/systemd/system/docker-vaultwarden.service
echo "[Service]" >> /lib/systemd/system/docker-vaultwarden.service
echo "RemainAfterExit=yes" >> /lib/systemd/system/docker-vaultwarden.service
echo "ExecStart=/usr/bin/docker start vaultwarden" >> /lib/systemd/system/docker-vaultwarden.service
echo "ExecStop=/usr/bin/docker stop vaultwarden" >> /lib/systemd/system/docker-vaultwarden.service
echo "" >> /lib/systemd/system/docker-vaultwarden.service
echo "[Install]" >> /lib/systemd/system/docker-vaultwarden.service
echo "WantedBy=multi-user.target" >> /lib/systemd/system/docker-vaultwarden.service
ln -sf /lib/systemd/system/docker-vaultwarden.service /etc/systemd/system/docker-vaultwarden.service
systemctl daemon-reload
systemctl enable docker-vaultwarden.service
fi
}
install_docker
install_vaultwarden