installer/installer.zsh

140 lines
2.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env zsh
# TODO:
#
# - Install and create rootfs.
# - Create disk images.
# - Create .iso files.
# TODO:
#
# - Setup the filesystems and/or partition the disks.
# - Get an arbitrary, random mountpoint (both /media or /mnt will do).
# - Setup roots password.
# - Configure the target systems keyboard layout (should be possible
# to disable it)
# - Install syslinux, through syslinux/setup.
autoload -U colors
colors
set -e
function info {
echo "${fg_bold[green]} * ${fg_bold[white]}$@${reset_color}"
}
function rootfs/setup {
local ROOTFS="$1"
local REPO_URL=http://weirdos.karchnu.fr
info "Installing initial packages."
apk add \
--root $ROOTFS --initdb \
-U --allow-untrusted -X $REPO_URL \
busybox apk-tools weirdos-keys rc service
if [[ ! -f "$ROOTFS/etc/apk/repositories" ]]; then
echo "$REPO_URL" > "$ROOTFS/etc/apk/repositories"
fi
}
function rootfs/setup-dev {
local ROOTFS="$1"
info "Installing the development environment packages."
apk add \
--root $ROOTFS \
-U \
zsh gcc musl musl-dev \
libyaml-dev libevent-dev gc-dev pcre-dev \
crystal package
}
function rootfs/mount {
local ROOT="$1"
info "Mounting pseudo-filessystems."
mount --bind /dev $ROOT/dev
mount -t proc none $ROOT/proc
mount -t sysfs none $ROOT/sys
cp -L /etc/resolv.conf $ROOT/etc/
}
function rootfs/unmount {
local ROOT="$1"
info "Unmounting pseudo-filesystems."
umount $ROOT/{sys,proc,dev}
}
function installer/parse-opts {
local failure=false
zparseopts -D -E -- -root:=root r:=root -help=help h=help m=mount -mount=mount u=unmount -unmount=unmount
root=${root[-1]}
[[ ! $root ]] && failure=true
[[ -n "${help[@]}" ]] && help=true || help=false
if $help || $failure; then
echo "usage: $0 [options]"
echo
echo " -r DIR, --root DIR Specifies where to bootstrap the rootfs."
echo " -m, --mount Use with -r to only mount a rootfs without bootstrapping it."
echo " -u, --unmount Use with -r to only unmount a rootfs without bootstrapping it."
echo " -h, --help Prints this message and exits."
if $help; then
exit 0
else
exit 1
fi
fi
unset help
}
# Export WEIRDOS_SOURCE if you want to import this scripts functions and
# utilities. If you do, no CLI parsing will be done and no function will
# be called, so itll really be a simple import of functions!
if [[ -z "$WEIRDOS_SOURCE" ]]; then
installer/parse-opts "$@"
if [[ -n "$mount" ]]; then
rootfs/mount "$root"
exit 0
fi
if [[ -n "$unmount" ]]; then
rootfs/unmount "$root"
exit 0
fi
# INITIAL SYSTEM BOOTSTRAP
##fs/setup
##fs/mount
rootfs/setup "$root"
rootfs/mount "$root"
##syslinux/setup
# SYSTEM CONFIGURATION
##rootfs/setup-passwd
##rootfs/setup-keyboard
# Installs default package sets? Preconfigures common services, like
# network-related services, cron, and so on?
#rootfs/setup-dev "$root"
# CLEANUP
rootfs/unmount "$root"
#fs/unmount
fi