summaryrefslogtreecommitdiffstats
path: root/login.sh
blob: 9b9f8ec4c1e966c2b7c9543c9a5bd0ccf4b7967b (plain)
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
#!/bin/bash
set -Eeuo pipefail

if [[ -d "/secrets" ]]; then
	/usr/local/bin/devbox-template
fi

# Add some /dev devices
[ -d /dev/net ] || mkdir -p /dev/net

# Load the required kernel modules
for mod in loop overlay veth bridge; do
	modprobe -q "$mod" 2>/dev/null || true
done

function overlay_fs() {
	local storage="$1"
	local img="$2"
	local owner="$3"
	local size="40G"

	mkdir -p "$storage"
	chown -R "$owner" "$storage"
	local fstype="$(df -PT "$storage" | tail -1 | awk '{print $2}')"
	echo "$fstype"
	case "$fstype" in
		virtiofs | 9p | fuse* | nfs* | cifs | overlay) ;;
		*) return 0 ;;
	esac

	if mountpoint -q "$storage"; then
		return 0
	fi

	# Set us up for loopback
	[ -e /dev/loop-control ] || mknod /dev/loop-control c 10 237 || true
	for i in {0..7}; do
		[ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i || true
	done

	[ -e "$img" ] || truncate -s "$size" "$img"
	blkid "$img" >/dev/null 2>&1 || mkfs.ext4 -qF -O dir_index,extent,has_journal "$img"

	local loop="$(losetup -f --show "$img")"
	if ! mount -o noatime "$loop" "$storage"; then
		losetup -d "$loop"
		exit 1
	fi
	mount --make-rshared "$storage"
}

overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" "root:root" ||
	echo "/var/lib/containers/storage must be bind mounted to a real filesystem"
overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev" ||
	echo "/home/dev/.local/share/containers/storage must be bind mounted to a real filesystem"


chmod u+s /bin/newgidmap
chmod u+s /bin/newuidmap

if [ "$(cat /proc/self/cgroup 2>/dev/null)" = "0::/" ] && [ -w /sys/fs/cgroup ]; then
	for ctrl in $(cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null); do
		echo "+$ctrl" >/sys/fs/cgroup/cgroup.subtree_control 2>/dev/null || true
	done
	chown -R dev:dev /sys/fs/cgroup 2>/dev/null || true
fi

# if [[ -z "${PASEO_PASSWORD:-}" ]]; then
#     echo "PASEO_PASSWORD is required" >&2
#     exit 1
# fi

# echo "[devbox] starting Paseo daemon on ${PASEO_LISTEN} (web UI: ${PASEO_WEB_UI_ENABLED})"
# exec paseo daemon run
exec runuser -u dev -- /bin/bash