-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpinfo.docker
executable file
·165 lines (145 loc) · 4.1 KB
/
pinfo.docker
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#! /usr/bin/env bash
set -eu
cd "$( dirname "$( readlink -e "${0}" )" )" || exit 1
# shellcheck disable=SC1091
[ ! -s common/vars.sh ] || . common/vars.sh
# shellcheck disable=SC2034 # Set from common/vars.sh
[[ -n "${__COMMON_VARS_INCLUDED:-}" ]] || {
echo >&2 "FATAL: Inclusion of common defaults failed"
exit 1
}
_command='docker'
if command -v podman >/dev/null 2>&1; then
_command='podman'
fi
# shellcheck disable=SC2034
declare IMAGE="none"
# shellcheck disable=SC1091
[ -s common/run.sh ] && . common/run.sh >/dev/null
_output=''
if ! [ -x "$( command -v "${_command}" )" ]; then
echo >&2 "FATAL: Cannot locate binary '${_command}'"
exit 1
elif ! _output="$( "${_command}" info 2>&1 )"; then
if [ "${_command}" = 'podman' ]; then
echo >&2 "FATAL: Unable to successfully execute" \
"'${_command}' - do you need to run '${_command}" \
"machine start' or re-run '$( basename "${0}" )' as" \
"'root'?"
else
echo >&2 "FATAL: Unable to successfully execute" \
"'${_command}' - do you need to re-run" \
"'$( basename "${0}" )' as 'root'?"
fi
exit 1
elif [ "$( uname -s )" != 'Darwin' ] &&
[ $(( $( id -u ) )) -ne 0 ] &&
echo "${_output}" | grep -Fq -- 'rootless: false'
then
echo >&2 "FATAL: Please re-run '$( basename "${0}")' as user 'root'"
exit 1
fi
unset _output
declare CATEGORY='app-text'
declare PN='pinfo'
declare page_volume="${PN}-pages"
# FIXME: shellcheck wants:
#
# docker_extra_mounts+=( $( add_mount ... ) )
#
# ... to be expressed in the form of:
#
# readarray -O "${#docker_extra_mounts[@]}" -t docker_extra_mounts < <(
# add_mount ...
# )
#
# shellcheck disable=SC2207
{
declare -a docker_extra_mounts=()
docker_extra_mounts+=( $( add_mount --print \
'/usr/share/info/' \
'/srv/host/...'
) ) || :
# shellcheck disable=SC2116
if [[ -n "${INFOPATH:-}" ]]; then
for e in $( echo "${INFOPATH//:/ }" ); do
if [[ -d "${e}" ]]; then
docker_extra_mounts+=( $( add_mount --print \
"${e}" \
'/srv/host/...'
) ) || :
fi
done
fi
export DOCKER_EXTRA_MOUNTS="${docker_extra_mounts[*]:-}"
unset docker_extra_mounts
}
declare f=''
for f in /etc/pinforc /etc/pinfo/pinforc /etc/pinfo/pinfo.rc; do
[ -s "${f}" ] && break
done
if [ -s "${f}" ]; then
DOCKER_VOLUMES="
--volume ${f}:/etc/pinforc:ro
"
fi
unset f
if [[ -n "${DEV_MODE:-}" ]]; then
DOCKER_VOLUMES+=" --volume ${PWD}/${base_dir:+"${base_dir}/"}entrypoint.sh.service:/usr/libexec/entrypoint.sh:ro"
fi
# Gather exported data from other created containers ...
id=''
for id in $( # <- Syntax
podman container ps \
--all \
--filter 'name=^openrc-' \
--filter 'name=^web-' \
--format '{{.ID}}'
); do
DOCKER_VOLUMES+=" --volumes-from ${id}:ro"
done
unset id
# Confusingly, if a volume is mounted from the host then the host contents are
# exposed in the container (even if there are none), but if a (new)
# named-volume is referenced then on first use the container contents are
# mirrored into the named-volume instead...
#
DOCKER_VOLUMES=" --volume ${page_volume}:/srv/${PN}/usr/share/info"
export DOCKER_VOLUMES
#DOCKER_SCRIPT="$( cat <<-EOF
# set -eux ;
# echo "Detected terminal size: \$( stty size )" ;
# export TERM LINES COLUMNS ;
# echo "Setting terminal to \${COLUMNS}x\${LINES}..." ;
# stty cols "\${COLUMNS}" rows "\${LINES}" ;
# echo "Detected terminal size: \$( stty size )" ;
# echo "args: \${@}"
# exec /usr/bin/pinfo "\${@}"
#EOF
#)"
#nl="$( printf '\n' )"
#DOCKER_SCRIPT="$( echo "${DOCKER_SCRIPT}" | tr "${nl}" ' ' )"
#unset nl
declare -a docker_cmd_vars=()
docker_cmd_vars=(
--env "LINES=${LINES}"
--env "COLUMNS=${COLUMNS}"
--env "TERM=${TERM}"
)
export DOCKER_CMD_VARS="${docker_cmd_vars[*]:-}"
unset docker_cmd_vars
export DOCKER_INTERACTIVE=1
export NO_BUILD_MOUNTS='no_build_mounts' # ... any value will do
#export DOCKER_ENTRYPOINT='/bin/sh'
_docker_resolve "${CATEGORY}/${PN}" 'service' >/dev/null
image="$( _docker_image_exists )"
export image
#set -o xtrace
if [[ -n "${*:-}" ]]; then
#_docker_run -c "${DOCKER_SCRIPT}" ${@+"${@}"}
_docker_run ${@+"${@}"}
else
#_docker_run -c "${DOCKER_SCRIPT}" 'dir'
_docker_run 'dir'
fi
# vi: set colorcolumn=80 syntax=sh: