-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuninstall.sh
executable file
·114 lines (99 loc) · 2.49 KB
/
uninstall.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
112
113
114
#!/bin/bash
# Uninstall Docker IaaS tools.
# Need to be run with root privileges.
#
# Created by Peter Bryzgalov
# Copyright (C) 2015 RIKEN AICS. All rights reserved
version="0.45"
debug=1
if [[ $(id -u) != "0" ]]; then
printf "Error: Must be root to use it.\n" 1>&2
exit 1
fi
eval $(./install.sh -c)
if [ ! -f "$diaasconfig" ]; then
echo "Configuration file not found. DIaaS may not have been installed."
exit 1
fi
source $diaasconfig
deleteFile() {
file=$1
if [ -a "$file" ]; then
rm -rf $file
if [[ $? -eq 1 ]]; then
echo "Error: Could not delete $file." 1>&2
exit 1
fi
printf "$format" "$file" "deleted"
fi
}
deleteUser() {
username=$1
./cleanuser.sh $username
printf "$format" "User $username" "deleted"
}
# Delete users
users=$(cat $usersfile | wc -l)
if [ $users -ge 1 ]; then
echo -n " Delete Docker IaaS users? [y/n]"
read -n 1 rmusers
printf "\n"
if [[ $rmusers == "y" ]]; then
mapfile -t userlines <<< "$(cat $usersfile)"
for userline in "${userlines[@]}"; do
read -ra userarray <<< "$userline"
deleteUser ${userarray[0]}
done
printf "$format" "Users deleted" "OK"
fi
fi
# Group
if [ -n "$(cat /etc/group | grep "$diaasgroup:")" ]; then
echo -n " Remove $diaasgroup? [y/n]"
read -n 1 rmgroup
printf "\n"
if [[ $rmgroup == "y" ]]; then
groupdel "$diaasgroup"
printf "$format" "Group $diaasgroup" "deleted"
fi
fi
# Remove files
deleteFile "$forcecommand"
deleteFile "$forcecommandlog"
deleteFile "$tablesfolder"
# Restore SSH config file
if [ -f "$ssh_backup" ]; then
echo -n " Restore backed up version of $ssh_conf? [y/n]"
read -n 1 restoressh
printf "\n"
if [[ $restoressh != "y" ]]; then
printf "$format" "$ssh_conf" "Leave untached"
else
mv "$ssh_backup" "$ssh_conf"
printf "$format" "$ssh_conf" "Restored original version"
fi
else
echo "Error: SSH configuration file $ssh_conf not found." 1>&2
fi
# Edit /etc/pam.d/sshd
if [ -n "$sshd_pam_edited" ]; then
sed -ri 's/^session\s+optional\s+pam_loginuid.so$/session required pam_loginuid.so/' "$sshd_pam"
if [[ $? -eq 0 ]]; then
printf "$format" "$sshd_pam" "restored: session optional pam_loginuid.so -> session required pam_loginuid.so"
fi
fi
echo -n " Restart sshd? [y/n]"
read -n 1 restartssh
printf "\n"
if [[ $restartssh == "y" ]]; then
service ssh restart
fi
# Remove DIaaS config file
rm $diaasconfig
printf "$format" "$diaasconfig" "deleted"
# Kill socat
if [[ -n $socatpid ]]; then
kill $socatpid
printf "$format" "socat proxy" "killed"
fi
echo "Uninstallation comlete."