generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dev.sh
executable file
·66 lines (56 loc) · 1.5 KB
/
dev.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
#!/usr/bin/env sh
set -e
dev_image=${DEV_IMAGE:-"ns8-dnsmasq-dev:18.19.1"}
container_name=ns8-dnsmasq-dev
build_image() {
podman build \
--force-rm \
--layers \
--target "$1" \
--tag "$2" \
.
}
if [ "$1" = "build" ]; then
build_image "dev" "$dev_image"
exit 0
fi
if ! podman image exists "$dev_image"; then
build_image "dev" "$dev_image"
fi
# params given will be appended at the end of the command
commands_given="$*"
shift "$#"
# setup podman command
set -- "$@" podman
if podman container exists $container_name; then
# base command to execute in container
set -- "$@" exec
# if terminal is interactive, add interactive and tty flags
if [ -t 0 ]; then
set -- "$@" --interactive --tty
fi
# add container name
set -- "$@" $container_name
else
# base command to create container
set -- "$@" run --name $container_name --replace --rm --volume "$(pwd)/ui":/app:Z
# if terminal is interactive, add interactive and tty flags
if [ -t 0 ]; then
set -- "$@" --interactive --tty
fi
# check if port 5173 is already in use, if not, add publish flag
if lsof -Pi :5173 -sTCP:LISTEN -t >/dev/null; then
echo "Something is listening on port 5173, you won't be able to reach dev build."
else
set -- "$@" --publish 5173:5173
fi
# add image name
set -- "$@" "$dev_image"
fi
# if commands_given are not zero, append them
if [ -n "$commands_given" ]; then
for command in $commands_given; do
set -- "$@" "$command"
done
fi
"$@"