forked from DOUBLE-TOP/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.sh
100 lines (97 loc) · 4.12 KB
/
docker.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
#!/bin/bash
#Thanks Let's Node!
# Default variables
dive="false"
function="install"
# Options
. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/colors.sh) --
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
while test $# -gt 0; do
case "$1" in
-h|--help)
. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/logo.sh)
echo
echo -e "${C_LGn}Functionality${RES}: the script installs or uninstalls Docker"
echo
echo -e "${C_LGn}Usage${RES}: script ${C_LGn}[OPTIONS]${RES}"
echo
echo -e "${C_LGn}Options${RES}:"
echo -e " -h, --help show the help page"
echo -e " -d, --dive install Dive (images analyser)"
echo -e " -u, --uninstall uninstall Docker (${C_R}completely delete all images and containers${RES})"
echo
echo -e "${C_LGn}Useful URLs${RES}:"
echo -e "https://github.com/SecorD0/utils/blob/main/installers/docker.sh - script URL"
echo -e "https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository — Docker installation"
echo -e "https://docs.docker.com/compose/install/#install-compose — Docker Compose installation"
echo -e "https://github.com/wagoodman/dive#installation — Dive installation"
echo -e "https://t.me/letskynode — node Community"
echo -e "https://teletype.in/@letskynode — guides and articles"
echo
return 0 2>/dev/null; exit 0
;;
-d|--dive)
dive="true"
shift
;;
-u|--uninstall)
function="uninstall"
shift
;;
*|--)
break
;;
esac
done
# Functions
install() {
cd
if ! docker --version; then
echo -e "${C_LGn}Docker installation...${RES}"
sudo apt update
sudo apt upgrade -y
sudo apt install curl apt-transport-https ca-certificates gnupg lsb-release apparmor -y
. /etc/*-release
if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ]; then
wget -qO- "https://download.docker.com/linux/${DISTRIB_ID,,}/gpg" | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
fi
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y
docker_version=`apt-cache madison docker-ce | grep -oPm1 "(?<=docker-ce \| )([^_]+)(?= \| https)"`
sudo apt install docker-ce="$docker_version" docker-ce-cli="$docker_version" containerd.io -y
fi
if ! docker-compose --version; then
echo -e "${C_LGn}Docker Сompose installation...${RES}"
sudo apt update
sudo apt upgrade -y
sudo apt install wget jq -y
local docker_compose_version=v2.16.0
# local docker_compose_version=`wget -qO- https://api.github.com/repos/docker/compose/releases/latest | jq -r ".tag_name"`
sudo wget -O /usr/bin/docker-compose "https://github.com/docker/compose/releases/download/${docker_compose_version}/docker-compose-`uname -s`-`uname -m`"
sudo chmod +x /usr/bin/docker-compose
. $HOME/.bash_profile
fi
if [ "$dive" = "true" ] && ! dpkg -s dive | grep -q "ok installed"; then
echo -e "${C_LGn}Dive installation...${RES}"
wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb
sudo apt install ./dive_0.9.2_linux_amd64.deb
rm -rf dive_0.9.2_linux_amd64.deb
fi
}
uninstall() {
echo -e "${C_LGn}Docker uninstalling...${RES}"
sudo dpkg -r dive
sudo systemctl stop docker.service docker.socket
sudo systemctl disable docker.service docker.socket
sudo rm -rf `systemctl cat docker.service | grep -oPm1 "(?<=^#)([^%]+)"` `systemctl cat docker.socket | grep -oPm1 "(?<=^#)([^%]+)"` /usr/bin/docker-compose
sudo apt purge docker-engine docker docker.io docker-ce docker-ce-cli -y
sudo apt autoremove --purge docker-engine docker docker.io docker-ce -y
sudo apt autoclean
sudo rm -rf /var/lib/docker /etc/appasudo rmor.d/docker
sudo groupdel docker
sudo rm -rf /etc/docker /usr/bin/docker /usr/libexec/docker /usr/libexec/docker/cli-plugins/docker-buildx /usr/libexec/docker/cli-plugins/docker-scan /usr/libexec/docker/cli-plugins/docker-app /usr/share/keyrings/docker-archive-keyring.gpg
}
# Actions
$function
echo -e "${C_LGn}Done!${RES}"