Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
pkg-scripts/tools/build.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
72 lines (56 sloc)
1.71 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
set -e | |
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/package/bin:/usr/local/bin | |
umask 022 | |
die() { | |
echo "$@" | |
exit 1 | |
} | |
die_usage() { | |
die "usage: $0 example-1.2.3-0 [--purge]" | |
} | |
ere_quote() { | |
sed 's/[]\.|$(){}?+*^]/\\&/g' <<< "$*" | |
} | |
log_cmd() { | |
echo "$@" | |
"$@" | |
} | |
eval set -- $(getopt --options "" --longoptions purge -- "$@") | |
while true; do | |
case "$1" in | |
--purge) opt_purge=1;shift;; | |
--) shift;break;; | |
*) die "internal error: unknown option $!" | |
esac | |
done | |
test $# -eq 1 || die_usage | |
PKG="$1" | |
PKG="${PKG%.build.sh}" | |
grep -q -E "^$(ere_quote "$PKG")\b" /etc/mxpkg || die "$PKG not found in mxpkg" | |
test -e "$PKG.build.sh" || die "$PKG.build.sh: file does not exist" | |
test $UID -eq 0 || die "$0: please run with sudo" | |
if [ ! -d "/package/pkg/$PKG" ]; then | |
log_cmd mkdir -p "/package/pkg/$PKG" | |
log_cmd chown build:build "/pkg/$PKG" | |
fi | |
if [ "$(stat -c %U "/pkg/$PKG")" != "build" ] && [ -z "$opt_purge" ] ; then | |
echo "/pkg/$PKG is no longer owned by build user" | |
echo "rerun with --purge if you want to build from scratch" | |
exit 1 | |
fi | |
if [ -n "$opt_purge" ]; then | |
# make double sure PKG is not empty even if bugs are introduced in code above | |
test -z "$PKG" && die "internal error: PKG is empty" | |
log_cmd find "/pkg/$PKG" -mindepth 1 -delete | |
test "$(stat -c %U "/pkg/$PKG")" = "build" || log_cmd chown build:build "/pkg/$PKG" | |
fi | |
chmod a+rx "$PKG.build.sh" | |
echo "sudo -u build script -q -c \"./$PKG.build.sh\" $PKG.build.log" | |
( | |
sudo -u build script -q -c "./$PKG.build.sh" $PKG.build.log | |
sudo -u build cp "$PKG.build.sh" "/package/pkg/$PKG/.$PKG.build.sh" | |
) | |
# make double sure PKG is not empty even if bugs are introduced in code above | |
test -z "$PKG" && die "internal error: PKG is empty" | |
log_cmd chown -R bin:bin "/pkg/$PKG" |