diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-01-05 13:50:53 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-01-05 13:50:53 -0500 |
commit | 13918acf5d6104fd696175d682b4300e42b9159b (patch) | |
tree | 9fc6ed02c9c3864d01a764f5cd5900ebdb3fa302 | |
download | pkg_creator-13918acf5d6104fd696175d682b4300e42b9159b.tar.gz |
Initial commit
-rw-r--r-- | common.inc | 38 | ||||
-rwxr-xr-x | pkg_create | 19 | ||||
-rwxr-xr-x | pkg_init | 41 |
3 files changed, 98 insertions, 0 deletions
diff --git a/common.inc b/common.inc new file mode 100644 index 0000000..f56290b --- /dev/null +++ b/common.inc @@ -0,0 +1,38 @@ +function readlink_ex +{ + script_location= + FAILURE=0 + if [ -e "$(which readlink 2>/dev/null)" ]; then + export script_location=$(dirname `readlink -f "$1"`) + retval=$? + if [ $retval -ne 0 ]; then + export FAILURE=1 + fi + else + export FAILURE=0 + fi + + # Well, if readlink doesn't work we only have one more option (i.e that I care to implement) + if [ $FAILURE -ne 0 ];then + export FAILURE=0 + export script_location=$(python -c "from __future__ import print_function; import os; print('{0}'.format(os.path.abspath(os.curdir)));") + retval=$? + if [ $retval -ne 0 ]; then + export FAILURE=1 + fi + fi + + if [ $FAILURE -ne 0 ]; then + echo "readlink failure. abort." + exit 1 + fi + + echo $script_location +} + +function init_vars +{ + scripts_default=( preinstall postinstall ) + PKGBUILD_CMD="pkgbuild" + PKGBUILD_ARGS="--scripts $PKG_SCRIPTS --identifier edu.stsci.$PKG_NAME.pkg --root $PKG_ROOT" +} diff --git a/pkg_create b/pkg_create new file mode 100755 index 0000000..4297f38 --- /dev/null +++ b/pkg_create @@ -0,0 +1,19 @@ +#!/bin/bash +source common.inc + +PKG_NAME="$1" +_ROOT="$(readlink_ex $0)" +_PKG_ROOT="$_ROOT/$PKG_NAME" +PKG_ROOT="$_PKG_ROOT/root" +PKG_SCRIPTS="$_PKG_ROOT/scripts" + +init_vars + + +if [ -z "$PKG_NAME" ]; then + echo Please give your package a name. + exit 1 +fi + +PKG_NAME="$PKG_NAME.pkg" +$PKGBUILD_CMD $PKGBUILD_ARGS $PKG_NAME diff --git a/pkg_init b/pkg_init new file mode 100755 index 0000000..36a497f --- /dev/null +++ b/pkg_init @@ -0,0 +1,41 @@ +#!/bin/bash +source common.inc + +PKG_NAME="$1" +_ROOT="$(readlink_ex $0)" +_PKG_ROOT="$_ROOT/$PKG_NAME" +PKG_ROOT="$_PKG_ROOT/root" +PKG_SCRIPTS="$_PKG_ROOT/scripts" + +if [ -z "$PKG_NAME" ]; then + echo Please give your package a name. + exit 1 +fi + +if [ -d "$_PKG_ROOT" ]; then + echo $_PKG_ROOT already exists. + exit 1 +fi + +# Create directories +mkdir -p "$PKG_ROOT" +mkdir -p "$PKG_SCRIPTS" + +# Generate template scripts +for template in "${scripts_default[@]}" +do +script="$PKG_SCRIPTS/$template" +cat << EOF > "$script" +#!/bin/bash +# +# Do stuff here +# + +exit 0 +EOF + +chmod 755 "$script" + +done + + |