forked from souk4711/hakoniwa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·179 lines (146 loc) · 3.89 KB
/
install.sh
File metadata and controls
executable file
·179 lines (146 loc) · 3.89 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
set -euo pipefail
command_exists() {
type "${1}" > /dev/null 2>&1
}
echo_info() {
echo -e "\e[1;34mINFO: $* \e[m"
}
echo_warn() {
echo -e "\e[1;33mWARN: $* \e[m"
}
echo_error() {
echo -e "\e[1;31mERROR: $* \e[m"
exit 1
}
get_arch() {
case $(uname -m) in
amd64|x86_64) echo "x86_64";;
aarch64|arm64) echo "aarch64";;
*) "NOT_SUPPORTED";;
esac
}
# shellcheck disable=SC1091
get_distro() {
if [ -f /etc/os-release ]; then
(
. /etc/os-release
if [ "${ID_LIKE-}" ]; then
for id_like in $ID_LIKE; do
case "$id_like" in arch | debian | fedora)
echo "$id_like"
return
;;
esac
done
fi
echo "$ID"
return
)
fi
}
install_deps() {
echo ""
echo_info "Installing dependencies..."
case $DISTRO in
arch)
echo "pacman -S --noconfirm libseccomp passt shadow"
sudo pacman -S --noconfirm libseccomp passt shadow
;;
debian)
echo "apt install -y libseccomp-dev passt uidmap"
sudo apt install -y libseccomp-dev passt uidmap
;;
fedora)
echo "dnf install -y libseccomp-devel passt shadow-utils"
sudo dnf install -y libseccomp-devel passt shadow-utils
;;
*)
echo_warn "distro $DISTRO is not supported, please manually install dependencies."
;;
esac
}
install_hakoniwa() {
echo ""
echo_info "Installing hakoniwa..."
filename="hakoniwa-$ARCH-unknown-linux-gnu.tar.gz"
url="https://github.com/souk4711/hakoniwa/releases/latest/download/$filename"
echo "curl -L --progress-bar -o $CACHE_DIR/$filename $url"
curl -L --progress-bar -o "$CACHE_DIR/$filename" "$url"
echo "tar -xzf $CACHE_DIR/$filename -C $CACHE_DIR"
tar -xzf "$CACHE_DIR/$filename" -C "$CACHE_DIR"
echo "cp $CACHE_DIR/hakoniwa /usr/bin/hakoniwa"
sudo cp "$CACHE_DIR/hakoniwa" /usr/bin/hakoniwa
}
configure_selinux() {
echo ""
echo_info "Configuring SELinux..."
if ! command_exists "getenforce"; then
echo "module SELinux not found. SKIPPING."
return
fi
case $DISTRO in
fedora)
echo "dnf install -y container-selinux"
sudo dnf install -y container-selinux
echo "chcon -u system_u -t container_runtime_exec_t /usr/bin/hakoniwa"
sudo chcon -u system_u -t container_runtime_exec_t /usr/bin/hakoniwa
;;
*)
echo_warn "distro $DISTRO is not supported, please manually configure SELinux."
;;
esac
}
configure_apparmor() {
echo ""
echo_info "Configuring AppArmor..."
if ! command_exists "apparmor_status"; then
echo "module AppArmor not found. SKIPPING."
return
fi
echo "cat <<EOF | tee /etc/apparmor.d/hakoniwa >/dev/null"
echo "# This profile allows everything and only exists to give the"
echo "......"
echo "EOF"
cat <<EOF | sudo tee /etc/apparmor.d/hakoniwa >/dev/null
# This profile allows everything and only exists to give the
# application a name instead of having the label "unconfined"
abi <abi/4.0>,
include <tunables/global>
profile hakoniwa /usr/bin/hakoniwa flags=(unconfined) {
userns,
# Site-specific additions and overrides. See local/README for details.
include if exists <local/hakoniwa>
}
EOF
if apparmor_status --enabled; then
echo "systemctl reload apparmor.service"
sudo systemctl reload apparmor.service
fi
}
main() {
if command_exists "/usr/bin/hakoniwa"; then
echo_warn "/usr/bin/hakoniwa already exists."
exit 0
fi
ARCH=${ARCH:-$(get_arch)}
DISTRO=${DISTRO:-$(get_distro)}
CACHE_DIR=$(mktemp -d)
echo_info "variables:"
echo "ARCH=$ARCH"
echo "DISTRO=$DISTRO"
echo "CACHE_DIR=$CACHE_DIR"
case $ARCH in
x86_64 | aarch64) ;;
*) echo_error "unsupported architecture: $ARCH.";;
esac
case $DISTRO in
arch | debian | fedora) ;;
*) echo_error "unsupported distro: $DISTRO.";;
esac
install_deps
install_hakoniwa
configure_selinux
configure_apparmor
}
main "$@"