#!/bin/bash
###########################################################
#
# Bitwarden Server - docker 이미지 설치
#
###########################################################
CURRENT_DIR=$(pwd -P)
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
USE_BITWARDEN=1
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/*
# Let's encrypt 인증서를 사용하여 5443포트로 실행한다.
# Let's encrypt 사용시 cert.pem은 fullchain.pem으로 교체하여 사용
docker run -d --name vaultwarden -e ROCKET_TLS="{certs=\"/ssl/live/hasu0707.duckdns.org/cert.pem\",key=\"/ssl/live/hasu0707.duckdns.org/privkey.pem\"}" -v /etc/letsencrypt/:/ssl/ -v /var/lib/vaultwarden/:/data/ -p 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_vaultwarden