Initial commit.

This commit is contained in:
Luka Vandervelden 2019-09-01 14:46:43 +02:00
commit e951e61e93

125
installer.zsh Executable file
View File

@ -0,0 +1,125 @@
#!/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
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 " -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 "$@"
# 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