-
Notifications
You must be signed in to change notification settings - Fork 0
/
containerize.sh
executable file
·83 lines (66 loc) · 1.96 KB
/
containerize.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -o errexit
set -o nounset
CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CURRENT_FILE=$(basename "${BASH_SOURCE[0]}")
REPO_NAME=$(basename $CURRENT_DIR)
OPTS=$(getopt --name $CURRENT_FILE --options r: --longoptions runtime: -- "$@")
eval set -- "$OPTS"
unset OPTS
while true; do
case $1 in
-r|--runtime)
RUNTIME=$2
shift 2
;;
--)
shift
break
;;
esac
done
DISTRO=${1%:*}
TAG=${1#*:}
DOCKERFILE=$CURRENT_DIR/.generated/$DISTRO/$TAG/Dockerfile
USER_ID=$(id -u)
USER_NAME=$(id -un)
create-dockerfile() {
mkdir -p $CURRENT_DIR/.generated/$DISTRO/$TAG
rm -rf $DOCKERFILE
write "FROM docker.io/library/$DISTRO:$TAG"
base-package-for-$DISTRO
write "ENV LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8"
locale-for-$DISTRO
write "RUN useradd -u $USER_ID -U -m $USER_NAME"
write "RUN sed -i 's/^SHELL=\/bin\/sh/SHELL=\/usr\/bin\/zsh/g' /etc/default/useradd"
write "RUN echo '$USER_NAME ALL=(root) NOPASSWD:ALL' >> /etc/sudoers.d/$USER_NAME"
write "RUN chmod 0440 /etc/sudoers.d/$USER_NAME"
write "USER $USER_NAME"
write "WORKDIR /home/$USER_NAME"
write "COPY --chown=$USER_NAME:$USER_NAME . $CURRENT_DIR"
write "RUN dbus-run-session $CURRENT_DIR/setup.sh"
}
base-package-for-ubuntu() {
base-package-for-debian
}
locale-for-ubuntu() {
locale-for-debian
}
base-package-for-debian() {
write "RUN apt-get update && apt-get install -y dbus locales sudo"
}
locale-for-debian() {
write "RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen"
}
base-package-for-fedora() {
write "RUN dnf install --assumeyes glibc-locale-source glibc-langpack-en dbus-daemon"
}
locale-for-fedora() {
write "RUN localedef -i en_US -f UTF-8 en_US.UTF-8"
}
write() {
echo $1 >> $DOCKERFILE
}
create-dockerfile
${RUNTIME:-podman} build -f $DOCKERFILE -t localhost/my-dot-file-container:$DISTRO-$TAG $CURRENT_DIR
echo "localhost/my-dot-file-container:$DISTRO-$TAG has been built successfully"