-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_rollback.sh
76 lines (63 loc) · 2.75 KB
/
docker_rollback.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
#!/bin/bash
# function error_handler() {
# if [[ %1 -gt 0 ]]; then
# echo
# }
### Start of functions in order of operations
function uninstall_previous_docker() {
read -p "Uninstall previous Docker installation? Hit enter to continue or Ctrl-C to quit. "
sudo apt-get remove docker docker-engine docker.io containerd runc;
sudo apt-get remove docker docker.io containerd runc
}
function apt_update_upgrade_autoremove() {
read -p "Continue, and run sudo apt-get update? Hit enter to continue or Ctrl-C to quit. "
sudo apt-get update
apt-get full-upgrade
sudo apt-get autoremove
}
function download_install_docker() {
echo " "
read -p "Install docker v20.10.7? Hit enter to continue or Ctrl-C to quit."
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz
tar xzvf ./docker-20.10.7.tgz
# Copies docker files to the /usr/bin directory; will force the operation if it fails because a text file in the directory is busy.
sudo cp docker/* /usr/bin/
}
function add_docker_user_group() {
# Suggests an optional setup step that makes Docker easier to use
echo "Check if 'docker' user group exists; If not, creating one is optional, but if you add current user $USER to it will help you avoid "
echo "having to use sudo to run Docker commands. If you don't want to add this group the next prompt will let you skip to the last step "
echo "and restart the Docker Daemon. "
read -p "Press any key to continue... "
# Check if 'docker' user group exists. If yes, skip. If no, asks the user if they want to create one and add the current user to it.
if getent group docker >/dev/null; then
echo "User group 'docker' already exists."
else
# Prompt user to create 'docker' user group
read -p "User group 'docker' does not exist. Create it and add current user? (Hit enter to continue or Ctrl-C to quit.): " response
if [ "$response" = "yes" ]; then
# Create 'docker' user group and add current user
sudo groupadd docker
sudo usermod -aG docker "$(whoami)"
echo "User group 'docker' created. Current user added to the group."
else
echo "Skipping creating 'docker' user group; restarting docker daemon."
sudo dockerd &
exit
fi
fi
}
function install_docker_compose(){
read -p "Install docker-compose? Hit enter to continue or Ctrl-C to quit. "
sudo apt-get install docker-compose
}
echo "This script must be run as root. Hit enter to continue or Ctrl-C to quit. "
echo " "
echo " "
uninstall_previous_docker
apt_update_upgrade_autoremove
download_install_docker
add_docker_user_group
install_docker_compose
echo " '"
echo "Script complete"