-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbop-container
executable file
·139 lines (115 loc) · 2.32 KB
/
bop-container
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
#! /usr/bin/env bash
# shellcheck disable=SC1117,SC2034,SC2154
################################################################################
NORM=0
BOLD=1
UNLN=4
RED=31
GREEN=32
YELLOW=33
BLUE=34
MAG=35
CYAN=36
GREY=37
DARK=90
CL_NORM="\e[0m"
CL_BOLD="\e[0;${BOLD};49m"
CL_UNLN="\e[0;${UNLN};49m"
CL_RED="\e[0;${RED};49m"
CL_GREEN="\e[0;${GREEN};49m"
CL_YELLOW="\e[0;${YELLOW};49m"
CL_BLUE="\e[0;${BLUE};49m"
CL_MAG="\e[0;${MAG};49m"
CL_CYAN="\e[0;${CYAN};49m"
CL_GREY="\e[0;${GREY};49m"
CL_DARK="\e[0;${DARK};49m"
CL_BL_RED="\e[1;${RED};49m"
CL_BL_GREEN="\e[1;${GREEN};49m"
CL_BL_YELLOW="\e[1;${YELLOW};49m"
CL_BL_BLUE="\e[1;${BLUE};49m"
CL_BL_MAG="\e[1;${MAG};49m"
CL_BL_CYAN="\e[1;${CYAN};49m"
CL_BL_GREY="\e[1;${GREY};49m"
################################################################################
IMAGE_DH="essentialkaos/bop:ol8"
IMAGE_GH="ghcr.io/essentialkaos/bop:ol8"
BOP_IMAGE="${IMAGE:-$IMAGE_GH}"
################################################################################
engine=""
################################################################################
# Main func
#
# *: All unparsed arguments passed to the script
#
# Code: No
# Echo: No
main() {
engine=$(getContainerEngine)
if [[ -z "$engine" ]] ; then
error "You must install Podman or Docker first"
exit 1
fi
run "$@"
exit $?
}
# Runs bop and generate recipe
#
# *: bop options and arguments
#
# Code: No
# Echo: No
run() {
local cwd
cwd=$(pwd)
# shellcheck disable=SC2086,SC2048
$engine run --rm -it -v "${cwd}:/bop" "$BOP_IMAGE" $*
return $?
}
# Get used container engine
#
# Code: No
# Echo: Engine name (String)
getContainerEngine() {
if hasApp "docker" ; then
echo "docker"
fi
if hasApp "podman" ; then
echo "podman"
fi
}
# Checks if given app is installed
#
# 1: Binray name (String)
#
# Code: Yes
# Echo: No
hasApp() {
type "$1" &> /dev/null
return $?
}
# Shows message
#
# 1: Message (String)
# 2: Message color (Number) [Optional]
#
# Code: No
# Echo: No
show() {
if [[ -n "$2" && -z "$no_colors" ]] ; then
echo -e "\e[${2}m${1}\e[0m"
else
echo -e "$*"
fi
}
# Shows error message
#
# 1: Message (String)
# 2: Message color (Number) [Optional]
#
# Code: No
# Echo: No
error() {
show "$@" 1>&2
}
################################################################################
main "$@"