-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathharbor.sh
114 lines (96 loc) · 4.91 KB
/
harbor.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
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
#!/bin/sh
#############################
# Alpine Linux Installation #
#############################
# Define the root directory to /home/container.
# We can only write in /home/container and /tmp in the container.
ROOTFS_DIR=/home/container
# Define the Alpine Linux version we are going to be using.
ALPINE_VERSION="3.18"
ALPINE_FULL_VERSION="3.18.3"
APK_TOOLS_VERSION="2.14.0-r2" # Make sure to update this too when updating Alpine Linux.
PROOT_VERSION="5.3.0" # Some releases do not have static builds attached.
# Detect the machine architecture.
ARCH=$(uname -m)
# Check machine architecture to make sure it is supported.
# If not, we exit with a non-zero status code.
if [ "$ARCH" = "x86_64" ]; then
ARCH_ALT=amd64
elif [ "$ARCH" = "aarch64" ]; then
ARCH_ALT=arm64
else
printf "Unsupported CPU architecture: ${ARCH}"
exit 1
fi
# Download & decompress the Alpine linux root file system if not already installed.
if [ ! -e $ROOTFS_DIR/.installed ]; then
# Download Alpine Linux root file system.
curl -Lo /tmp/rootfs.tar.gz \
"https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/releases/${ARCH}/alpine-minirootfs-${ALPINE_FULL_VERSION}-${ARCH}.tar.gz"
# Extract the Alpine Linux root file system.
tar -xzf /tmp/rootfs.tar.gz -C $ROOTFS_DIR
fi
################################
# Package Installation & Setup #
################################
# Download static APK-Tools temporarily because minirootfs does not come with APK pre-installed.
if [ ! -e $ROOTFS_DIR/.installed ]; then
# Download the packages from their sources.
curl -Lo /tmp/apk-tools-static.apk "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/main/${ARCH}/apk-tools-static-${APK_TOOLS_VERSION}.apk"
curl -Lo /tmp/gotty.tar.gz "https://github.com/sorenisanerd/gotty/releases/download/v1.5.0/gotty_v1.5.0_linux_${ARCH_ALT}.tar.gz"
curl -Lo $ROOTFS_DIR/usr/local/bin/proot "https://github.com/proot-me/proot/releases/download/v${PROOT_VERSION}/proot-v${PROOT_VERSION}-${ARCH}-static"
# Extract everything that needs to be extracted.
tar -xzf /tmp/apk-tools-static.apk -C /tmp/
tar -xzf /tmp/gotty.tar.gz -C $ROOTFS_DIR/usr/local/bin
# Install base system packages using the static APK-Tools.
/tmp/sbin/apk.static -X "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/main/" -U --allow-untrusted --root $ROOTFS_DIR add alpine-base apk-tools
# Make PRoot and GoTTY executable.
chmod 755 $ROOTFS_DIR/usr/local/bin/proot $ROOTFS_DIR/usr/local/bin/gotty
fi
# Clean-up after installation complete & finish up.
if [ ! -e $ROOTFS_DIR/.installed ]; then
# Add DNS Resolver nameservers to resolv.conf.
printf "nameserver 1.1.1.1\nnameserver 1.0.0.1" > ${ROOTFS_DIR}/etc/resolv.conf
# Wipe the files we downloaded into /tmp previously.
rm -rf /tmp/apk-tools-static.apk /tmp/rootfs.tar.gz /tmp/sbin
# Create .installed to later check whether Alpine is installed.
touch $ROOTFS_DIR/.installed
fi
# Print some useful information to the terminal before entering PRoot.
# This is to introduce the user with the various Alpine Linux commands.
clear && cat << EOF
██╗ ██╗ █████╗ ██████╗ ██████╗ ██████╗ ██████╗
██║ ██║██╔══██╗██╔══██╗██╔══██╗██╔═══██╗██╔══██╗
███████║███████║██████╔╝██████╔╝██║ ██║██████╔╝
██╔══██║██╔══██║██╔══██╗██╔══██╗██║ ██║██╔══██╗
██║ ██║██║ ██║██║ ██║██████╔╝╚██████╔╝██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
Welcome to Alpine Linux minirootfs!
This is a lightweight and security-oriented Linux distribution that is perfect for running high-performance applications.
Here are some useful commands to get you started:
apk add [package] : install a package
apk del [package] : remove a package
apk update : update the package index
apk upgrade : upgrade installed packages
apk search [keyword] : search for a package
apk info [package] : show information about a package
gotty -p [server-port] -w ash : share your terminal
If you run into any issues make sure to report them on GitHub!
https://github.com/RealTriassic/Harbor
EOF
###########################
# Start PRoot environment #
###########################
# This command starts PRoot and binds several important directories
# from the host file system to our special root file system.
$ROOTFS_DIR/usr/local/bin/proot \
--rootfs="${ROOTFS_DIR}" \
--link2symlink \
--kill-on-exit \
--root-id \
--cwd=/root \
--bind=/proc \
--bind=/dev \
--bind=/sys \
--bind=/tmp \
/bin/sh