#!/bin/sh # ============================================================== # _ _ _ _ # | | _____ _ __ (_) | ___ ___| |__ a tool to install, # | |/ / _ \| '_ \| | |/ _ \ / __| '_ \ update, and run a # | < (_) | | | | | | (_) |\__ \ | | | local konilo system. # |_|\_\___/|_| |_|_|_|\___(_)___/_| |_| # # ================================================ 2024.04.30 == MULTILO="N" BACKUP="Y" H=$(uname | tr '[:upper:]' '[:lower:]') M=$(uname -m | tr '[:upper:]' '[:lower:]' | sed 's/x86_64/amd64/;s/i[3-6]86/x86/;s/sun4u/sparc/') TRIPLE="ilo-$M-$H" mkdir -p ~/.konilo ~/.konilo/_backups cd ~/.konilo/ || exit backup() { D=$(date '+%Y%m%d-%H%M') cp ilo.blocks _backups/"$D" && gzip _backups/"$D" find _backups/* -mtime +5 -type f -delete } download() { DL="none" for cmd in wget curl; do type $cmd >/dev/null 2>/dev/null && { DL=$cmd && break; } done [ "$DL" = "curl" ] && DL="curl -O" [ "$H" = "openbsd" ] && DL=ftp [ "$H" = "netbsd" ] && DL=ftp [ "$H" = "freebsd" ] && DL=fetch [ "$DL" = "none" ] && { echo "Neither wget(1) nor curl(1) detected! Install one of these and try again."; exit; } $DL "$1" } docs() { download http://konilo.org/konilo-sh.txt && less konilo-sh.txt && rm konilo-sh.txt printf "Do you wish to continue? (y/n)" read -r choice case "$choice" in [Yy]*) touch continue ;; [Nn]*) echo "Aborting..."; exit ;; *) echo "Aborting..."; exit ;; esac } gzdownload() { download "$1" && gunzip "$(basename "$1")" } update() { backup rm ilo.rom && mv ilo.blocks user.blocks gzdownload http://konilo.org/ilo.rom.gz && gzdownload http://konilo.org/ilo.blocks.gz dd if=ilo.blocks of=user.blocks bs=4k seek=3 skip=3 count=1024 conv=notrunc dd if=ilo.blocks of=user.blocks bs=4k seek=6144 skip=6144 count=2048 conv=notrunc dd if=ilo.blocks of=user.blocks bs=4k seek=8192 skip=8192 count=5120 conv=notrunc mv user.blocks ilo.blocks && exit } uninstall() { rm -i ~/.konilo/_backups/* ~/.konilo/ilo* ~/.konilo/continue && exit } run() { stty cbreak && ./"$TRIPLE" && stty -cbreak } multilo() { download http://konilo.org/latest/milo.c && cc -O2 -s milo.c -o "$TRIPLE" && rm milo.c && chmod +x "$TRIPLE" } obtain() { [ ! -f ilo.rom ] && gzdownload http://konilo.org/ilo.rom.gz [ ! -f ilo.blocks ] && gzdownload http://konilo.org/ilo.blocks.gz [ "$MULTILO" = "Y" ] && [ ! -f "$TRIPLE" ] && multilo [ ! -f "$TRIPLE" ] && download http://konilo.org/binaries/"$TRIPLE" [ ! -f "$TRIPLE" ] && download http://konilo.org/latest/ilo.c [ -f ilo.c ] && cc -O2 -s ilo.c -o "$TRIPLE" && rm ilo.c chmod +x "$TRIPLE" } case $1 in uninstall) uninstall ;; update) update ;; esac [ ! -f continue ] && docs obtain && run [ "$BACKUP" = "Y" ] && backup && exit