forked from kiss-community/kiss
kiss: Further simplify utilities.
This commit is contained in:
parent
23448e5079
commit
10333def43
@ -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
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user