-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
100 lines (89 loc) · 2.71 KB
/
main.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
if ! command -v zenity &> /dev/null
then
function get_distro() {
if [[ -f /etc/os-release ]]
then
source /etc/os-release
echo $ID
else
uname
fi
}
case $(get_distro) in
fedora)
sudo dnf install zenity
;;
ubuntu)
sudo apt-get -y install zenity
;;
debian)
sudo apt-get -y install zenity
;;
esac
fi
if ! command -v docker &> /dev/null
then
zenity --question \
--title "DocGUI" \
--text "Docker is not installed. Do you want to install it?"
case $? in
0)
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker $USER
newgrp docker
;;
1)
zenity --warning --title="Docker not Installed" --text="You need Docker to be installed to create containers."
exit
;;
esac
fi
maindata=$(zenity --forms --title="DocGUI" --text="Run Container" \
--add-entry="Image" \
--add-entry="Container Name" \
--add-entry="Host Port" \
--add-entry="Container Port" \
--add-entry="Host Volume" \
--add-entry="Container Volume"
)
[[ "$?" != "0" ]] && exit 1
image=$(echo $maindata | awk 'BEGIN {FS="|" } { print $1 }')
name=$(echo $maindata | awk 'BEGIN {FS="|" } { print $2 }')
host_port=$(echo $maindata | awk 'BEGIN {FS="|" } { print $3 }')
container_port=$(echo $maindata | awk 'BEGIN {FS="|" } { print $4 }')
host_volume=$(echo $maindata | awk 'BEGIN {FS="|" } { print $5 }')
container_volume=$(echo $maindata | awk 'BEGIN {FS="|" } { print $6 }')
if [ -z "$name" ]
then
container_name=""
else
container_name="--name ${name}"
fi
if [ -z "$host_volume" ] || [ -z "$container_volume" ]
then
volume=""
else
volume="-v $host_volume:$container_volume"
fi
options=$(zenity --list --checklist \
--title 'Container Options' \
--text 'Select the Options' \
--column 'Select' \
--column 'Options' TRUE "Detached Mode" FALSE "Delete Container after stopping"
)
[[ "$?" != "0" ]] && exit 1
if [[ $options == "Detached Mode|Delete Container after stopping" ]]; then
detached="-d"
removal="--rm"
elif [[ $options == "Detached Mode" ]]; then
detached="-d"
elif [[ $options == "Delete Container after stopping" ]]; then
removal="--rm"
fi
tmpfile=$(mktemp)
docker run ${removal} ${detached} ${container_name} -p ${host_port}:${container_port} ${volume} ${image} | tee >(zenity --title="Creating Container" \
--progress --pulsate --text="Creating Container..." \
--auto-kill --auto-close) >${tmpfile}
zenity --title "${name} Details" \
--text-info --filename="${tmpfile}"