-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_server.sh
executable file
·198 lines (154 loc) · 5.68 KB
/
build_server.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
set -ex
# Install required packages if host Debian/Ubuntu
if [[ -d /var/lib/apt/ ]] ; then
cp /etc/apt/sources.list /etc/apt/sources.list.d/noble.list
sed -i s/jammy/noble/g /etc/apt/sources.list.d/noble.list
apt update
apt -t noble install arch-install-scripts pacman-package-manager archlinux-keyring makepkg -y
apt -t jammy install wget qemu-user-static binfmt-support wget unzip qemu-utils -y
fi
mkdir -p misilix
# Create a temporary pacman.conf for bootstrapping
[[ -f pacman.conf ]] || cat > pacman.conf << EOF
[options]
Architecture = aarch64
Color
ILoveCandy
VerbosePkgLists
ParallelDownloads = 5
SigLevel = Never TrustAll
[core]
Server = http://mirror.archlinuxarm.org/\$arch/\$repo/
[extra]
Server = http://mirror.archlinuxarm.org/\$arch/\$repo/
[alarm]
Server = http://mirror.archlinuxarm.org/\$arch/\$repo/
[aur]
Server = http://mirror.archlinuxarm.org/\$arch/\$repo/
[pkgbuild-ci]
SigLevel = Optional TrustAll
Server = https://github.com/misile00/misilix/releases/download/pkgbuild-ci
EOF
# Initialize pacman keyring and populate Arch Linux keyring
pacman-key --init && pacman-key --populate archlinux
# Create Rootfs
[[ -f misilix/etc/os-release ]] || cat pkglist_server.txt | pacstrap -MGC ./pacman.conf misilix -
cat > misilix/boot/config.txt << EOF
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details
initramfs initramfs-linux.img followkernel
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
#core_freq=250
#sdram_freq=400
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Uncomment to enable bluetooth
#dtparam=krnbt=on
# Early boot delay in the hope monitors are initialised enough to provide EDID
bootcode_delay=1
# We need this to be 32Mb to support VCHI services and drivers which use them
# but this isn't used by mainline VC4 driver so reduce to lowest supported value
# You need to set this to at least 80 for using the camera
# gpu_mem=32
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Run in 64-bit mode
arm_64bit=1
# Disable compensation for displays with overscan
disable_overscan=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[pi4]
# Run as fast as firmware / board allows
arm_boost=1
EOF
if which service ; then
service binfmt-support start
fi
# Configure system
cp usr/local/resize-fs.sh misilix/usr/local/
cp -r etc/* misilix/etc/
chmod a+x misilix/etc/profile.d/pacman-init.sh misilix/usr/local/resize-fs.sh
chroot misilix /usr/bin/systemctl enable resize-fs.service NetworkManager.service sshd.service avahi-daemon.service
sed -i s/#NTP=/NTP=0.pool.ntp.org/g misilix/etc/systemd/timesyncd.conf
echo -e "\nC.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nen_US ISO-8859-1" >> misilix/etc/locale.gen
echo "LANG=en_US.UTF-8" > misilix/etc/locale.conf
echo "KEYMAP=trq" > misilix/etc/vconsole.conf
echo -e "nameserver 8.8.8.8\nnameserver 8.8.8.4" > misilix/etc/resolv.conf
echo "%wheel ALL=(ALL:ALL) NOPASSWD: ALL" > misilix/etc/sudoers.d/10-nopasswd
echo "Defaults env_reset,pwfeedback" > misilix/etc/sudoers.d/10-pwfeedback
chroot misilix /usr/bin/locale-gen
# Create default user accounts
chroot misilix /bin/bash -c "useradd alarm -mUG wheel -m -u 1000"
echo -e "root\nroot\n" | chroot misilix /bin/bash -c "passwd root"
echo -e "alarm\nalarm\n" | chroot misilix /bin/bash -c "passwd alarm"
find misilix/var/log/ -type f | xargs rm -f
chroot misilix /bin/bash -c "pacman -Scc --noconfirm"
# Create image
size=$(echo "($(du -s "misilix" | cut -f 1) * 1.5) / 1" | bc)
qemu-img create "misilix-server.img" ${size}k
parted -s "misilix-server.img" mklabel msdos
parted -s "misilix-server.img" mkpart primary fat32 0 300M
parted -s "misilix-server.img" mkpart primary btrfs 301M 100%
# Format image
losetup -d /dev/loop0 || true
loop=$(losetup --partscan --find --show "misilix-server.img" | grep "/dev/loop")
mkfs.vfat ${loop}p1 -n "BOOT_MSL"
mkfs.btrfs ${loop}p2 -L "ROOT_MSL"
# Copy boot partition
mount ${loop}p1 /mnt
cp -prfv misilix/boot/* /mnt/ 2>&1 > /dev/null
sync
umount -f /mnt
# Copy rootfs partition
mount ${loop}p2 /mnt
cp -prfv misilix/* /mnt/ 2>&1 > /dev/null
sync
umount /mnt
losetup -d /dev/loop0
xz -T0 misilix-server.img
# Done