/
1.rootfs
executable file
·89 lines (58 loc) · 2.17 KB
/
1.rootfs
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
#############
[ -d "rootfs" ] && exit 1
[ -f "/usr/bin/busybox" ] || exit 1
[ -f "binhost/stage3.tar.xz" ] || exit 1
#############
install -d -o 0 -g 0 -m 0755 "rootfs"
/usr/bin/busybox tar xf "binhost/stage3.tar.xz" -C "rootfs"
install -o 0 -g 0 -m 0755 "/usr/bin/busybox" "rootfs/usr/bin/busybox"
ln -sf "/usr/bin/busybox" "rootfs/usr/bin/ash"
cd "rootfs" || exit 1
#############
### users
sed -i '/^root/c root:x:0:0::/root:/usr/bin/ash' "etc/passwd"
sed -i '/^root/c root:x:0:' "etc/group"
sed -i '/^root/c root:!:::::::' "etc/shadow"
install -d -o 0 -g 0 -m 0700 "root"
chown -R 0:0 "root"
find "root" -type d -exec chmod 0700 {} \;
find "root" -type f -exec chmod 0600 {} \;
sed -i '/^nobody/c nobody:x:65534:65534::/var/empty:/usr/bin/ash' "etc/passwd"
sed -i '/^nobody/c nobody:x:65534:' "etc/group"
sed -i '/^nobody/c nobody:!:::::::' "etc/shadow"
install -d -o 65534 -g 65534 -m 0700 "var/empty"
chown -R 65534:65534 "var/empty"
find "var/empty" -type d -exec chmod 0700 {} \;
find "var/empty" -type f -exec chmod 0600 {} \;
### locale
ln -sf "/usr/share/zoneinfo/UTC" "etc/localtime"
printf "%s\n" "en_GB.UTF-8 UTF-8" > "etc/locale.gen"
chroot . locale-gen
### config
ln -sf "/root/config/etc/profile" "etc/profile"
[ -d "etc/scripts" ] && rm -rf "etc/scripts"
ln -sf "/root/config/etc/scripts" "etc/scripts"
[ -d "etc/portage" ] && rm -rf "etc/portage"
ln -sf "/root/portage" "etc/portage"
### network
printf "%s\n" "search localdomain" > "etc/resolv.conf"
printf "%s\n" "options edns0" >> "etc/resolv.conf" # no-aaaa
printf "%s\n" "nameserver 127.0.0.1" >> "etc/resolv.conf"
chown 0:0 "etc/resolv.conf"
chmod 0644 "etc/resolv.conf"
### cleanup
find . -type f -name '._cfg*' -exec rm {} \;
find . -type f -name '.keep*' -exec rm {} \;
find . -perm -4000 -exec chmod u-s {} \;
find . -perm -2000 -exec chmod g-s {} \;
find . -perm -1000 -exec chmod -t {} \;
[ -d "boot" ] && rm -rf "boot"
[ -d "home" ] && rm -rf "home"
[ -d "media" ] && rm -rf "media"
[ -d "mnt" ] && rm -rf "mnt"
[ -d "opt" ] && rm -rf "opt"
[ -d "run" ] && rm -rf "run"
[ -d "usr/local" ] && rmdir usr/local/*
[ -d "usr/local" ] && rmdir usr/local
[ -d "var/spool" ] && rmdir var/spool
#############