This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·137 lines (121 loc) · 3.22 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·137 lines (121 loc) · 3.22 KB
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
132
133
134
135
136
137
#!/bin/sh
# vim:set tabstop=8 shiftwidth=4 expandtab:
# kate: space-indent on; indent-width 4;
# shellcheck disable=SC2039
#
# Copyright (c) 2022 Jakob Meng, <jakobmeng@web.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# NOTE: declare local variables first and initialize them later because return code of "local ..." is always 0
set -e
#set -x
stderr() {
local _msg
while read -r _msg
do
echo "$_msg" 1>&2
done
}
error() {
stderr << ____EOF
ERROR: $*
____EOF
}
warn() {
stderr << ____EOF
WARN: $*
____EOF
}
# shellcheck disable=SC2120
auto() {
if command -v docker >/dev/null 2>&1; then
docker "$@"
else
error "docker not found"
return 255
fi
}
docker() {
local _debug=""
local _targets=""
local _volumes=""
while [ -n "$1" ]; do
case "$1" in
"--debug")
_debug="yes"
;;
"-v"|"--volume")
if [ -z "$2" ]; then
error "flag $1 is missing arg"
return 255
fi
_volumes="$_volumes '$1' '$2'"
shift
;;
-*)
error "unknown flag: $1"
return 255
;;
*)
_targets="$*"
set -- 'FOR_NEXT_SHIFT_ONLY'
;;
esac
shift
done
[ "$_debug" = "yes" ] && set -x
# find project root directory
local _dir=""
_dir="$(dirname "$(readlink -e "$0")")"
local _namespace=jm1337
local _repository=bootstrap-docker
local _tag=bookworm
# build container image if it does not exist
if [ -z "$(command docker image ls -q "$_namespace/$_repository:$_tag")" ]; then
command docker build --pull=true \
-t "$_namespace/$_repository:$_tag-$(date +%Y%m%d)" \
-t "$_namespace/$_repository:$_tag" \
"$_dir/$_repository:$_tag"
fi
eval command docker run -ti --rm \
--security-opt no-new-privileges --cap-drop ALL --cap-add CAP_DAC_READ_SEARCH \
-v "/var/run/docker.sock:/var/run/docker.sock:rw" \
"$_volumes" \
--name "${_namespace}-${_repository}-${_tag}" \
"$_namespace/$_repository:$_tag" \
"$_targets"
}
if [ $# -eq 0 ]; then
# shellcheck disable=SC2119
auto
exit
fi
while [ -n "$1" ]; do
case "$1" in
"auto"|"docker")
("$@")
exit
;;
-*)
error "unknown flag: $1"
exit 1
;;
*)
error "unknown command: $1"
exit 1
;;
esac
shift
done