Created
January 20, 2015 17:16
-
-
Save wiedi/9a721c7b207c12acc3fc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
REPO=$(pwd) | |
if [ $# -eq 1 ]; then | |
REPO="$1" | |
fi | |
fail() { | |
echo "$*" >&2 | |
exit 1 | |
} | |
sanitycheck() { | |
[[ -d "${REPO}" ]] || fail "Build repository ${REPO} doesn\'t exist" | |
[[ -f "${REPO}/manifest" ]] || fail "Can't find manifest" | |
#[[ -f "${REPO}/manifest.json" ]] || fail "Can't find manifest" | |
[[ -f "${REPO}/customize" ]] || fail "Can't find customize script" | |
} | |
create_copyin_archive() { | |
echo 'dump_archive() {' | |
echo " uudecode -p <<'__EOM__'" | |
(cd ${REPO}/copy && tar -c . | uuencode -m -) | |
echo "__EOM__" | |
echo '}' | |
} | |
copyin() { | |
create_copyin_archive | |
echo 'dump_archive | gtar -C / -x --no-same-owner' | |
} | |
read_manifest() { | |
# find something better... | |
source "${REPO}/manifest" | |
} | |
product() { | |
PRODUCT=/etc/product | |
echo "echo \"Name: ${organization} ${brand}\" > $PRODUCT" | |
echo "echo \"Image: ${name} ${version}\" >> $PRODUCT" | |
echo "echo \"Documentation: ${homepage}\" >> $PRODUCT" | |
} | |
motd() { | |
[[ ! -f "${REPO}/motd" ]] && return | |
echo "cat /etc/motd <<'__EOM__'" | |
(sed -e "s!%brand%!${brand}!g" \ | |
-e "s!%name%!${name}!g" \ | |
-e "s!%version%!${version}!g" \ | |
-e "s!%homepage%!${homepage}!g" "${REPO}/motd") | |
echo "__EOM__" | |
} | |
bootstrap() { | |
[[ ! -f "${REPO}/bootstrap" ]] && return | |
cat "${REPO}/bootstrap" | |
} | |
pkg() { | |
[[ ! -f "${REPO}/packages" ]] && return | |
packages=$(grep -e ^# -v ${REPO}/packages | xargs) | |
echo "pkgin -f -y up" | |
echo "pkg_add -v $packages" | |
} | |
customize() { | |
cat "${REPO}/customize" | |
} | |
main() { | |
sanitycheck | |
create_copyin_archive | |
copyin | |
read_manifest | |
product | |
motd | |
bootstrap | |
pkg | |
customize | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment