summaryrefslogtreecommitdiff
path: root/adelie-build-cd
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2017-01-29 14:01:52 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2017-01-29 14:02:14 -0600
commit96a0e248ba150a60703ca8dc2c411f249b1f867b (patch)
tree233fc3db059d8d513ec8a068396ea257aeaad374 /adelie-build-cd
parent2a7982735068e10a26bc1b0638b5f6c5b674eff2 (diff)
downloadimage-96a0e248ba150a60703ca8dc2c411f249b1f867b.tar.gz
image-96a0e248ba150a60703ca8dc2c411f249b1f867b.tar.bz2
image-96a0e248ba150a60703ca8dc2c411f249b1f867b.tar.xz
image-96a0e248ba150a60703ca8dc2c411f249b1f867b.zip
Significantly refactor build-cd script, and add a man page woo
Diffstat (limited to 'adelie-build-cd')
-rwxr-xr-xadelie-build-cd350
1 files changed, 350 insertions, 0 deletions
diff --git a/adelie-build-cd b/adelie-build-cd
new file mode 100755
index 0000000..0a7ee3d
--- /dev/null
+++ b/adelie-build-cd
@@ -0,0 +1,350 @@
+#!/bin/sh
+
+def_arch=$(uname -m)
+declare -r PROGNAME=$(basename $0)
+
+
+warn() {
+ printf '>>> '
+ printf '\033[01;33mWARNING\033[00;39m '
+ printf '>>> '
+ printf '\033[01;33mWARNING\033[00;39m '
+ printf '>>> '
+ printf '\033[01;33mWARNING\033[00;39m '
+ printf '>>> '
+ printf '\033[01;33mWARNING\033[00;39m '
+ printf '>>>\n'
+}
+
+
+fatal() {
+ printf '>>> '
+ printf '\033[01;31mERROR\033[00;39m '
+ printf '>>> '
+ printf '\033[01;31mERROR\033[00;39m '
+ printf '>>> '
+ printf '\033[01;31mERROR\033[00;39m '
+ printf '>>> '
+ printf '\033[01;31mERROR\033[00;39m '
+ printf '>>>\n'
+}
+
+
+ensure_commands() {
+ if ! type apk>/dev/null; then
+ fatal
+ printf 'You must have apk installed. On Gentoo, see sys-devel/apk-tools.\n'
+ exit -1
+ fi
+
+ if ! type cpio>/dev/null; then
+ fatal
+ printf 'You must have cpio installed. On Gentoo, see app-arch/cpio.\n'
+ exit -1
+ fi
+
+ if ! type mksquashfs>/dev/null; then
+ fatal
+ printf 'You must have mksquashfs installed. On Gentoo, see sys-fs/squashfs-tools.\n'
+ exit -1
+ fi
+
+ if ! type mkisofs>/dev/null; then
+ fatal
+ printf 'You must have mkisofs installed. Try cdrtools or cdrkit.\n'
+ exit -1
+ fi
+}
+
+
+usage() {
+ printf 'usage: %s [-a ARCH] [-f|--full] [-p|--phase PHASE] [--help]\n\n' $PROGNAME
+ printf 'Create an Adélie Linux CD image (.ISO) using the specified parameters.\n'
+ printf 'Default ARCH: %s\n' $def_arch
+ printf 'Valid phases: clean install initrd iso all\n'
+}
+
+
+while [ -n "$1" ]; do
+ case $1 in
+ -a | --arch)
+ shift
+ declare -r MY_ARCH=$1
+ ;;
+ -h | --help)
+ usage
+ exit
+ ;;
+ -f | --full)
+ shift
+ declare -r DO_FULL=full
+ ;;
+ -p | --phase)
+ shift
+ declare -r PHASE=$1
+ ;;
+ *)
+ usage >&2
+ exit -1
+ ;;
+ esac
+ shift
+done
+
+set -a
+declare -r ARCH=${MY_ARCH:-$def_arch}
+declare -r LDARCH=${LDARCH:-$ARCH}
+declare -r PHASE=${PHASE:-all}
+set +a
+
+ensure_commands
+
+header() {
+ printf '\033[01;32m * \033[37m%s\033[00;39m\n' "$1"
+}
+
+header 'Adélie Linux CD Creation Tool'
+printf '\n'
+
+clean_dirs() {
+ warn
+ printf 'This will erase all files at the directories %s/cdroot-%s\n' `pwd` $ARCH
+ printf '%s/initrd-%s and %s/squashroot-%s.\n\n' `pwd` $ARCH `pwd` $ARCH
+ printf 'When you are ready, press RETURN. To cancel, press Ctrl-C.\n'
+ read
+
+ rm -rf cdroot-$ARCH
+ rm -rf initrd-$ARCH
+ rm -rf squashroot-$ARCH
+ mkdir cdroot-$ARCH
+ mkdir initrd-$ARCH
+ mkdir squashroot-$ARCH
+}
+
+install_pkgs() {
+ header "Installing base system to squash root..."
+
+ declare -r PACKAGES="
+ shadow \
+ libffi \
+ adelie-base \
+ bash \
+ openrc openrc-openrc \
+ hwids eudev udev-init-scripts-openrc \
+ parted \
+ lvm2-openrc \
+ easy-kernel easy-kernel-modules easy-kernel-firmware genkernel \
+ dhcpcd net-tools bind-tools s6-dns \
+ ca-certificates \
+ rfkill wireless-tools wpa_supplicant \
+ pciutils libusb1 usbutils \
+ hdparm \
+ less \
+ bzip2 \
+ netifrc netifrc-doc netifrc-openrc \
+ diskdev_cmds hfsutils mtools
+ dropbear dropbear-openrc openssh openssh-openrc
+ "
+
+ declare -r ARCH_PKGS=$(cat packages-$ARCH 2>/dev/null || echo '')
+
+ mkdir -p squashroot-$ARCH/etc/apk/keys
+ cp 'packages@adelielinux.org.pub' squashroot-$ARCH/etc/apk/keys/
+ apk --arch $ARCH -X "https://distfiles.adelielinux.org/adelie/1.0-alpha/$EXTRA_MIRROR" -U --root squashroot-$ARCH --initdb add $PACKAGES $ARCH_PKGS
+}
+
+make_structure() {
+ mkdir -p squashroot-$ARCH/home/live
+ mkdir squashroot-$ARCH/target
+ mkdir -p squashroot-$ARCH/media/live
+ ln -s /bin/bash squashroot-$ARCH/bin/sh
+
+ echo 'hostname="adelie"' > squashroot-$ARCH/etc/conf.d/hostname
+ echo 'mtab_is_file=no' > squashroot-$ARCH/etc/conf.d/mtab
+
+ cp -RPp squashroot-$ARCH/usr/share/openrc/runlevels squashroot-$ARCH/etc/runlevels
+ ln -s /etc/init.d/udev squashroot-$ARCH/etc/runlevels/sysinit/udev
+ ln -s /etc/init.d/udev-trigger squashroot-$ARCH/etc/runlevels/sysinit/udev-trigger
+ ln -s /etc/init.d/lvmetad squashroot-$ARCH/etc/runlevels/sysinit/lvmetad
+
+ cat >squashroot-$ARCH/etc/fstab <<- FSTAB
+ # Welcome to Adélie Linux.
+ # This fstab(5) is for the live media only. Do not edit or use for your installation.
+
+ tmpfs /tmp tmpfs defaults 0 1
+ tmpfs /var/log tmpfs size=8m 0 1
+ tmpfs /root tmpfs size=16m 0 1
+ tmpfs /home/live tmpfs size=16m 0 1
+ proc /proc proc defaults 0 1
+ FSTAB
+
+ cat >squashroot-$ARCH/etc/passwd <<- PASSWD
+ root:x:0:0:Charlie Root:/root:/bin/bash
+ man:x:13:15:man-db:/usr/share/man:/sbin/nologin
+ sshd:x:22:22:SSH daemon:/var/empty:/sbin/nologin
+ at:x:25:25:at:/var/spool/at/atjobs:/sbin/nologin
+ fcron:x:101:206:fcron:/dev/null:/sbin/nologin
+ messagebus:x:103:203:DBus unprivileged user:/dev/null:/sbin/nologin
+ polkit:x:104:202:PolicyKit unprivileged user:/dev/null:/sbin/nologin
+ rtkit:x:105:200:RTKit unprivileged user:/dev/null:/sbin/nologin
+ postfix:x:207:207:postfix:/var/spool/postfix:/sbin/nologin
+ live:x:1000:1000:Live User:/home/live:/bin/bash
+ PASSWD
+
+ cat >squashroot-$ARCH/etc/group <<- GROUP
+ root:x:0:
+ tty:x:5:
+ wheel:x:10:live
+ mail:x:12:postfix
+ uucp:x:14:
+ cron:x:16:
+ audio:x:18:
+ sshd:x:22:
+ at:x:25:
+ rtkit:x:200:
+ plugdev:x:201:
+ polkitd:x:202:
+ messagebus:x:203:
+ input:x:205:
+ fcron:x:206:
+ postfix:x:207:
+ postdrop:x:208:
+ postmaster:x:249:
+ utmp:x:406:
+ live:x:1000:
+ GROUP
+
+ cat >squashroot-$ARCH/etc/shadow <<- SHADOW
+ root::::::::
+ man::::::::
+ sshd::::::::
+ at::::::::
+ fcron::::::::
+ messagebus::::::::
+ polkit::::::::
+ rtkit::::::::
+ postfix::::::::
+ live::::::::
+ SHADOW
+
+ cat >squashroot-$ARCH/etc/shells <<- SHELLS
+ /bin/bash
+ /bin/zsh
+ SHELLS
+
+ cat >squashroot-$ARCH/etc/resolv.conf <<- RESOLVE
+ nameserver 84.200.69.80
+ nameserver 2001:1608:10:25::1c04:b12f
+ RESOLVE
+
+ cat >squashroot-$ARCH/etc/apk/repositories <<-REPOS
+ https://distfiles.adelielinux.org/adelie/1.0-alpha/$EXTRA_MIRROR
+ REPOS
+
+ cat >squashroot-$ARCH/etc/issue <<-ISSUE
+ Welcome to Adélie Linux!
+ You may log in as 'root' to install, or 'live' to play around.
+
+ Have fun.
+
+ ISSUE
+
+ chmod 600 squashroot-$ARCH/etc/shadow
+
+ if test -n "${DO_FULL+full}"; then
+ declare -r PACKAGES_DIR=squashroot-$ARCH/packages/$ARCH
+ mkdir -p $PACKAGES_DIR
+ apk --arch $ARCH --root squashroot-$ARCH fetch -o $PACKAGES_DIR $(apk --root squashroot-$ARCH info)
+ if test -n "${SIGNING_KEY+use_key}"; then
+ apk index -o .tmp.APKINDEX.unsigned.tar.gz $PACKAGES_DIR/*.apk
+ openssl dgst -sha256 -sign $SIGNING_KEY -out .SIGN.RSA.packages\@adelielinux.org.pub .tmp.APKINDEX.unsigned.tar.gz
+ tar cf .tmp.signature.tar .SIGN.RSA.packages\@adelielinux.org.pub
+ cat .tmp.signature.tar | abuild-tar --cut | gzip -9 > .tmp.signature.tar.gz
+ cat .tmp.signature.tar.gz .tmp.APKINDEX.unsigned.tar.gz > .tmp.APKINDEX.tar.gz
+ rm .tmp.APKINDEX.unsigned.tar.gz .tmp.signature.tar.gz .tmp.signature.tar .SIGN.RSA.packages\@adelielinux.org.pub
+ mv .tmp.APKINDEX.tar.gz $PACKAGES_DIR/APKINDEX.tar.gz
+ fi
+ fi
+
+ cp AdelieTux.icns cdroot-$ARCH/.VolumeIcon.icns
+}
+
+squash_it() {
+ header 'Creating compressed file system image...'
+
+ mksquashfs squashroot-$ARCH cdroot-$ARCH/adelie.squashfs
+}
+
+make_initrd() {
+ header 'Creating initrd structure...'
+
+ # mount points
+ mkdir initrd-$ARCH/dev
+ mkdir initrd-$ARCH/media
+ mkdir initrd-$ARCH/newroot
+ mkdir initrd-$ARCH/proc
+ mkdir initrd-$ARCH/sys
+
+ # manual /dev nodes for initial udev startup
+ mknod -m 600 initrd-$ARCH/dev/console c 5 1
+ mknod -m 666 initrd-$ARCH/dev/null c 1 3
+ mknod -m 666 initrd-$ARCH/dev/ptmx c 5 2
+ mknod -m 666 initrd-$ARCH/dev/random c 1 8
+ mknod -m 666 initrd-$ARCH/dev/tty c 5 0
+ mknod -m 620 initrd-$ARCH/dev/tty1 c 4 1
+ mknod -m 666 initrd-$ARCH/dev/urandom c 1 9
+ mknod -m 666 initrd-$ARCH/dev/zero c 1 5
+
+ # base
+ mkdir initrd-$ARCH/lib
+ cp squashroot-$ARCH/usr/lib/libc.so initrd-$ARCH/lib/ld-musl-$LDARCH.so.1
+ cp squashroot-$ARCH/lib/libblkid.so.1 initrd-$ARCH/lib/
+ cp squashroot-$ARCH/lib/libuuid.so.1 initrd-$ARCH/lib/
+
+ # udev
+ mkdir -p initrd-$ARCH/etc/udev
+ mkdir initrd-$ARCH/run
+ mkdir initrd-$ARCH/sbin
+ cp squashroot-$ARCH/bin/udevadm initrd-$ARCH/sbin/
+ cp squashroot-$ARCH/sbin/udevd initrd-$ARCH/sbin/
+ cp squashroot-$ARCH/lib/libkmod.so.2 initrd-$ARCH/lib/
+ cp squashroot-$ARCH/lib/libudev.so.1 initrd-$ARCH/lib/
+ cp squashroot-$ARCH/etc/udev/hwdb.bin initrd-$ARCH/etc/udev/
+
+ # init
+ cp cdinit-$ARCH initrd-$ARCH/init
+
+ header 'Compressing initrd...'
+
+ pushd initrd-$ARCH
+ find . | cpio -H newc -o > ../cdroot-$ARCH/initrd
+ popd
+ gzip -9 cdroot-$ARCH/initrd
+ mv cdroot-$ARCH/initrd.gz cdroot-$ARCH/initrd
+}
+
+prepare_cdroot() {
+ header 'Adding kernel...'
+
+ cp squashroot-$ARCH/boot/vmlinu* cdroot-$ARCH/bzImage
+
+ if test -f post-$ARCH.sh; then
+ header 'Running architecture-specific scripts...'
+ sh post-$ARCH.sh
+ fi
+}
+
+create_iso() {
+ header 'Creating the CD...'
+
+ declare -r CD_PARAMS=$(cat iso-params-$ARCH)
+ mkisofs -o adelie-${DO_FULL:-live}-$ARCH-1.0-ALPHA2-$(date +%Y%m%d).iso -joliet -rational-rock -V "Adelie 1.0a2 $ARCH" ${CD_PARAMS} cdroot-$ARCH
+}
+
+#clean_dirs
+#install_pkgs
+#make_structure
+#squash_it
+#make_initrd
+prepare_cdroot
+create_iso