From 10333def43cee4e79190b7da16fa17135a812d6a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 18 Apr 2020 12:27:38 +0300 Subject: [PATCH] kiss: Further simplify utilities. --- contrib/kiss-chroot | 52 +++++++++++++++++++++------------------------ contrib/kiss-new | 51 ++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 61 deletions(-) diff --git a/contrib/kiss-chroot b/contrib/kiss-chroot index c61233b..cca0e38 100755 --- a/contrib/kiss-chroot +++ b/contrib/kiss-chroot @@ -23,36 +23,32 @@ clean() { } } -main() { - [ -z "$1" ] && die Need a path to the chroot - [ -d "$1" ] || die Given path does not exist - [ "$(id -u)" = 0 ] || die Script needs to be run as root +[ -z "$1" ] && die Need a path to the chroot +[ -d "$1" ] || die Given path does not exist +[ "$(id -u)" = 0 ] || die Script needs to be run as root - trap 'clean "$1"' EXIT INT +trap 'clean "$1"' EXIT INT - log Mounting /dev, /proc and /sys from host; { - mountpoint -q "$1/dev" || mount -o bind /dev "$1/dev" - mountpoint -q "$1/proc" || mount -t proc proc "$1/proc" - mountpoint -q "$1/sys" || mount -t sysfs sys "$1/sys" +log Mounting /dev, /proc and /sys from host; { + mountpoint -q "$1/dev" || mount -o bind /dev "$1/dev" + mountpoint -q "$1/proc" || mount -t proc proc "$1/proc" + mountpoint -q "$1/sys" || mount -t sysfs sys "$1/sys" - } - - log Copying /etc/resolv.conf from host; { - cp -f /etc/resolv.conf "$1/etc" - } - - log Entering chroot; { - chroot "$1" /usr/bin/env -i \ - HOME=/root \ - TERM="$TERM" \ - SHELL=/bin/sh \ - USER=root \ - KISS_ASROOT=1 \ - CFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \ - CXXFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \ - MAKEFLAGS="-j$(nproc 2>/dev/null || echo 1)" \ - /bin/sh -l - } } -main "$@" +log Copying /etc/resolv.conf from host; { + cp -f /etc/resolv.conf "$1/etc" +} + +log Entering chroot; { + chroot "$1" /usr/bin/env -i \ + HOME=/root \ + TERM="$TERM" \ + SHELL=/bin/sh \ + USER=root \ + KISS_ASROOT=1 \ + CFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \ + CXXFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \ + MAKEFLAGS="-j$(nproc 2>/dev/null || echo 1)" \ + /bin/sh -l +} diff --git a/contrib/kiss-new b/contrib/kiss-new index db82dec..9eeb8f3 100755 --- a/contrib/kiss-new +++ b/contrib/kiss-new @@ -2,45 +2,30 @@ # Create a boilerplate package. die() { - printf 'error: %s.\n' "$*" >&2 + printf '%s\n' "$*" exit 1 } log() { - printf '=> %s.\n' "$*" + printf '=> %s.\n' "$1" } -main() { - [ "$1" ] || { - log Create boilerplate KISS packages - log Usage: kiss-new name version source +[ "$1" ] || die "usage: kiss-new [name] [version] [source]" +[ -d "$1" ] && die "error: Package $1 already exists" +mkdir -p "$1" || die "error: Couldn't create directory in $PWD" +cd "$1" || die "error: Couldn't enter directory $1/" - exit - } - - [ -d "$1" ] && - die Package "$1" already exists. - - mkdir -p "$1" || - die Couldn\'t create directory in "$PWD" - - cd "$1" || - die Couldn\'t enter directory "$1/" - - log Creating build file; { - printf '#!/bin/sh -e\n' > build - chmod +x build - } - - log Creating version file with "'${2%% *} 1'"; { - printf '%s\n' "${2%% *} 1" > version - } - - log Creating sources file with "'$3'"; { - printf '%s\n' "$3" > sources - } - - log Package "$1" created in "$PWD" +log "Creating build file"; { + printf '#!/bin/sh -e\n' > build + chmod +x build } -main "$@" +log "Creating version file with '${2%% *} 1'"; { + printf '%s\n' "${2%% *} 1" > version +} + +log "Creating sources file with '$3'"; { + printf '%s\n' "$3" > sources +} + +log "Package $1 created in $PWD"