diff options
Diffstat (limited to 'kerl')
-rwxr-xr-x | kerl | 169 |
1 files changed, 136 insertions, 33 deletions
@@ -28,7 +28,7 @@ KERL_DOWNLOAD_DIR=$KERL_BASE_DIR/archives KERL_BUILD_DIR=$KERL_BASE_DIR/builds KERL_CONFIGURE_OPTIONS= KERL_MAKE_OPTIONS= -KERL_INSTALL_AGNER= +KERL_DISABLE_AGNER= # ensure the base dir exsists mkdir -p $KERL_BASE_DIR @@ -45,7 +45,9 @@ usage() { echo " install Install the specified release at the given location" echo " update Update the list of available releases from erlang.org" echo " list List releases, builds and installations" + echo " delete Delete builds and installations" echo " active Print the path of the active installation" + echo " status Print available builds and installations" exit 1 } @@ -75,6 +77,24 @@ check_releases() { fi } +# c.f. agner issue #98 +# https://github.com/agner/agner/issues/#issue/98 +KERL_NO_AGNER_SUPPORT="R10B-0 R10B-2 R10B-3 R10B-4 R10B-5 R10B-6 R10B-7 +R10B-8 R10B-9 R11B-0 R11B-1 R11B-2 R11B-3 R11B-4 R11B-5 R12B-0 R12B-1 +R12B-2 R12B-3 R12B-4 R12B-5 R13A R13B R13B01 R13B02 R13B03 R13B04" + +agner_support() { + if [ -z "$KERL_DISABLE_AGNER" ]; then + for v in $KERL_NO_AGNER_SUPPORT; do + if [ "$v" = "$1" ]; then + return 1 + fi + done + return 0 + fi + return 1 +} + assert_valid_release() { check_releases for rel in `cat $KERL_BASE_DIR/otp_releases`; do @@ -86,6 +106,13 @@ assert_valid_release() { exit 1 } +is_valid_installation() { + if [ -f "$1/activate" ]; then + return 0 + fi + return 1 +} + do_build() { assert_valid_release $1 FILENAME=otp_src_$1.tar.gz @@ -110,23 +137,35 @@ do_build() { echo "Extracting source code" cd $KERL_BUILD_DIR && tar xfz $KERL_DOWNLOAD_DIR/$FILENAME fi + mkdir -p "$KERL_BASE_DIR/install" echo "Building Erlang/OTP $1, please wait..." cd $KERL_BUILD_DIR/otp_src_$1 - ./configure $KERL_CONFIGURE_OPTIONS > \ + ./configure $KERL_CONFIGURE_OPTIONS --prefix="$KERL_BASE_DIR/install/$1" > \ $KERL_BASE_DIR/logs/configure_$1.log 2>&1 if [ "$?" -eq 1 ]; then echo "./configure failed, see $KERL_BASE_DIR/logs/configure_$1.log"; exit 1 fi rm -f "$KERL_BASE_DIR/logs/configure_$1.log" - make $KERL_MAKE_OPTIONS > $KERL_BASE_DIR/logs/build_$1.log 2>&1 + make $KERL_MAKE_OPTIONS > $KERL_BASE_DIR/logs/build_$1.log 2>&1 && \ + make install > $KERL_BASE_DIR/logs/build_$1.log 2>&1 if [ "$?" -eq 1 ]; then - echo "Build failed, see $KERL_BASE_DIR/logs/build_$1.log"; + echo "Build failed, see $KERL_BASE_DIR/logs/build_$1.log" list_remove builds $2 fi rm -f "$KERL_BASE_DIR/logs/build_$1.log" - echo "Erlang/OTP $1 has been successfully built"; + echo "Erlang/OTP $1 has been successfully built" list_add builds $1 + if agner_support $1; then + echo "Fetching and building agner..." + cd "$KERL_BASE_DIR/builds" && \ + git clone https://github.com/agner/agner.git agner_$1 > /dev/null 2>&1 && \ + cd agner_$1 && PATH="$KERL_BASE_DIR/otp_src_$1/bin:$PATH" make > /dev/null 2>&1 + if [ "$?" -eq 1 ]; then + echo "Agner install failed"; exit 1 + fi + echo "Agner has been successfully built" + fi } do_install() { @@ -143,8 +182,8 @@ do_install() { absdir=`cd "$2" && pwd` echo "Installing Erlang/OTP $1 in $absdir..." cd $KERL_BUILD_DIR/otp_src_$1 - ./configure --prefix="$absdir" > /dev/null 2>&1 - make install > /dev/null 2>&1 + ./configure $KERL_CONFIGURE_OPTIONS --prefix="$absdir" > /dev/null 2>&1 && + make $KERL_MAKE_OPTIONS install > /dev/null 2>&1 if [ $? -eq 1 ]; then echo "Couldn't install Erlang/OTP $1 in $absdir" exit 1 @@ -163,10 +202,10 @@ kerl_deactivate() { export AGNER_BIN unset _KERL_SAVED_AGNER_BIN fi - if [ -n "\$_KERL_SAVED_AGNER_PREFIX" ]; then - AGNER_PREFIX="\$_KERL_SAVED_AGNER_PREFIX" - export AGNER_PREFIX - unset _KERL_SAVED_AGNER_PREFIX + if [ -n "\$_KERL_SAVED_AGNER_EXACT_PREFIX" ]; then + AGNER_EXACT_PREFIX="\$_KERL_SAVED_AGNER_EXACT_PREFIX" + export AGNER_EXACT_PREFIX + unset _KERL_SAVED_AGNER_EXACT_PREFIX fi if [ -n "\$BASH" -o -n "\$ZSH_VERSION" ]; then hash -r @@ -180,28 +219,32 @@ _KERL_SAVED_PATH="\$PATH" export _KERL_SAVED_PATH _KERL_SAVED_AGNER_BIN="\$AGNER_BIN" export _KERL_SAVED_AGNER_BIN -_KERL_SAVED_AGNER_PREFIX="\$AGNER_PREFIX" -export _KERL_SAVED_AGNER_PREFIX +_KERL_SAVED_AGNER_EXACT_PREFIX="\$AGNER_EXACT_PREFIX" +export _KERL_SAVED_AGNER_EXACT_PREFIX PATH="$absdir/bin:\$PATH" export PATH AGNER_BIN="$absdir/bin" export AGNER_BIN -AGNER_PREFIX="$absdir/agner" -export AGNER_PREFIX +AGNER_EXACT_PREFIX="$absdir/lib/erlang/lib" +export AGNER_EXACT_PREFIX if [ -n "\$BASH" -o -n "\$ZSH_VERSION" ]; then hash -r fi ACTIVATE - if [ -n "$KERL_INSTALL_AGNER" ]; then + if agner_support $1; then echo "Installing agner in $absdir..." - . "$absdir/activate" && cd "$absdir" && \ - git clone https://github.com/agner/agner.git agner_build > /dev/null 2>&1 && \ - cd agner_build && make > /dev/null 2>&1 && \ + . "$absdir/activate" && cd "$KERL_BASE_DIR/builds/agner_$1" && \ ./agner install agner > /dev/null 2>&1 if [ "$?" -eq 1 ]; then echo "Couldn' install agner in $absdir" exit 1 fi + if [ -n "$KERL_AGNER_AUTOINSTALL" ]; then + for i in $KERL_AGNER_AUTOINSTALL; do + echo "Autoinstalling $i" + agner install $i > /dev/null 2>&1 + done + fi fi rm -Rf "$absdir/agner_build" echo "You can activate this installation running the following command:" @@ -224,22 +267,22 @@ list_print() { list_add() { if [ -f $KERL_BASE_DIR/otp_$1 ]; then - grep $2 $KERL_BASE_DIR/otp_$1 > /dev/null 2>&1 || \ - echo $2 >> $KERL_BASE_DIR/otp_$1 + grep "$2" $KERL_BASE_DIR/otp_$1 > /dev/null 2>&1 || \ + echo "$2" >> $KERL_BASE_DIR/otp_$1 else - echo $2 > $KERL_BASE_DIR/otp_$1 + echo "$2" > $KERL_BASE_DIR/otp_$1 fi } list_remove() { - if [ -f $KERL_BASE_DIR/otp_$1 ]; then - sed -i -e '/$2/d' $KERL_BASE_DIR/otp_$1 + if [ -f "$KERL_BASE_DIR/otp_$1" ]; then + sed -i -e "/^.*$2$/d" "$KERL_BASE_DIR/otp_$1" fi } list_has() { - if [ -f $KERL_BASE_DIR/otp_$1 ]; then - grep $2 $KERL_BASE_DIR/otp_$1 > /dev/null 2>&1 && return 0 + if [ -f "$KERL_BASE_DIR/otp_$1" ]; then + grep $2 "$KERL_BASE_DIR/otp_$1" > /dev/null 2>&1 && return 0 fi return 1 } @@ -248,6 +291,21 @@ list_usage() { echo "usage: $0 list <releases|builds|installations>" } +delete_usage() { + echo "usage: $0 delete <build|installation> id_or_path" +} + +do_active() { + if [ -n "$_KERL_SAVED_PATH" ]; then + echo "The current active installation is:" + echo `echo $PATH | cut -d ":" -f 1 | head -c -4` + return 0 + else + echo "No Erlang/OTP kerl installation is currently active" + return 1 + fi +} + case "$1" in build) if [ $# -ne 2 ]; then @@ -262,13 +320,13 @@ case "$1" in exit 1 fi if [ $# -eq 3 ]; then - do_install $2 $3 + do_install $2 "$3" else do_install $2 . fi ;; update) - rm -f $KERL_BASE_DIR/otp_releases + rm -f "$KERL_BASE_DIR/otp_releases" check_releases echo "The available releases are:" list_print releases spaces @@ -297,15 +355,60 @@ case "$1" in ;; esac ;; + delete) + if [ $# -ne 3 ]; then + delete_usage + exit 1 + fi + case "$2" in + build) + assert_valid_release $3 + if [ -d "$KERL_BUILD_DIR/otp_src_$3" ]; then + rm -Rf $KERL_BUILD_DIR/otp_src_$3 + rm -Rf $KERL_BUILD_DIR/agner_$3 + list_remove $2s $3 + echo "The $3 build has been deleted" + else + echo "No build for Erlang/OTP $3" + exit 1 + fi + ;; + installation) + if is_valid_installation "$3"; then + rm -Rf "$3" + escaped=`echo "$3" | sed -e 's#\/#\\\/#g'` + list_remove $2s "$escaped" + echo "The installation in $3 has been deleted" + else + echo "$3 is not a kerl-managed Erlang/OTP installation" + exit 1 + fi + ;; + *) + echo "Cannot delete $2" + delete_usage + exit 1 + ;; + esac + ;; active) - if [ -n "$_KERL_SAVED_PATH" ]; then - echo "The current active installation is:" - echo `echo $PATH | cut -d ":" -f 1 | head -c -4` - else - echo "No Erlang/OTP kerl installation is currently active" + if ! do_active; then + exit 1; fi ;; + status) + echo "Available builds:" + list_print builds + echo "----------" + echo "Available installations:" + list_print installations + echo "----------" + echo "Currently active installation:" + do_active + exit 0 + ;; *) echo "unkwnown command: $1"; usage; exit 1 ;; esac + |