installer/installer.zsh

140 lines
2.9 KiB
Bash
Raw Permalink Normal View History

2019-09-01 14:46:43 +02:00
#!/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
2019-09-03 13:22:58 +02:00
zparseopts -D -E -- -root:=root r:=root -help=help h=help m=mount -mount=mount u=unmount -unmount=unmount
2019-09-01 14:46:43 +02:00
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."
2019-09-03 13:22:58 +02:00
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."
2019-09-01 14:46:43 +02:00
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 "$@"
2019-09-03 13:22:58 +02:00
if [[ -n "$mount" ]]; then
rootfs/mount "$root"
exit 0
fi
if [[ -n "$unmount" ]]; then
rootfs/unmount "$root"
exit 0
fi
2019-09-01 14:46:43 +02:00
# INITIAL SYSTEM BOOTSTRAP
##fs/setup
##fs/mount
2019-09-03 13:22:58 +02:00
2019-09-01 14:46:43 +02:00
rootfs/setup "$root"
2019-09-03 13:22:58 +02:00
2019-09-01 14:46:43 +02:00
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