rorenv/91-teardown.sh

109 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
SCRIPTHOME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPTHOME
sudo echo -n ""
if [ $(whoami) = "root" ]; then
echo "sudo せずに実行してください"
exit 0
fi
## 認証局の削除
# CAの削除
rm -rf SSL/exampleCA
if [ $(cat .setupphase.txt) -eq 0 ]; then
exit
fi
# CA証明書の削除
sudo rm /usr/local/share/ca-certificates/example.net.ca.crt
sudo update-ca-certificates -f
if [ $(cat .setupphase.txt) -eq 1 ]; then
exit
fi
# SSL証明書と秘密鍵の削除
sudo rm /etc/ssl/private/wildcard.example.net.crt
sudo rm /etc/ssl/private/wildcard.example.net.key
if [ $(cat .setupphase.txt) -eq 2 ]; then
exit
fi
# Apacheの削除
sudo rm /etc/apache2/sites-available/example.net.conf
sudo rm /etc/apache2/sites-available/gitea.conf
sudo rm /etc/apache2/sites-available/kopano.conf
sudo rm /etc/apache2/conf-available/fqdn.conf
sudo apt -y purge apache2
sudo apt -y autoremove
if [ $(cat .setupphase.txt) -eq 3 ]; then
exit
fi
# git接続設定の削除
rm ~/.ssh/git-key
rm ~/.ssh/git-key.pub
sed -i "/host git\.example\.net/,/~\/\.ssh\/git-key/d" ~/.ssh/config
ssh-keygen -f ~/.ssh/known_hosts -R git.example.net
sudo apt -y purge ssh
sudo apt -y autoremove
if [ $(cat .setupphase.txt) -eq 4 ]; then
exit
fi
# ユーザーgitの削除
sudo deluser --remove-home --force git
sudo rm /usr/local/bin/gitea
if [ $(cat .setupphase.txt) -eq 5 ]; then
exit
fi
# コンテナ関連の削除
sudo docker compose -f docker/docker-compose.yml stop
sudo docker container rm -f kopano gitea rordb
sudo docker container prune -f
sudo docker network rm docker_rornet
sudo docker volume rm -f docker_gitea docker_kopano docker_mysql
sudo docker image rm -f custom/kopano custom/gitea mariadb:10.8.3-jammy
sudo docker image prune -f
sudo docker builder prune -f
sudo rm docker/config/gitea/conf/app.ini
sudo rm docker/config/gitea/cert/ca.crt
sudo rm docker/config/kopano/packages/cert/server.crt
sudo rm docker/config/kopano/packages/cert/server.key
if [ $(cat .setupphase.txt) -eq 6 ]; then
exit
fi
# rvmの削除
rvm implode
sudo apt -y purge gnupg2
sudo apt -y autoremove
tac ~/.bashrc | sed '/# Load RVM/,+4 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.bashrc
tac ~/.bash_profile | sed '/# Load RVM/,+1 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.bash_profile
tac ~/.mkshrc | sed '/\.rvm\/bin/,+2 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.mkshrc
tac ~/.profile | sed '/# Load RVM/,+4 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.profile
tac ~/.zlogin | sed '/# Load RVM/,+1 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.zlogin
tac ~/.zshrc | sed '/\.rvm\/bin/,+2 d' | tac > ~/elifkrow; [ -s ~/elifkrow ] && mv ~/elifkrow ~/.zshrc
[ -f ~/elifkrow ] && rm ~/elifkrow
if [ $(cat .setupphase.txt) -eq 7 ]; then
exit
fi
# hostsからのホスト削除
sudo sed -i "/example\.net git\.example\.net mail\.example\.net smtp\.example\.net/d" /etc/hosts
# .setupphase.txtの削除
rm .setupphase.txt