From c1b1b467ebc179528f33fca7afb74c119ef39184 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 13 Feb 2010 06:31:42 -0600 Subject: [PATCH] Initial commit --- Makefile | 81 + patch/boot_boot.config-config.patch | 6 + patch/boot_device.hints-ata-probe.patch | 13 + patch/boot_loader.conf-config.patch | 14 + patch/etc_bashrc-sensible-defaults.patch | 21 + patch/etc_fstab-sensible-defaults.patch | 7 + patch/etc_inputrc-sensible-defaults.patch | 21 + patch/etc_profile-sensible-defaults.patch | 62 + patch/etc_rc.conf-sensible-defaults.patch | 18 + patch/etc_rc.d_saveconfig-script.patch | 19 + .../etc_rc.initdiskless-mount-anything.patch | 26 + patch/etc_rc.initdiskless-no-rescue.patch | 11 + patch/etc_ttys-serialconsole.patch | 28 + patch/sbin_saveconfig-script.patch | 56 + ..._etc_gkrellmd.conf-sensible-defaults.patch | 34 + patch/usr_local_etc_sudoers-allow-wheel.patch | 11 + script/burn | 24 + script/gencard | 103 + script/geniso | 66 + script/gentree | 228 + script/genufs | 73 + script/genuzip | 63 + script/lib/ansi.sh | 42 + script/lib/ask.sh | 20 + script/lib/env.sh | 35 + script/lib/log.sh | 55 + script/lib/progress.sh | 26 + script/lib/root.sh | 15 + script/lib/skel.sh | 8 + script/mkisofs-sample.txt | 1636 +++++++ script/sample.txt | 3840 +++++++++++++++++ 31 files changed, 6662 insertions(+) create mode 100644 Makefile create mode 100644 patch/boot_boot.config-config.patch create mode 100644 patch/boot_device.hints-ata-probe.patch create mode 100644 patch/boot_loader.conf-config.patch create mode 100644 patch/etc_bashrc-sensible-defaults.patch create mode 100644 patch/etc_fstab-sensible-defaults.patch create mode 100644 patch/etc_inputrc-sensible-defaults.patch create mode 100644 patch/etc_profile-sensible-defaults.patch create mode 100644 patch/etc_rc.conf-sensible-defaults.patch create mode 100644 patch/etc_rc.d_saveconfig-script.patch create mode 100644 patch/etc_rc.initdiskless-mount-anything.patch create mode 100644 patch/etc_rc.initdiskless-no-rescue.patch create mode 100644 patch/etc_ttys-serialconsole.patch create mode 100644 patch/sbin_saveconfig-script.patch create mode 100644 patch/usr_local_etc_gkrellmd.conf-sensible-defaults.patch create mode 100644 patch/usr_local_etc_sudoers-allow-wheel.patch create mode 100755 script/burn create mode 100755 script/gencard create mode 100755 script/geniso create mode 100755 script/gentree create mode 100755 script/genufs create mode 100755 script/genuzip create mode 100644 script/lib/ansi.sh create mode 100644 script/lib/ask.sh create mode 100644 script/lib/env.sh create mode 100644 script/lib/log.sh create mode 100644 script/lib/progress.sh create mode 100644 script/lib/root.sh create mode 100644 script/lib/skel.sh create mode 100644 script/mkisofs-sample.txt create mode 100644 script/sample.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e962640 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +# mkisofs meanings +# -v Verbose +# -quiet quiet? +# -o output to root.iso +# -D No deep directory relocation (and no RR_MOVED) +# -no-pad Don't pad to 150 sectors +# -p preparer +# -V volume label + +# Settables +worktree ?= tree +boot_pad ?= 1280 +image_sect ?= 1000944 + +# Generation scripts +gentree = script/gentree +genufs = script/genufs +geniso = script/geniso +genuzip = script/genuzip +gencard = script/gencard + +# Image utilities +mkuzip != which mkuzip +mkuzip_opts ?= -s 65536 +mkisofs != which mkisofs +mkisofs_opts?= -quiet -D -R -no-pad -p CyberLeo + +# Default device for burn target +dev ?= null + +# Check current user +curruser != id -u +checkroot = @if [ $(curruser) -gt 0 ]; then printf "\033[1;31mI need root\033[0m\n"; exit 1; fi +checkdeps = @if [ ! -x "$(mkisofs)" -o ! -x "$(mkuzip)" ]; then printf "\033[1;31mCheck depends! mkisofs: $(mkisofs) mkuzip: $(mkuzip)\033[0m\n"; exit 1; fi + +all: card.img + +image: card.img + +firmware: card.img + +checkroot: + $(checkroot) + +burn: card.img + $(checkroot) + script/burn $(.ALLSRC) $(dev) + +card.img: boot.img root.img + $(checkroot) + ${gencard} -c $(worktree)/conf + +boot.img: $(worktree)/boot + $(checkroot) + ${genufs} -p $(boot_pad) $(worktree)/boot + +root.img: root.iso + $(checkroot) + $(checkdeps) + ${genuzip} $(.ALLSRC) $(.TARGET) + +root.iso: $(worktree)/root + $(checkroot) + $(checkdeps) + ${geniso} -n root $(.ALLSRC) $(.TARGET) + +$(worktree): root + $(checkroot) + $(gentree) -t $(worktree) -r $(.ALLSRC) + +$(worktree)/boot: root + $(checkroot) + $(gentree) -t $(worktree) -r $(.ALLSRC) + +$(worktree)/root: root + $(checkroot) + $(gentree) -t $(worktree) -r $(.ALLSRC) + +clean: + $(checkroot) + rm -Rf card.img boot.img root.img root.iso $(worktree) diff --git a/patch/boot_boot.config-config.patch b/patch/boot_boot.config-config.patch new file mode 100644 index 0000000..d8724a5 --- /dev/null +++ b/patch/boot_boot.config-config.patch @@ -0,0 +1,6 @@ +--- /dev/null 2010-01-10 20:33:01.000000000 -0600 ++++ boot/boot.config 2010-01-03 07:48:07.000000000 -0600 +@@ -0,0 +1,2 @@ ++/loader -h ++ + diff --git a/patch/boot_device.hints-ata-probe.patch b/patch/boot_device.hints-ata-probe.patch new file mode 100644 index 0000000..36840f2 --- /dev/null +++ b/patch/boot_device.hints-ata-probe.patch @@ -0,0 +1,13 @@ +--- boot/device.hints 2010-01-10 18:01:08.000000000 -0600 ++++ boot/device.hints 2009-11-07 02:28:38.000000000 -0600 +@@ -7,6 +7,9 @@ + hint.fd.0.drive="0" + hint.fd.1.at="fdc0" + hint.fd.1.drive="1" ++hint.ata.0.at="isa" ++hint.ata.0.port="0x1F0" ++hint.ata.0.irq="14" + hint.atkbdc.0.at="isa" + hint.atkbdc.0.port="0x060" + hint.atkbd.0.at="atkbdc" + diff --git a/patch/boot_loader.conf-config.patch b/patch/boot_loader.conf-config.patch new file mode 100644 index 0000000..8a3f162 --- /dev/null +++ b/patch/boot_loader.conf-config.patch @@ -0,0 +1,14 @@ +--- /dev/null 2010-01-10 20:33:01.000000000 -0600 ++++ boot/loader.conf 2010-01-03 08:52:40.000000000 -0600 +@@ -0,0 +1,10 @@ ++console="comconsole" ++comconsole_speed="115200" ++ ++ahci_load="YES" ++siis_load="YES" ++zlib_load="YES" ++geom_uzip_load="YES" ++ ++vfs.root.mountfrom="cd9660:/dev/iso9660/root" ++ + diff --git a/patch/etc_bashrc-sensible-defaults.patch b/patch/etc_bashrc-sensible-defaults.patch new file mode 100644 index 0000000..4092073 --- /dev/null +++ b/patch/etc_bashrc-sensible-defaults.patch @@ -0,0 +1,21 @@ +--- /dev/null 2010-01-24 09:56:47.000000000 +0000 ++++ etc/bashrc 2010-01-24 09:57:28.000000000 +0000 +@@ -0,0 +1,18 @@ ++# Enable emacs line editing mode ++set -o emacs ++ ++# Some useful aliases ++alias h='fc -l' ++alias j=jobs ++alias m=$PAGER ++alias ll='ls -laFo' ++alias l='ls -l' ++alias g='egrep -i' ++alias ls='ls -G' ++alias pp='ps axopid,user,state,command' ++ ++# Be paranoid ++alias cp='cp -ip' ++alias mv='mv -i' ++alias rm='rm -i' ++ diff --git a/patch/etc_fstab-sensible-defaults.patch b/patch/etc_fstab-sensible-defaults.patch new file mode 100644 index 0000000..59e5088 --- /dev/null +++ b/patch/etc_fstab-sensible-defaults.patch @@ -0,0 +1,7 @@ +--- /dev/null 2010-01-10 20:44:00.000000000 -0600 ++++ etc/fstab 2010-01-10 13:19:32.000000000 -0600 +@@ -0,0 +1,4 @@ ++/dev/iso9660/root / cd9660 ro 0 0 ++/dev/ufs/boot /boot/boot ufs ro,noatime,sync 0 2 ++/dev/ufs/conf /conf ufs ro,noatime,sync 0 2 ++ diff --git a/patch/etc_inputrc-sensible-defaults.patch b/patch/etc_inputrc-sensible-defaults.patch new file mode 100644 index 0000000..434d4c2 --- /dev/null +++ b/patch/etc_inputrc-sensible-defaults.patch @@ -0,0 +1,21 @@ +--- /dev/null 2010-01-24 09:36:47.000000000 +0000 ++++ etc/inputrc 2010-01-24 09:36:29.000000000 +0000 +@@ -0,0 +1,18 @@ ++set meta-flag on ++set input-meta on ++set convert-meta off ++set output-meta on ++ ++"\e[1~": beginning-of-line ++"\e[4~": end-of-line ++"\e[5~": beginning-of-history ++"\e[6~": end-of-history ++"\e[3~": delete-char ++"\e[2~": quoted-insert ++"\e[5C": forward-word ++"\e[5D": backward-word ++ ++# fix Home and End for German users ++"\e[7~": beginning-of-line ++"\e[8~": end-of-line ++ diff --git a/patch/etc_profile-sensible-defaults.patch b/patch/etc_profile-sensible-defaults.patch new file mode 100644 index 0000000..8c6efa3 --- /dev/null +++ b/patch/etc_profile-sensible-defaults.patch @@ -0,0 +1,62 @@ +--- etc/profile.orig 2010-01-24 09:37:51.000000000 +0000 ++++ etc/profile 2010-01-24 09:54:47.000000000 +0000 +@@ -16,3 +16,59 @@ + # msgs -f + # Allow terminal messages + # mesg y ++ ++# Title for titleable terminals ++case "${TERM}" in ++xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix) ++ title="\[\033]0;\h(\u)\007\]" ++ ;; ++screen) ++ title="\[\033_\h(\u)\033\\\]" ++ ;; ++*) ++ title="" ++ ;; ++esac ++ ++# Set the flag variable, if we can ++[ -x "$(which flag)" -a ! -f "${HOME}/.noflag" ] && export FLAG="($($(which flag) -e))" ++export PS1="${title}${FLAG}${PS1}" ++ ++# Set up input handling and environment ++[ -f /etc/inputrc ] && export INPUTRC=/etc/inputrc ++[ -f "${HOME}/.inputrc" ] && export INPUTRC="${HOME}/.inputrc" ++ ++[ -f "${HOME}/.shrc" ] && . "${HOME}/.shrc" ++ ++export BLOCKSIZE=K ++export EDITOR=vi ++export PAGER=less ++ ++# Path ++if [ "$(id -u)" -eq 0 ] || (id -nG | egrep -q "(^wheel *|* wheel *|* wheel$)") ++then ++ export PATH=${HOME}/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin ++else ++ export PATH=${HOME}/bin:/bin:/usr/bin:/usr/games:/usr/local/bin ++fi ++ ++# Local environment ++if [ -n "${BASH}" ] ++then ++ if [ -f "${HOME}/.bashrc" ] ++ then ++ export ENV="${HOME}/.bashrc" ++ . "${HOME}/.bashrc" ++ elif [ -f "/etc/bashrc" ] ++ then ++ export ENV="/etc/bashrc" ++ . "/etc/bashrc" ++ fi ++else ++ if [ -f "${HOME}/.shrc" ] ++ then ++ export ENV="${HOME}/.shrc" ++ . "${HOME}/.shrc" ++ fi ++fi ++ diff --git a/patch/etc_rc.conf-sensible-defaults.patch b/patch/etc_rc.conf-sensible-defaults.patch new file mode 100644 index 0000000..5f5d021 --- /dev/null +++ b/patch/etc_rc.conf-sensible-defaults.patch @@ -0,0 +1,18 @@ +--- /dev/null 2010-01-24 09:33:48.000000000 +0000 ++++ etc/rc.conf 2010-01-24 09:34:08.000000000 +0000 +@@ -0,0 +1,15 @@ ++# System config ++hostname="ss4200.cyberleo.net" ++local_startup="/etc/local/rc.d" ++ifconfig_em0="DHCP" ++ ++# Daemon configuration ++sshd_enable="YES" ++gkrellmd_enable="YES" ++ ++# Disable sendmail ++sendmail_enable="NONE" ++sendmail_submit_enable="NO" ++sendmail_outbound_enable="NO" ++sendmail_msp_queue_enable="NO" ++ diff --git a/patch/etc_rc.d_saveconfig-script.patch b/patch/etc_rc.d_saveconfig-script.patch new file mode 100644 index 0000000..0b349ac --- /dev/null +++ b/patch/etc_rc.d_saveconfig-script.patch @@ -0,0 +1,19 @@ +--- /dev/null 2010-01-30 08:55:01.000000000 +0000 ++++ etc/rc.d/saveconfig 2010-01-24 11:07:56.000000000 +0000 +@@ -0,0 +1,16 @@ ++#!/bin/sh ++ ++# PROVIDE: saveconfig ++# REQUIRE: var ++# BEFORE: swap1 ++# KEYWORD: shutdown ++ ++name="saveconfig" ++stop_cmd="saveconfig_stop" ++ ++saveconfig_stop(){ ++ /sbin/saveconfig ++} ++ ++load_rc_config $name ++run_rc_command "$1" diff --git a/patch/etc_rc.initdiskless-mount-anything.patch b/patch/etc_rc.initdiskless-mount-anything.patch new file mode 100644 index 0000000..a98367a --- /dev/null +++ b/patch/etc_rc.initdiskless-mount-anything.patch @@ -0,0 +1,26 @@ +--- etc/rc.initdiskless 2009-11-30 02:55:12.000000000 +0000 ++++ etc/rc.initdiskless 2010-01-03 16:02:27.000000000 +0000 +@@ -190,8 +190,21 @@ # handle_remount() { # $1 = mount point + log "nfspt ${nfspt} mountopts ${mountopts}" + # prepend the nfs root if not present + [ `expr "$nfspt" : '\(.\)'` = "/" ] && nfspt="${nfsroot}${nfspt}" +- mount_nfs $mountopts $nfspt $b +- chkerr $? "mount_nfs $nfspt $b" ++ ++ # Hack to allow mounting of any filesystem type, not just NFS ++ # (thumbdrive w/glabel *hint hint*) ++ # ufs:/dev/label/conf (or nfs:server:/root -- server:/root works too, if ++ # server isn't named ufs, msdosfs, etc...) ++ eval $(echo ${nfspt} | sed -E 's/^([^:]+):(.*)$/fstype="\1" device="\2"/') ++ case "${fstype}" in ++ ufs|msdosfs|cd9660|nfs) ;; ++ # Backwards compatibility. Hopefully someoen didn't name their NFS server 'ufs'... ++ *) device="${fstype}:${device}"; fstype="nfs" ;; ++ esac ++ mount -t "${fstype}" "${device}" "${b}" ++ chkerr $? "mount -t ${fstype} ${device} ${b}" ++ # ++ + to_umount="$b ${to_umount}" + } + diff --git a/patch/etc_rc.initdiskless-no-rescue.patch b/patch/etc_rc.initdiskless-no-rescue.patch new file mode 100644 index 0000000..fdf2c27 --- /dev/null +++ b/patch/etc_rc.initdiskless-no-rescue.patch @@ -0,0 +1,11 @@ +--- etc/rc.initdiskless 2010-01-03 03:44:29.000000000 +0000 ++++ etc/rc.initdiskless 2010-01-03 03:44:43.000000000 +0000 +@@ -376,7 +376,7 @@ + if [ -f $j ]; then + create_md $subdir + echo "Loading /$subdir from cpio archive $j" +- (cd / ; /rescue/tar -xpf $j) ++ (cd / ; /usr/bin/tar -xpf $j) + fi + done + for j in /conf/$i/*.remove ; do diff --git a/patch/etc_ttys-serialconsole.patch b/patch/etc_ttys-serialconsole.patch new file mode 100644 index 0000000..6adef4b --- /dev/null +++ b/patch/etc_ttys-serialconsole.patch @@ -0,0 +1,28 @@ +--- etc/ttys.orig 2010-01-24 09:48:01.000000000 +0000 ++++ etc/ttys 2010-01-24 09:49:02.000000000 +0000 +@@ -32,17 +32,17 @@ + # + ttyv0 "/usr/libexec/getty Pc" cons25 on secure + # Virtual terminals +-ttyv1 "/usr/libexec/getty Pc" cons25 on secure +-ttyv2 "/usr/libexec/getty Pc" cons25 on secure +-ttyv3 "/usr/libexec/getty Pc" cons25 on secure +-ttyv4 "/usr/libexec/getty Pc" cons25 on secure +-ttyv5 "/usr/libexec/getty Pc" cons25 on secure +-ttyv6 "/usr/libexec/getty Pc" cons25 on secure +-ttyv7 "/usr/libexec/getty Pc" cons25 on secure ++ttyv1 "/usr/libexec/getty Pc" cons25 off secure ++ttyv2 "/usr/libexec/getty Pc" cons25 off secure ++ttyv3 "/usr/libexec/getty Pc" cons25 off secure ++ttyv4 "/usr/libexec/getty Pc" cons25 off secure ++ttyv5 "/usr/libexec/getty Pc" cons25 off secure ++ttyv6 "/usr/libexec/getty Pc" cons25 off secure ++ttyv7 "/usr/libexec/getty Pc" cons25 off secure + ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure + # Serial terminals + # The 'dialup' keyword identifies dialin lines to login, fingerd etc. +-ttyu0 "/usr/libexec/getty std.9600" dialup off secure ++ttyu0 "/usr/libexec/getty std.115200" vt100 on secure + ttyu1 "/usr/libexec/getty std.9600" dialup off secure + ttyu2 "/usr/libexec/getty std.9600" dialup off secure + ttyu3 "/usr/libexec/getty std.9600" dialup off secure diff --git a/patch/sbin_saveconfig-script.patch b/patch/sbin_saveconfig-script.patch new file mode 100644 index 0000000..79c34ec --- /dev/null +++ b/patch/sbin_saveconfig-script.patch @@ -0,0 +1,56 @@ +--- /dev/null 2010-01-30 08:55:01.000000000 +0000 ++++ sbin/saveconfig 2010-01-24 11:02:05.000000000 +0000 +@@ -0,0 +1,53 @@ ++#!/bin/sh ++ ++echo -n "Saving configuration... " ++ ++if [ ! -f /etc/diskless ] ++then ++ echo "No flash setup detected." ++ exit 1 ++fi ++ ++find_newer_files() { ++ [ -d "${1}" ] || return 1 ++ find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print ++} ++ ++archive() { ++ [ -d "${1}" ] || return 1 ++ find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz" ++} ++ ++# Mount /conf read-write, and remount if it already is. ++if [ $(grep -c /conf /etc/fstab) -gt 0 ] ++then ++ mount -w /conf ++ if [ $? -ne 1 ] ++ then ++ umount /conf ++ mount -w /conf ++ _was_mounted=true ++ fi ++fi ++ ++ ++# Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE! ++dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")" ++mv /conf/default "/conf/backup/${dest}" ++ ++mkdir /conf/default ++ ++cd / ++# Copy changed config files to /conf/default (anything younger than /etc/diskless) ++#find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/ ++# This can be changed to allow compressed configuration here as well: ++archive etc ++archive var ++ ++# Umount /conf afterwards, if it wasn't mounted ++if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] ++then ++ umount /conf ++fi ++ ++echo "Done!" diff --git a/patch/usr_local_etc_gkrellmd.conf-sensible-defaults.patch b/patch/usr_local_etc_gkrellmd.conf-sensible-defaults.patch new file mode 100644 index 0000000..1d4a7c1 --- /dev/null +++ b/patch/usr_local_etc_gkrellmd.conf-sensible-defaults.patch @@ -0,0 +1,34 @@ +--- usr/local/etc/gkrellmd.conf.orig 2010-01-24 09:30:22.000000000 +0000 ++++ usr/local/etc/gkrellmd.conf 2010-01-24 09:31:10.000000000 +0000 +@@ -13,11 +13,11 @@ + # Specify a specific network interface to listen on for connections. + # By default gkrellmd listens on all available network interfaces. + # +-address 127.0.0.1 ++#address 127.0.0.1 + + # Specify the port to listen on for connections. + # +-port 19150 ++port 10000 + + # List of hosts allowed to connect. If no hosts are specified in a + # gkrellmd.conf file or on the command line, all hosts will be allowed. +@@ -74,7 +74,7 @@ + # Minimum is 2 (less than 2 for no I/O disconnecting and is the default). + # Requires at least 2.1.8 versions of both gkrellmd and gkrellm. + # +-#io-timeout 5 ++io-timeout 5 + + # Configure gkrellm clients to attempt automatic reconnects to a + # gkrellmd server every reconnect-timeout seconds after a disconnected +@@ -83,7 +83,7 @@ + # Minimum is 2 (less than 2 for no automatic reconnecting and is the default). + # Requires at least 2.1.8 versions of both gkrellmd and gkrellm. + # +-#reconnect-timeout 5 ++reconnect-timeout 5 + + # Server side local mailbox counts can be sent to gkrellm clients. List here + # paths to mbox, MH mail, or Maildir style mailboxes. diff --git a/patch/usr_local_etc_sudoers-allow-wheel.patch b/patch/usr_local_etc_sudoers-allow-wheel.patch new file mode 100644 index 0000000..05b8a06 --- /dev/null +++ b/patch/usr_local_etc_sudoers-allow-wheel.patch @@ -0,0 +1,11 @@ +--- usr/local/etc/sudoers.orig 2010-01-24 09:26:28.000000000 +0000 ++++ usr/local/etc/sudoers 2010-01-24 09:26:38.000000000 +0000 +@@ -28,7 +28,7 @@ + root ALL=(ALL) ALL + + # Uncomment to allow people in group wheel to run all commands +-# %wheel ALL=(ALL) ALL ++%wheel ALL=(ALL) ALL + + # Same thing without a password + # %wheel ALL=(ALL) NOPASSWD: ALL diff --git a/script/burn b/script/burn new file mode 100755 index 0000000..5e5d3b9 --- /dev/null +++ b/script/burn @@ -0,0 +1,24 @@ +#!/bin/sh + +_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" + +want root log + +image="${1}" +tgt="${2}" + +[ -b "${tgt}" -o -c "${tgt}" ] || tgt="/dev/${tgt}" +[ -b "${tgt}" -o -c "${tgt}" ] || err "${1}: no such file or directory" +[ -n "${image}" -a -r "${image}" ] || err "${2}: no such file or directory" + +bs=131072 +size="$(stat -f '%z' "${image}")" + +bar="bar -dan -bs ${bs} -s ${size}" +if [ -z "$(which bar)" ] +then + warn "misc/clpbar not installed! Running blind!" + bar="cat" +fi + +cat "${image}" | ${bar} | dd of="${tgt}" bs=${bs} diff --git a/script/gencard b/script/gencard new file mode 100755 index 0000000..ea485e5 --- /dev/null +++ b/script/gencard @@ -0,0 +1,103 @@ +#!/bin/sh + +_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" +want root log + +pebkac(){ + [ "${*}" ] && echo "$(basename "${0}"): ${*}" && echo "" + echo "Generate a card image using the specified boot and root images," + echo " and the optional conf directory to fill the free space." + echo "" + echo "Options:" + echo " -b Boot image filename (default boot.img)" + echo " -r Root image filename (default root.img)" + echo " -c Config directory to embed into card image" + echo " -o Card image filename to write (default card.img)" + echo " -s Intended card size, in 512-byte sectors" + echo " -h Hi!" + exit 1 +} + +img_sects(){ + [ ! -f "${1}" ] && return 0 + ( + eval $(stat -s "${1}") + echo "$(( ( ${st_size} + ( ${st_size} % 512 ) ) / 512 ))" + ) +} + +compute_label(){ + # Params: 1: cardsects 2: boot.img 3: root.img + card_size="${1}" + boot_file="${2}" + root_file="${3}" + [ -z "${card_size}" -o -z "${boot_file}" -o -z "${root_file}" ] && pebkac "RTFS, bitch!" + + omfg_ofst=0 + omfg_size=16 + boot_ofst="$(( ${omfg_ofst} + ${omfg_size} ))" + boot_size="$(img_sects boot.img)" + root_ofst="$(( ${boot_ofst} + ${boot_size} ))" + root_size="$(img_sects root.img)" + conf_ofst="$(( ${root_ofst} + ${root_size} ))" + conf_size="$(( ${card_size} - ( ${omfg_size} + ${boot_size} + ${root_size} ) ))" + last_ofst="$(( ${conf_ofst} + ${conf_size} ))" + + echo "a: ${boot_size} ${boot_ofst} 4.2BSD" + echo "c: ${card_size} 0 unused" + echo "d: ${root_size} ${root_ofst} 4.2BSD" + echo "e: ${conf_size} ${conf_ofst} 4.2BSD" +} + +# Defaults +boot_img="boot.img" +root_img="root.img" +conf_dir="conf" +card_img="card.img" +card_size=1000944 + +# Parse command line options +while getopts "b:r:c:o:s:h" opt +do + case "${opt}" in + b) boot_img="${OPTARG}" ;; + r) root_img="${OPTARG}" ;; + c) conf_dir="${OPTARG}" ;; + o) card_img="${OPTARG}" ;; + s) card_size="${OPTARG}" ;; + h) pebkac ;; + [?]) pebkac "Unrecognized option ${opt}" ;; + esac +done +shift $(( $OPTIND - 1 )) + +[ -f "${boot_img}" ] || err "${boot_img}: no such file or directory" +[ -f "${root_img}" ] || err "${root_img}: no such file or directory" +[ -d "${conf_dir}" ] || err "${conf_dir}: not a directory" +[ "${card_size}" -gt 0 ] || err "${card_size}: not a number " + +log Card size: ${card_size} sectors +rm -f "${card_img}" +dd if=/dev/zero of="${card_img}" bs=512 count=0 seek="${card_size}" 2>/dev/null +md=$(mdconfig -a -t vnode -f "${card_img}") +mnt="$(mktemp -d /tmp/conf.XXXXXXXX)" +trap "umount '${mnt}'; rmdir '${mnt}'; mdconfig -d -u '${md}'" exit hup int term kill + +compute_label "${card_size}" "${boot_img}" "${root_img}" | bsdlabel -R -B "${md}" /dev/stdin +log Applied label: +bsdlabel "${md}" + +log Writing boot image from "${boot_img}" +dd if="${boot_img}" of="/dev/${md}a" bs=131072 2>/dev/null + +log Writing root image from "${root_img}" +dd if="${root_img}" of="/dev/${md}d" bs=131072 2>/dev/null + +log Writing conf image +newfs -U -L conf "/dev/${md}e" + +log Populating conf from "${conf_dir}" +mount "/dev/${md}e" "${mnt}" +( cd "${conf_dir}"; find . | cpio -p "${mnt}" ) + +sync diff --git a/script/geniso b/script/geniso new file mode 100755 index 0000000..ec34e91 --- /dev/null +++ b/script/geniso @@ -0,0 +1,66 @@ +#!/bin/sh + +# Boilerplate +_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" + +# Load needed modules +want ansi log progress +printf "${a_normal}" + +pebkac() { + echo "Insert help here" +} + +# Parse command line options +while getopts "n:h" opt +do + case "${opt}" in + n) name="${OPTARG}" ;; + h) pebkac ;; + [?]) pebkac "Unrecognized option ${opt}" ;; + esac +done +shift $(( $OPTIND - 1 )) + +src="${1}" +out="${2}" + +[ -r "${src}" ] || err "${src}: no such file or directory" +[ ! -f "${out}" ] || err "${out}: file exists" + +command="/usr/local/bin/mkisofs -v -gui -D -R -no-pad -iso-level 4 -p CyberLeo -V '${name}' -o '${out}' '${src}' 2>&1" + +time_start="$(date +%s)" + +eval ${command} | sed -l -e '/^Writing: *The File(s).*$/s/^.*$/started=1 total=10000/; s/^\([ 0-9.%]*\) done.*$/count=\1/; /^[0-9]* extents written/s/^.*$/finished=1/; /=/!d; /^count=/s/[ .%]//g' | while read line +do + # initialization + count="${count:-0}" + + # Read in values + eval ${line} + + # Compute aggregates + iter="$(( ${iter:-0} + 1 ))" + + if [ -n "${finished}" -o "$(( ${iter} % ${limit_break:-16} ))" -eq 0 ] && \ + [ -n "${finished}" -o "$(date +%s)" != "${time_last}" ] + then + time="$(date +%s)" + + iter_diff="$(( ${iter:-0} - ${iter_last:-0} ))" + time_diff="$(( ${time} - ${time_last:-0} ))" + + # Adjust last iteration length as a rolling average of half the last per-second cluster count + [ -z "${finished}" ] && limit_break="$(( ( ${limit_break:-16} + ( ( ${iter_diff} / ${time_diff} ) / 2 ) ) / 2 ))" + + iter_last="${iter:-0}" + time_last="${time}" + + [ -n "${finished}" ] && count="${total}" + + printf "\r %s\033[K" "$(progress "${count}" "${total}")" + + [ -n "${finished}" ] && printf "\n" + fi +done diff --git a/script/gentree b/script/gentree new file mode 100755 index 0000000..551d395 --- /dev/null +++ b/script/gentree @@ -0,0 +1,228 @@ +#!/bin/sh + +# Boilerplate +_root="$(dirname "${0}")" +. "${_root}/lib/env.sh" + +# Load needed modules +want root ansi log ask + +targets="prepwork admin packages patch prepboot preptmp prepetc prepvar imgboot imgconf imgetc imgvar custom" + +pebkac() { + [ "${*}" ] && printf "${*}\n\n" + echo "Usage: $(basename "${0}") <-b basedir> <-t stagedir> <-i pkgsdir> <-p patchdir>" + echo " <-r rootdir> <-l logfile> [-h] " + echo ' -b basedir Basedir for automagic defaults' + echo ' -t stagedir Staging directory name (Default: ${base}/stage)' + echo ' -i pkgsdir Directory holding packages to install (Default: ${base}/pkg)' + echo ' -p patchdir Directory holding patches to apply (Default: ${base}/patch)' + echo ' -r rootdir Directory holding the virgin source tree (Default: ${root})' + echo ' -l logfile File to hold stderr spam (Default: ${stage}/gentree.log' + echo ' -h Hello! >^-^<' + echo '' + echo 'Available targets:' + for target in ${targets} + do + echo " ${target}" + done + exit 1 +} + +while getopts "b:t:i:p:r:l:h" opt +do + case "${opt}" in + b) base="${OPTARG}" ;; + t) stage="${OPTARG}" ;; + i) pkgs="${OPTARG}" ;; + p) patch="${OPTARG}" ;; + r) root="${OPTARG}" ;; + l) logfile="${OPTARG}" ;; + h) pebkac ;; + [?]) pebkac "Unrecognized option ${opt}" ;; + esac +done +shift $(( $OPTIND - 1 )) + +sequence="${*:-${targets}}" + +base="${base:-/usr/home/cyberleo/world}" +stage="${stage:-${base}/tree}" +pkgs="${pkgs:-${base}/pkg}" +patch="${patch:-${base}/patch}" +root="${root:-${root}}" +logfile="${logfile:-${stage}/gentree.log}" + +mkdir -p "${stage}" +stage="$(realpath "${stage}")" +sroot="${stage}/root" +sboot="${stage}/boot" +sconf="${stage}/conf" + +exec 2>>"${logfile}" +_log_to_stderr=yes + +# Helper functions +onelink() { + # Make sure the provided file(s) have only one link! + while [ -n "${1}" ] + do + if [ -f "${1}" -a "$(stat -f '%l' "${1}")" -gt 1 ] + then + cp -p "${1}" "${1}.tmp" && mv "${1}.tmp" "${1}" || err "breaklink failed" + fi + shift + done +} + +# Build steps +do_prepwork() { + log Prepare workspace + if [ -d "${stage}" -a \( -d "${sroot}" -o -d "${sboot}" -o -d "${sconf}" \) ] + then + yn n " ${a_yellow}*${a_normal} Workspace already exists. Delete? [y/N]" || err Aborting + chk rm -Rf "${sroot}" "${sboot}" "${sconf}" + fi + chk mkdir -p "${sroot}" + # Eliminate schg, because it interferes with hardlinks + chk chflags -R noschg "${root}/lib" + chk chflags -R noschg "${root}/libexec" + chk chflags -R noschg "${root}/sbin" + chk chflags -R noschg "${root}/usr" + ( cd "${root}" && find . | cpio -p --link "${sroot}" ) || chk +} + +do_admin() { + log Create an emergency user admin/admin + # delink passwd to ensure it doesn't get patched in-place + chk onelink "${sroot}/etc/passwd" "${sroot}/etc/master.passwd" + echo '$1$2rXOWsK/$eiBHA6K7xL96DZbcY24YR0' | chk chroot "${sroot}" /usr/sbin/pw useradd admin -u 999 -g wheel -G operator -c Administrator -d /usr/home/admin -m -s /bin/csh -H 0 +} + +do_packages() { + if [ -d "${pkgs}" -a "$(ls -1 "${pkgs}" | wc -l)" -gt 0 ] + then + count="$(ls -1 "${pkgs}" | wc -l)" + log Install ${count} packages from "${pkgs}" + chk mkdir -p "${sroot}/pkg" + ( cd "${pkgs}" && find . | cpio -p --link "${sroot}/pkg" ) || chk + chk chroot "${sroot}" /bin/sh -c 'cd /pkg; exec pkg_add -F *' + chk rm -Rf "${sroot}/pkg" + fi +} + +do_patch() { + log Apply patches from "${patch}" + for file in "${patch}"/* + do + note "... $(basename "${file}")" + echo "... $(basename "${file}")" >&2 + ( cd "${sroot}"; patch < "${file}" ) || chk + done +} + +do_prepboot() { + log Prepare /boot + chk mv "${sroot}/boot/boot" "${sroot}/boot/boot.blk" + chk ln -sf . "${sroot}/boot/boot" +} + +do_preptmp() { + log Prepare /tmp + ( cd "${sroot}/tmp" && find . | cpio -p --link ../var/tmp ) || chk + chk rm -Rf "${sroot}/tmp" + chk ln -sf var/tmp "${sroot}/tmp" +} + +do_prepetc() { + log Prepare /etc + chk mkdir -p "${sroot}/etc/local" + chk mkdir -p "${sroot}/usr/local/etc" # Silence warnings + ( cd "${sroot}/usr/local/etc" && find . | cpio -p --link ../../../etc/local ) || chk + chk rm -Rf "${sroot}/usr/local/etc" + chk ln -sf ../../etc/local "${sroot}/usr/local/etc" +} + +do_prepvar() { + log Prepare /var + # Nothing necessary here +} + +do_imgboot() { + log Create boot imgsrc + chk mv "${sroot}/boot" "${stage}" + chk mkdir -p "${sroot}/boot" + chk rm -f "${sboot}/kernel"/*.symbols + # Gzipped kernel is okay + gzip -9 "${sboot}/kernel/kernel" + # Compress all files in /boot/kernel + # Loader cannot handle gzipped modules. Decompress the required modules + # kldload cannot handle gzipped modules either + #find "${sboot}/kernel" -type f | xargs gzip -9f || chk + #cat "${sboot}/loader.conf" | grep '_load=' | sed -e 's/^\(.*\)_load=.*$/\1/' | while read mod + #do + # [ -f "${sboot}/kernel/${mod}.ko.gz" ] && gunzip "${sboot}/kernel/${mod}.ko.gz" || chk + #done + # + # Instead: put all modules in the root image, except those needed to boot the kernel + chk mkdir -p "${sroot}/boot/boot" + chk mkdir -p "${sroot}/boot/kernel" + + # Link all modules into the root fs + ( cd "${sboot}/kernel"; find . -name '*.ko' -o -name 'linker.hints' | cpio -p --link "${sroot}/boot/kernel" ) || chk + + # Remove all modules from the root fs that are preloaded by the loader + cat "${sboot}/loader.conf" | grep '_load=' | sed -e 's#^\(.*\)_load=.*$#'"${sroot}/boot/kernel/"'\1.ko#' | xargs rm -f + + # Remove all modules from the boot fs that are present in the root fs + ( cd "${sroot}/boot/kernel"; ls -1 ) | sed -e 's#^#'"${sboot}/kernel/"'#' | xargs rm -f + + # Link the preloaded modules from the boot fs to the root fs, to provide a homogenous view + ( cd "${sboot}/kernel"; ls -1 ) | while read mod + do + ln -sf "../boot/kernel/${mod}" "${sroot}/boot/kernel/${mod}" + done +} + +do_imgconf() { + log Create conf imgsrc + chk mkdir -p "${sroot}/conf" + echo "ufs:/dev/ufs/conf" > "${sroot}/conf/diskless_remount" || chk + chk mkdir -p "${sconf}/base/etc" + chk mkdir -p "${sconf}/base/var" + chk mkdir -p "${sconf}/default/etc" + chk mkdir -p "${sconf}/default/var" +} + +do_imgetc() { + log Create etc imgsrc + chk touch "${sroot}/etc/diskless" + chk mv "${sroot}/etc" "${stage}" + chk mkdir -p "${sroot}/etc" + chk cp -p "${stage}/etc/rc" "${stage}/etc/rc.subr" "${stage}/etc/rc.initdiskless" "${stage}/etc/login.conf.db" "${stage}/etc/diskless" "${sroot}/etc" + echo "10240" > "${sconf}/base/etc/md_size" || chk + ( cd "${stage}"; find etc | cpio -o ) | gzip -9 > "${sconf}/base/etc.cpio.gz" || chk + chk rm -Rf "${stage}/etc" +} + +do_imgvar() { + log Create var imgsrc + chk mv "${sroot}/var" "${stage}" + chk mkdir -p "${sroot}/var" + echo "131072" > "${sconf}/base/var/md_size" || chk + ( cd "${stage}"; find var | cpio -o ) | gzip -9 > "${sconf}/base/var.cpio.gz" || chk + chk rm -Rf "${stage}/var" +} + +do_custom() { + log Patch in custom config + ( cd "${base}/conf" && find . | cpio -p --link "${sconf}/default" ) || chk + # Make sure files in default are newer than the tagfile, so they will be caught by saveconfig + find "${sconf}/default" -type f -print0 | xargs -0 touch +} + +for step in ${sequence} +do + echo "${targets}" | grep -q "${step}" || err Unrecognized target "${step}" + do_${step} +done diff --git a/script/genufs b/script/genufs new file mode 100755 index 0000000..e90a4dc --- /dev/null +++ b/script/genufs @@ -0,0 +1,73 @@ +#!/bin/sh + +_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" + +want root log + +min_ufs_pad=1024 + +pebkac(){ + [ "${*}" ] && echo "${*}" + echo "" + echo "Usage: genufs [-h] [-l