#!/bin/sh def_arch=$(uname -m) def_ver="1.0-beta3" 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] [--mini] [-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 ;; --mini) declare -r MINI=yes ;; -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..." if test -n "${MINI+mini}"; then declare -r PACKAGES="adelie-core" declare -r ARCH_PKGS="" else declare -r PACKAGES=$(cat packages 2>/dev/null || fatal 'No core packages specified') declare -r ARCH_PKGS=$(cat packages-$ARCH 2>/dev/null || echo '') fi 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 -r rootfs-$ARCH/boot/* out/kernels/$ARCH/ } tar_it() { header 'Creating compressed file system image...' cd rootfs-$ARCH tar -cJf ../out/adelie-rootfs-${MINI+mini-}$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