kiss: Further simplify utilities.

This commit is contained in:
Dylan Araps 2020-04-18 12:27:38 +03:00
parent 23448e5079
commit 10333def43
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
2 changed files with 42 additions and 61 deletions

View File

@ -23,25 +23,24 @@ 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; {
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; {
log Copying /etc/resolv.conf from host; {
cp -f /etc/resolv.conf "$1/etc"
}
}
log Entering chroot; {
log Entering chroot; {
chroot "$1" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
@ -52,7 +51,4 @@ main() {
CXXFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \
MAKEFLAGS="-j$(nproc 2>/dev/null || echo 1)" \
/bin/sh -l
}
}
main "$@"

View File

@ -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; {
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"
}
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"