Skip to content

Commit 6d68c73

Browse files
committed
Rewrite scripts and Makefile from scratch
1 parent 4073f8f commit 6d68c73

File tree

11 files changed

+594
-0
lines changed

11 files changed

+594
-0
lines changed

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export RELEASE_NAME ?= $(shell date +%Y%m%d)
2+
3+
rootfs-$(RELEASE_NAME).tar.gz:
4+
./make_rootfs.sh rootfs-$(RELEASE_NAME) $@
5+
6+
archlinux-xfce-pine64-$(RELEASE_NAME).img: rootfs-$(RELEASE_NAME).tar.gz
7+
./make_empty_image.sh $@
8+
./make_image.sh $@ $< u-boot-sunxi-with-spl-pine64.bin
9+
10+
archlinux-xfce-sopine-$(RELEASE_NAME).img: rootfs-$(RELEASE_NAME).tar.gz
11+
./make_empty_image.sh $@
12+
./make_image.sh $@ $< u-boot-sunxi-with-spl-sopine.bin
13+
14+
archlinux-xfce-pinebook-$(RELEASE_NAME).img: rootfs-$(RELEASE_NAME).tar.gz
15+
./make_empty_image.sh $@
16+
./make_image.sh $@ $< u-boot-sunxi-with-spl-pinebook.bin
17+
18+
.PHONY: archlinux-xfce-pine64
19+
archlinux-xfce-pine64: archlinux-xfce-pine64-$(RELEASE_NAME).img
20+
21+
.PHONY: archlinux-xfce-sopine
22+
archlinux-xfce-sopine: archlinux-xfce-sopine-$(RELEASE_NAME).img
23+
24+
.PHONY: archlinux-xfce-pinebook
25+
archlinux-xfce-pinebook: archlinux-xfce-pinebook-$(RELEASE_NAME).img

do_chroot.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
if [ "$(id -u)" -ne "0" ]; then
7+
echo "This script requires root."
8+
exit 1
9+
fi
10+
11+
cleanup() {
12+
if [ -e "$DEST/proc/cmdline" ]; then
13+
umount "$DEST/proc"
14+
fi
15+
if [ -d "$DEST/sys/kernel" ]; then
16+
umount "$DEST/sys"
17+
fi
18+
umount "$DEST/dev" || true
19+
umount "$DEST/tmp" || true
20+
}
21+
trap cleanup EXIT
22+
23+
DEST=rootfs-20180912
24+
25+
mount -o bind /tmp "$DEST/tmp"
26+
mount -o bind /dev "$DEST/dev"
27+
chroot "$DEST" mount -t proc proc /proc
28+
chroot "$DEST" mount -t sysfs sys /sys
29+
#chroot "$DEST" mv /etc/resolv.conf /etc/resolv.conf.dist
30+
cp /etc/resolv.conf $DEST/etc/resolv.conf
31+
chroot "$DEST" $@
32+
#chroot "$DEST" mv /etc/resolv.conf.dist /etc/resolv.conf
33+
chroot "$DEST" umount /sys
34+
chroot "$DEST" umount /proc
35+
umount "$DEST/dev"
36+
umount "$DEST/tmp"

make_empty_image.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
set -x
4+
set -e
5+
6+
IMAGE_NAME="$1"
7+
IMAGE_SIZE=6144M
8+
PART_POSITION=20480 # K
9+
FAT_SIZE=100 #M
10+
SWAP_SIZE=2048 # M
11+
12+
if [ -z "$IMAGE_NAME" ]; then
13+
echo "Usage: $0 <image name>"
14+
exit 1
15+
fi
16+
17+
fallocate -l $IMAGE_SIZE $IMAGE_NAME
18+
19+
cat << EOF | fdisk $IMAGE_NAME
20+
o
21+
n
22+
p
23+
1
24+
$((PART_POSITION*2))
25+
+${FAT_SIZE}M
26+
t
27+
c
28+
n
29+
p
30+
2
31+
$((PART_POSITION*2+FAT_SIZE*1024*2))
32+
+${SWAP_SIZE}M
33+
t
34+
2
35+
82
36+
n
37+
p
38+
3
39+
$((PART_POSITION*2+FAT_SIZE*1024*2+SWAP_SIZE*1024*2))
40+
41+
t
42+
3
43+
83
44+
a
45+
3
46+
w
47+
EOF

make_image.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
6+
IMAGE_NAME="$1"
7+
TARBALL="$2"
8+
BOOTLOADER="$3"
9+
10+
if [ -z "$IMAGE_NAME" ] || [ -z "$TARBALL" ] || [ -z "$BOOTLOADER" ]; then
11+
echo "Usage: $0 <image name> <tarball> <bootloader>"
12+
exit 1
13+
fi
14+
15+
if [ "$(id -u)" -ne "0" ]; then
16+
echo "This script requires root."
17+
exit 1
18+
fi
19+
20+
echo "Attaching loop device"
21+
LOOP_DEVICE=$(losetup -f)
22+
losetup -P $LOOP_DEVICE $IMAGE_NAME
23+
24+
echo "Creating filesystems"
25+
mkfs.vfat ${LOOP_DEVICE}p1
26+
mkswap ${LOOP_DEVICE}p2
27+
mkfs.ext4 ${LOOP_DEVICE}p3
28+
29+
TEMP_ROOT=$(mktemp -d)
30+
mkdir -p $TEMP_ROOT
31+
echo "Mounting rootfs"
32+
mount ${LOOP_DEVICE}p3 $TEMP_ROOT
33+
34+
echo "Unpacking rootfs archive"
35+
bsdtar -xpf "$TARBALL" -C "$TEMP_ROOT"
36+
37+
echo "Installing bootloader"
38+
dd if=$TEMP_ROOT/boot/$BOOTLOADER of=${LOOP_DEVICE} bs=8k seek=1
39+
40+
echo "Unmounting rootfs"
41+
umount $TEMP_ROOT
42+
rm -rf $TEMP_ROOT
43+
44+
# Detach loop device
45+
losetup -d $LOOP_DEVICE

make_rootfs.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
BUILD="build"
6+
OTHERDIR="otherfiles"
7+
DEST="$1"
8+
OUT_TARBALL="$2"
9+
BUILD_ARCH=arm64
10+
11+
export LC_ALL=C
12+
13+
if [ -z "$DEST" ] || [ -z "$OUT_TARBALL" ]; then
14+
echo "Usage: $0 <destination-folder> <destination-tarball>"
15+
exit 1
16+
fi
17+
18+
if [ "$(id -u)" -ne "0" ]; then
19+
echo "This script requires root."
20+
exit 1
21+
fi
22+
23+
DEST=$(readlink -f "$DEST")
24+
25+
if [ ! -d "$DEST" ]; then
26+
mkdir -p $DEST
27+
fi
28+
29+
if [ "$(ls -A -Ilost+found $DEST)" ]; then
30+
echo "Destination $DEST is not empty. Aborting."
31+
exit 1
32+
fi
33+
34+
TEMP=$(mktemp -d)
35+
cleanup() {
36+
if [ -e "$DEST/proc/cmdline" ]; then
37+
umount "$DEST/proc"
38+
fi
39+
if [ -d "$DEST/sys/kernel" ]; then
40+
umount "$DEST/sys"
41+
fi
42+
umount "$DEST/dev" || true
43+
umount "$DEST/tmp" || true
44+
if [ -d "$TEMP" ]; then
45+
rm -rf "$TEMP"
46+
fi
47+
}
48+
trap cleanup EXIT
49+
50+
ROOTFS="http://archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz"
51+
TAR_OPTIONS=""
52+
53+
mkdir -p $BUILD
54+
TARBALL="$BUILD/$(basename $ROOTFS)"
55+
56+
mkdir -p "$BUILD"
57+
if [ ! -e "$TARBALL" ]; then
58+
echo "Downloading $DISTRO rootfs tarball ..."
59+
wget -O "$TARBALL" "$ROOTFS"
60+
fi
61+
62+
# Extract with BSD tar
63+
echo -n "Extracting ... "
64+
set -x
65+
bsdtar -xpf $TAR_OPTIONS "$TARBALL" -C "$DEST"
66+
echo "OK"
67+
68+
# Add qemu emulation.
69+
cp /usr/bin/qemu-aarch64-static "$DEST/usr/bin"
70+
cp /usr/bin/qemu-arm-static "$DEST/usr/bin"
71+
72+
do_chroot() {
73+
cmd="$@"
74+
mount -o bind /tmp "$DEST/tmp"
75+
mount -o bind /dev "$DEST/dev"
76+
chroot "$DEST" mount -t proc proc /proc
77+
chroot "$DEST" mount -t sysfs sys /sys
78+
chroot "$DEST" $cmd
79+
chroot "$DEST" umount /sys
80+
chroot "$DEST" umount /proc
81+
umount "$DEST/dev"
82+
umount "$DEST/tmp"
83+
}
84+
85+
mv "$DEST/etc/resolv.conf" "$DEST/etc/resolv.conf.dist"
86+
cp /etc/resolv.conf "$DEST/etc/resolv.conf"
87+
sed -i 's|CheckSpace|#CheckSpace|' "$DEST/etc/pacman.conf"
88+
89+
cat >> "$DEST/etc/pacman.conf" <<EOF
90+
[pine64-mainline]
91+
SigLevel = Never
92+
Server = https://github.com/anarsoul/PKGBUILDs/releases/download/mainline/
93+
EOF
94+
95+
cat > "$DEST/second-phase" <<EOF
96+
#!/bin/sh
97+
pacman-key --init
98+
pacman-key --populate archlinuxarm
99+
killall -KILL gpg-agent
100+
pacman -Sy --noconfirm
101+
pacman -Rsn --noconfirm linux-aarch64
102+
pacman -S --noconfirm --needed dosfstools curl xz iw rfkill netctl dialog wpa_supplicant alsa-utils \
103+
pv linux-pine64 linux-pine64-headers networkmanager dkms-rtl8723cs uboot-pine64-git
104+
105+
# Install XFCE
106+
pacman -S --noconfirm xfce4 xorg-server xf86-input-libinput lxdm ttf-dejavu ttf-liberation firefox \
107+
pulseaudio nm-connection-editor network-manager-applet \
108+
xfce4-pulseaudio-plugin \
109+
pulseaudio-alsa pavucontrol
110+
systemctl enable lxdm
111+
systemctl enable NetworkManager
112+
usermod -a -G network,video,audio,optical,storage,input,scanner,games,lp alarm
113+
114+
sed -i 's|^#en_US.UTF-8|en_US.UTF-8|' /etc/locale.gen
115+
cd /usr/share/i18n/charmaps
116+
# locale-gen can't spawn gzip when running under qemu-user, so ungzip charmap before running it
117+
# and then gzip it back
118+
gzip -d UTF-8.gz
119+
locale-gen
120+
gzip UTF-8
121+
yes | pacman -Scc
122+
EOF
123+
chmod +x "$DEST/second-phase"
124+
do_chroot /second-phase
125+
rm $DEST/second-phase
126+
127+
# Final touches
128+
rm "$DEST/usr/bin/qemu-aarch64-static"
129+
rm "$DEST/usr/bin/qemu-arm-static"
130+
mv "$DEST/etc/resolv.conf.dist" "$DEST/etc/resolv.conf"
131+
132+
cp $OTHERDIR/asound.state $DEST/var/lib/alsa
133+
cp $OTHERDIR/pine64_first_boot.sh $DEST/usr/local/sbin/
134+
cp $OTHERDIR/resize_rootfs.sh $DEST/usr/local/sbin/
135+
cp $OTHERDIR/pine64-first-boot.service $DEST/etc/systemd/system/
136+
cp $OTHERDIR/modesetting.conf $DEST/etc/X11/xorg.conf.d/
137+
cp $OTHERDIR/sysrq.conf $DEST/etc/sysctl.d/
138+
139+
echo "Installed rootfs to $DEST"
140+
141+
# Create tarball with BSD tar
142+
echo -n "Creating tarball ... "
143+
pushd .
144+
cd $DEST && bsdtar -czpf ../$OUT_TARBALL .
145+
popd
146+
rm -rf $DEST
147+
148+
set -x
149+
echo "Done"

0 commit comments

Comments
 (0)