-
Notifications
You must be signed in to change notification settings - Fork 22
/
start_devel_env.sh
executable file
·131 lines (110 loc) · 3.87 KB
/
start_devel_env.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env sh
#
# Create development environment using a Docker or Podman container
#
JEKYLL_VERSION=3.8
DOCKER_INSTALLED=0
PODMAN_INSTALLED=0
choice=0
function run_docker() {
# Serve the site via Docker and update site when files changed in repo
docker run --rm \
-p 4000:4000 \
-v "$PWD:/srv/jekyll:Z" \
-v "$PWD/.bundle-cache:/usr/local/bundle" \
-it "jekyll/jekyll:$JEKYLL_VERSION" \
sh -c "jekyll serve --watch"
}
function run_podman() {
# Serve the site via Podman and update site when files changed in repo
podman run --rm \
-p 4000:4000 \
-v "$PWD:/srv/jekyll:Z" \
-v "$PWD/.bundle-cache:/usr/local/bundle" \
-it "docker.io/jekyll/jekyll:$JEKYLL_VERSION" \
sh -c "jekyll serve --watch"
}
# Ensure _site directory is created for Jekyll engine
if [ ! -d ./_site ]; then
mkdir ./_site
fi
# Ensure .bundle-cache exists for Podman
if [ ! -d ./.bundle-cache ]; then
mkdir ./.bundle-cache
fi
# Check if docker is installed
if command -v docker &> /dev/null; then
DOCKER_INSTALLED=1
fi
# Check if podman is installed
if command -v podman &> /dev/null; then
PODMAN_INSTALLED=1
fi
ANDED=$(( $DOCKER_INSTALLED & $PODMAN_INSTALLED ))
# Checking the ANDed value of the Docker and Podman variables
case $ANDED in
# If it's 0, that means one of them is installed (or neither)
0)
if (( $DOCKER_INSTALLED == 1 )); then
echo "Detected Docker installation, using that..."
run_docker
elif (( $PODMAN_INSTALLED ==1 )); then
echo "Detected Podman installation, using that..."
run_podman
else
echo "It appears you don't have Docker or Podman installed. Please ensure it is installed and proceed with running the development environment."
fi
;;
1)
invalid=0
# Looping the user input in case they input an invalid number
while [ $invalid -eq 0 ]; do
# Goofy ANSI escape codes
# What they mean:
#
# Full string:
# \033[1;31m(0)\033[0m
#
# Broken down:
#
# \033
# ∟ Escape character in ANSI telling the terminal "Hey there's a color sequence coming up"
#
# [1;31m
# ∟ 1-Bold; 31m means red foreground `m` probably means end of sequence or something
#
# (0)
# ∟ The text displayed
#
# \033
# ∟ Escape character in ANSI telling the terminal "Hey there's a color sequence coming up"
#
# [0m
# ∟ Resetting the color back to normal cause if you don't it'll stay the previous color
#
# Learn more here - https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences (or https://archive.is/bMIsg)
echo -e "Both Docker \033[1;31m(0)\033[0m and Podman \033[1;31m(1)\033[0m seem to be installed, which would you like to use?"
echo -n -e "\033[1;31m(0, 1)\033[0m - "
read choice
invalid=1
# Caseing the choice for whether the user wants to use Podman or Docker
case $choice in
0)
run_docker
;;
1)
run_podman
;;
# If the user entered an invalid option it'll loop
*)
echo "Invalid option selected, please try again. (Or press C-c to exit)..."
invalid=0
;;
esac
done
;;
# Default case for if something bad happens, and if something bad happens then something bad happened.
*)
echo "An Unknown Error occurred, please report this to the maintainers..."
;;
esac