diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2018-09-10 15:40:07 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2018-09-10 15:40:07 -0500 |
commit | d7fb725f494c7cd193d4e39b559328de0835985e (patch) | |
tree | 9e253ac4950c65c5b94ac93e9ce80a0b25f408a3 /adelie-build-txz | |
parent | b428d0f593048646dbcfea4ae0392c1160f378f0 (diff) | |
download | image-d7fb725f494c7cd193d4e39b559328de0835985e.tar.gz image-d7fb725f494c7cd193d4e39b559328de0835985e.tar.bz2 image-d7fb725f494c7cd193d4e39b559328de0835985e.tar.xz image-d7fb725f494c7cd193d4e39b559328de0835985e.zip |
Presenting adelie-build-txz, for generating rootfs tarballs
Diffstat (limited to 'adelie-build-txz')
-rwxr-xr-x | adelie-build-txz | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/adelie-build-txz b/adelie-build-txz new file mode 100755 index 0000000..1ae12fa --- /dev/null +++ b/adelie-build-txz @@ -0,0 +1,207 @@ +#!/bin/sh + +def_arch=$(uname -m) +def_ver="1.0-beta1" +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 2>/dev/null; then + fatal + printf 'You must have apk installed. On Gentoo, see sys-devel/apk-tools.\n' + exit -1 + fi + + if ! type tar>/dev/null 2>/dev/null; then + fatal + printf 'You must have tar installed.\n' + exit -1 + fi +} + + +usage() { + printf 'usage: %s [-a ARCH] [-s] [-v VERSION] [--help]\n\n' $PROGNAME + printf 'Create an Adélie Linux root FS tarball (.TXZ) using the specified parameters.\n\n' + printf 'Default ARCH: %s\n' $def_arch + printf 'Default VERSION: %s\n' $def_ver +} + + +while [ -n "$1" ]; do + case $1 in + -a | --arch) + shift + declare -r MY_ARCH=$1 + ;; + -h | --help) + usage + exit + ;; + -s | --sign) + declare -r SIGN=yes + ;; + -v | --version) + shift + declare -r MY_VER=$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=${MY_PHASE:-all} +declare -r VERSION=${MY_VER:-$def_ver} +declare -r URL=${MY_URL:-https://distfiles.adelielinux.org/adelie/$VERSION/} +set +a + +ensure_commands + +header() { + printf '\033[01;32m * \033[37m%s\033[00;39m\n' "$1" +} + +header 'Adélie Linux Root FS Tarball Creation Tool' +printf '\n' + +clean_dirs() { + warn + printf 'This will erase all files at the directories %s/rootfs-%s.\n\n' `pwd` $ARCH + printf 'When you are ready, press RETURN. To cancel, press Ctrl-C.\n' + read + + rm -rf rootfs-$ARCH + mkdir rootfs-$ARCH + mkdir -p out +} + +install_pkgs() { + header "Installing base system to tar root..." + + declare -r PACKAGES=$(cat packages 2>/dev/null || fatal 'No core packages specified') + declare -r ARCH_PKGS=$(cat packages-$ARCH 2>/dev/null || echo '') + + mkdir -p rootfs-$ARCH/etc/apk/keys + cp 'packages@adelielinux.org.pub' rootfs-$ARCH/etc/apk/keys/ + # XXX: Handle pre-install scripts. + mkdir -p rootfs-$ARCH/dev + mknod rootfs-$ARCH/dev/urandom c 1 9 + mkdir -p rootfs-$ARCH/usr/sbin + cp addgroup adduser rootfs-$ARCH/usr/sbin/ + apk --arch $ARCH \ + -X "$URL/system/$EXTRA_MIRROR" \ + -X "$URL/user/$EXTRA_MIRROR" \ + -U --root rootfs-$ARCH --initdb add $PACKAGES $ARCH_PKGS +} + +make_structure() { + mkdir -p rootfs-$ARCH/etc/runlevels/{sysinit,boot,default,shutdown} + + echo 'adelie-root' > rootfs-$ARCH/etc/hostname + echo 'mtab_is_file=no' > rootfs-$ARCH/etc/conf.d/mtab + + for siservice in udev udev-trigger lvmetad; do + ln -s /etc/init.d/$siservice \ + rootfs-$ARCH/etc/runlevels/sysinit/$siservice + done + + for bootservice in root binfmt bootmisc fsck hostname hwclock keymaps \ + localmount loopback modules mtab procfs sysctl sysfsconf termencoding \ + tmpfiles.setup urandom; do + ln -s /etc/init.d/$bootservice \ + rootfs-$ARCH/etc/runlevels/boot/$bootservice + done + + cat >rootfs-$ARCH/etc/fstab <<- FSTAB + # Welcome to Adélie Linux. + # This fstab(5) is for the live media only. Edit for use for your installation. + + tmpfs /tmp tmpfs defaults 0 1 + proc /proc proc defaults 0 1 + FSTAB + + cat >rootfs-$ARCH/etc/shells <<- SHELLS + /bin/bash + /bin/zsh + SHELLS + + cat >rootfs-$ARCH/etc/resolv.conf <<- RESOLVE + nameserver 84.200.69.80 + nameserver 2001:1608:10:25::1c04:b12f + RESOLVE + + cat >rootfs-$ARCH/etc/apk/repositories <<-REPOS + https://distfiles.adelielinux.org/adelie/$VERSION/system/$EXTRA_MIRROR + https://distfiles.adelielinux.org/adelie/$VERSION/user/$EXTRA_MIRROR + REPOS + + cp AdelieTux.icns rootfs-$ARCH/.VolumeIcon.icns + + # Put a copy of the kernel(s) in the kernels-$ARCH/ directory, so that + # users may download them for netbooting or such. + mkdir -p out/kernels/$ARCH + cp rootfs-$ARCH/boot/* out/kernels/$ARCH/ +} + +tar_it() { + header 'Creating compressed file system image...' + + cd rootfs-$ARCH + tar -cJf ../out/adelie-rootfs-$ARCH-$VERSION-$(date +%Y%m%d).txz . +} + +# in case we want to add phase support like adelie-build-cd has later +case $PHASE in + clean) + clean_dirs + ;; + install) + install_pkgs + make_structure + ;; + tar) + tar_it + ;; + *) + clean_dirs + install_pkgs + make_structure + tar_it + ;; +# *) +# fatal +# printf 'Unknown phase %s. Stop.\n' $PHASE +# ;; +esac |