diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-22 21:56:04 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-22 21:56:04 +0000 |
commit | 82d0f92ab8b84466ae20ab919c1f9c3577b5cecb (patch) | |
tree | 776015ae6c6a386125b2d39e13b62f91b99548f8 /sub/layout | |
download | lh-bootstrap-82d0f92ab8b84466ae20ab919c1f9c3577b5cecb.tar.xz |
Initial commit
Diffstat (limited to 'sub/layout')
-rw-r--r-- | sub/layout/Makefile | 14 | ||||
-rwxr-xr-x | sub/layout/configure-localoptions | 20 | ||||
-rwxr-xr-x | sub/layout/copylayout | 70 | ||||
-rw-r--r-- | sub/layout/permissions | 18 |
4 files changed, 122 insertions, 0 deletions
diff --git a/sub/layout/Makefile b/sub/layout/Makefile new file mode 100644 index 0000000..e8772b5 --- /dev/null +++ b/sub/layout/Makefile @@ -0,0 +1,14 @@ + +# copies our pre-made layout ("copylayout") in /layout to the output directory +# add our local options to the layout ("configure-localoptions") +$(OUTPUT)/tmp/.lh_layout_copied: $(OUTPUT)/tmp/.lh_prepared layout | $(OUTPUT)/build-build/.lh_skarnet_installed + exec sub/layout/copylayout $(OUTPUT) + exec sub/layout/configure-localoptions $(OUTPUT) $(COUNTRY_CODE) $(LOCAL_IP) $(ROUTER_IP) + exec setuidgid $(NORMALUSER) s6-touch $@ + +$(OUTPUT)/tmp/.lh_layout_s6rcdb_made: $(OUTPUT)/tmp/.lh_layout_copied | $(OUTPUT)/build-build/.lh_skarnet_installed + stamp=$$(s6-clock) && s6-rc-compile -v2 -h sysfdh $(OUTPUT)/rootfs/etc/s6-rc/compiled-$$stamp $(OUTPUT)/rootfs/etc/s6-rc/source-base && s6-ln -s compiled-$$stamp $(OUTPUT)/rootfs/etc/s6-rc/compiled.new && s6-rename $(OUTPUT)/rootfs/etc/s6-rc/compiled.new $(OUTPUT)/rootfs/etc/s6-rc/compiled + exec setuidgid $(NORMALUSER) s6-touch $@ + +$(OUTPUT)/tmp/.lh_layout_installed: $(OUTPUT)/tmp/.lh_layout_copied $(OUTPUT)/tmp/.lh_layout_s6rcdb_made | $(OUTPUT)/build-build/.lh_skarnet_installed + exec setuidgid $(NORMALUSER) s6-touch $@ diff --git a/sub/layout/configure-localoptions b/sub/layout/configure-localoptions new file mode 100755 index 0000000..451fcce --- /dev/null +++ b/sub/layout/configure-localoptions @@ -0,0 +1,20 @@ +#!/bin/sh -e + +output="$1" +countrycode="$2" +localip="$3" +routerip="$4" + +case "$countrycode" in + fr) timezone=Europe/Paris ;; + uk) timezone=Europe/London ;; + rs) timezone=Europe/Belgrade ;; + cn) timezone=Asia/Shanghai ;; + vn) timezone=Asia/Saigon ;; + *) echo "invalid countrycode: please choose fr, uk, rs, cn or vn" 1>&2 ; exit 100 ;; +esac + +echo "$countrycode" > $output/rootfs/etc/s6-linux-init/env-stage2/COUNTRY_CODE +echo "$localip" > $output/rootfs/etc/s6-linux-init/env-stage2/ETH0_IP4 +echo "$routerip" > $output/rootfs/etc/s6-linux-init/env-stage2/DEFAULT_ROUTER_IP4 +echo ":$timezone" > $output/rootfs/etc/s6-linux-init/env/TZ diff --git a/sub/layout/copylayout b/sub/layout/copylayout new file mode 100755 index 0000000..59dd0e0 --- /dev/null +++ b/sub/layout/copylayout @@ -0,0 +1,70 @@ +#!/bin/sh -e + +# TODO: need comments + +output="$1" + + +case "$QEMU_ARCH" in + x86_64) disk=sda ; partition=sda ; netmodule=e1000 ; console=ttyS0 ;; + x86) disk=sda ; partition=sda ; netmodule=e1000 ; console=ttyS0 ;; + arm) disk=mmcblk0 ; partition=mmcblk0p ; netmodule=virtio_net ; console=ttyAMA0 ;; + aarch64) disk=mmcblk0 ; partition=mmcblk0p ; netmodule=virtio_net ; console=ttyAMA0 ;; +esac + +if $USE_VIRTIO_DISK ; then + disk=vda + partition=vda +fi + +if $USE_VIRTIO_NETWORK ; then + netmodule=virtio_net +fi + +s6-hiercopy layout/initramfs $output/initramfs +find "$output/initramfs" -type f -name .empty -size 0c -exec s6-rmrf {} \; +s6-hiercopy layout/rootfs $output/rootfs +find "$output/rootfs" -type f -name .empty -size 0c -exec s6-rmrf {} \; +s6-hiercopy layout/rwfs $output/rwfs +find "$output/rwfs" -type f -name .empty -size 0c -exec s6-rmrf {} \; +s6-hiercopy layout/userfs $output/userfs +find "$output/userfs" -type f -name .empty -size 0c -exec s6-rmrf {} \; +s6-hiercopy layout/stagingfs $output/stagingfs +find "$output/stagingfs" -type f -name .empty -size 0c -exec s6-rmrf {} \; + +if $USE_GRAPHIC ; then + console=tty1 + echo "load-essential-modules" >> $output/rootfs/etc/s6-rc/source-base/ok-local/contents +fi + +timeout=${S6RC_TIMEOUT} +buildtime=$(s6-clock) + +hostarch=$(s6-echo $TRIPLE | cut -f1 -d-) +# sed -i -e "s/%%HOSTNAME%%/lh-$hostarch/g" $output/rootfs/etc/s6-rc/source-base/00/up $output/rootfs/etc/s6-linux-init/run-image/service/s6-linux-init-early-getty/run $output/rootfs/etc/motd $output/rootfs/etc/issue.net $output/rootfs/root/.execline-shell $output/userfs/home/guest/.execline-shell +sed -i -e "s/%%CONSOLE%%/$console/g" $output/rootfs/etc/s6-linux-init/run-image/service/s6-linux-init-early-getty/run +# sed -i -e "s/%%NETMODULE%%/$netmodule/g" $output/rootfs/etc/s6-rc/source-base/init-eth0/up +# sed -i -e "s/%%RCTIMEOUT%%/$timeout/g" -e "s/%%BUILDTIME%%/$buildtime/g" $output/rootfs/etc/rc.init + + +if $USE_DHCP ; then + eth0_service=udhcpc-eth0-pipeline +else + eth0_service=static-eth0 +fi +# echo ${eth0_service} > $output/rootfs/etc/s6-rc/source-base/activate-eth0/contents + +for i in $output/initramfs/init $output/rootfs/etc/s6-rc/source-base/mount-*/* ; do + sed -i -e "s/%%DISK%%/$disk/g" -e "s/%%PARTITION%%/$partition/g" $i +done + +chown -R root.root $output/initramfs $output/rootfs $output/rwfs $output/userfs + +s6-mkfifo -m 0600 -- $output/rootfs/etc/s6-linux-init/run-image/service/s6-svscan-log/fifo || s6-true + +while read file user group perms ; do + if s6-test -n "$file" -a "$file" != "#" ; then + $output/build-build/command/s6-chown -u $user -g $group -- $output/$file + $output/build-build/command/s6-chmod $perms $output/$file + fi +done < sub/layout/permissions diff --git a/sub/layout/permissions b/sub/layout/permissions new file mode 100644 index 0000000..459355e --- /dev/null +++ b/sub/layout/permissions @@ -0,0 +1,18 @@ +rootfs/etc/shadow 0 0 0600 +rootfs/etc/s6-linux-init/run-image/uncaught-logs 98 98 2700 + +rwfs/var/tmp 0 0 1777 +rwfs/var/log/devd 100 61 2700 +rwfs/var/log/dnscache 114 64 2700 +rwfs/var/log/fdholder 135 76 2700 +rwfs/var/log/fdholder-tmp 135 76 2700 +rwfs/var/log/klogd 102 61 2700 +rwfs/var/log/ntpclient 106 62 2700 +rwfs/var/log/sshd-4 138 61 2700 +rwfs/var/log/syslogd 104 61 2700 +# rwfs/var/log/udhcpc-eth0 139 78 2700 + +userfs/home/guest 1000 100 2755 +userfs/home/guest/.execline-shell 1000 100 0755 +userfs/home/guest/.execline-loginshell 1000 100 0755 +userfs/home/guest/.ssh 1000 100 2700 |