-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall-gitlab.sh
executable file
·111 lines (102 loc) · 2.74 KB
/
uninstall-gitlab.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash -
#===============================================================================
#
# FILE: uninstall-gitlab.sh
#
# USAGE: uninstall-gitlab.sh -h hostname [-a] [-v]
# uninstall-gitlab.sh --host hostname [--all] [--verbose]
#
# DESCRIPTION: This script will uninstall Gitlab and it's virutal host files.
# If the all flag is passed, all the data and users associated
# with the installation, including all the repositories, will
# also be removed.
# OPTIONS:
# -a | --all
# Also remove all data and users, including the repositories.
# -h | --host
# The fully qualified domain name of the virtual host you wish
# to use to access GitLab.
# -v | --verbose
# If passed, will show all commands executed.
# REQUIREMENTS: Gitlab, Nginx, Passenger, Yum
# BUGS: ---
# NOTES: ---
# AUTHOR: Jason White ([email protected]),
# ORGANIZATION: @iDoAWS
# CREATED: 05/17/2016 22:33
# REVISION: 001
#===============================================================================
# Strict mode
set -uo pipefail
IFS=$'\n\t'
# Check for arguments or provide help
if [ $# -eq 0 ] ; then
echo "Usage:"
echo " `basename $0` -h hostname [-a] [-v]"
echo " `basename $0` --host host name [--all] [--verbose]"
echo "This remove Gitlab from your system."
echo "Including the all flag will also remove related all data and users."
exit 0
fi
# Confirm that the user really wants to do this
read -p "Are you sure you wish to remove Gitlab? [y/N] " -n 1 -r REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
exit 0
fi
# Parse command line arguments into variables
while :
do
case ${1:-} in
-a | --all)
ALL=true
shift 1
;;
-h | --host)
HOST="$2"
shift 2
;;
-v | --verbose)
VERBOSE=true
shift 1
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
# Validate arguments
if [ ! -v HOST ] ; then
echo 'Host name is required.'
exit 1
fi
# Check verbosity
if [ -v VERBOSE ] ; then
set -v
fi
# Do it
echo "Stopping Nginx."
sudo service nginx stop
if [ -v ALL ] ; then
sudo gitlab-ctl cleanse
else
sudo gitlab-ctl uninstall
fi
sudo yum remove gitlab-ce -y
sudo userdel -rf git
sudo userdel -rf gitlab-redis
sudo userdel -rf gitlab-psql
sudo userdel -rf gitlab-www
sudo rm -rf /opt/gitlab
sudo rm -rf /etc/gitlab
sudo rm -rf /var/log/gitlab
sudo rm /etc/nginx/sites-enabled/$HOST.conf
sudo rm /etc/nginx/sites-available/$HOST.conf
# Finish
echo "Starting Nginx."
sudo service nginx start
echo "Gitlab has been removed."
exit 0