Skip to content

Commit

Permalink
Add 'kerl deploy' command to deploy an installation to a given host a…
Browse files Browse the repository at this point in the history
…nd directory
  • Loading branch information
scalone-cw committed May 9, 2024
1 parent 6d4f48b commit 095247e
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 17 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ You can verify your build has been registered:
R14B02,r14b02_hipe

Now install a build to some location (optionally you can disable agner support by adding KERL_DISABLE_AGNER=yes to your $HOME/.kerlrc file, or on the contrary define a list of additional packages to install using the KERL_AGNER_AUTOINSTALL directive in the same file or on the command line):

$ kerl install r14b02 /path/to/install/dir/
Installing Erlang/OTP R14B02 (r14b02) in /path/to/install/dir...
Installing agner in /path/to/install/dir...
Expand Down Expand Up @@ -144,13 +144,23 @@ You can get an overview of the current kerl state with:
/path/to/install/dir

You can delete builds and installations with the following commands:

$ kerl delete build r14b02
The r14b02 build has been deleted

$ kerl delete installation /path/to/install/dir
The installation in /path/to/install/dir has been deleted

You can easily deploy an installation to another host having ssh and rsync access with the following command:

$ kerl deploy anotherhost /path/to/install/dir

Cloning Erlang/OTP r14b02 (/path/to/install/dir) to anotherhost (/path/to/install/dir) ...
On anotherhost, you can activate this installation running the following command:
. /path/to/install/dir/activate
Later on, you can leave the installation typing:
kerl_deactivate

You can update the agner version associated with a specific build (this will only affect installations made after that):

$ kerl update agner r14b02
Expand Down Expand Up @@ -183,6 +193,8 @@ You can set the following variables:
- KERL_USE_AUTOCONF use autoconf in the builds process
- KERL_INSTALL_MANPAGES if non-empty will install manpages
- KERL_INSTALL_HTMLDOCS if non-empty will install HTML docs
- KERL_DEPLOY_SSH_OPTIONS if additional options are required, e.g. "-qx -o PasswordAuthentication=no"
- KERL_DEPLOY_RSYNC_OPTIONS if additional options are required, e.g. "--delete"

Glossary
========
Expand Down Expand Up @@ -241,7 +253,7 @@ Install a named build to the specified filesystem location

kerl install <build_name> [path]

If path is ommited the current working directory will be used. However, if KERL_DEFAULT_INSTALL_DIR is defined in ~/.kerlrc, KERL_DEFAULT_INSTALL_DIR/<build-name> will be used instead.
If path is omitted the current working directory will be used. However, if KERL_DEFAULT_INSTALL_DIR is defined in ~/.kerlrc, KERL_DEFAULT_INSTALL_DIR/<build-name> will be used instead.

*Note*: kerl assumes the specified directory is for its sole use. If you later delete it with the kerl delete command, the whole directory will be deleted, along with anything you may have added to it!

Expand All @@ -267,6 +279,34 @@ You can have manpages installed automatically setting KERL_INSTALL_MANPAGES=yes

You can have HTML docs installed automatically setting KERL_INSTALL_HTMLDOCS=yes in your $HOME/.kerlrc file or prepending it to the command line

deploy
------

Deploy the specified installation to the given host and location

### Syntax

kerl deploy <[user@]host> [directory] [remote_directory]

If remote_directory is omitted the specified directory will be used.

If directory and remote_directory is omitted the current working directory will be used.

*NOTE*: kerl assumes the specified host is accessible via ssh and rsync.

### Example

$ kerl deploy anotherhost /path/to/install/dir

### Tuning

#### Additional SSH options

You can have additional options given to SSH by setting them in the KERL_DEPLOY_SSH_OPTIONS variable in your $HOME/.kerlrc file or on the command line, e.g. KERL_DEPLOY_SSH_OPTIONS="-qx -o PasswordAuthentication=no"

#### Additional RSYNC options

You can have additional options given to RSYNC by setting them in the KERL_DEPLOY_RSYNC_OPTIONS variable in your $HOME/.kerlrc file or on the command line, e.g. KERL_DEPLOY_RSYNC_OPTIONS="--delete"

update
------
Expand Down
18 changes: 13 additions & 5 deletions bash_completion/kerl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ _kerl()
RELEASES=`cat "$HOME/.kerl/otp_releases"`
fi
COMPREPLY=( $( compgen -W "git $RELEASES" -- "$cur") )
else
else
if [ -f "$HOME/.kerl/otp_builds" ]; then
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
fi
COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
fi
Expand All @@ -33,10 +33,18 @@ _kerl()
;;
install)
if [ -f "$HOME/.kerl/otp_builds" ]; then
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
fi
COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
;;
deploy)
if [ "$COMP_CWORD" -eq 3 ]; then
if [ -f "$HOME/.kerl/otp_installations" ]; then
PATHS=`cat "$HOME/.kerl/otp_installations" | cut -d " " -f 2`
fi
fi
COMPREPLY=( $( compgen -W "$PATHS" -- "$cur") )
;;
delete)
COMPREPLY=( $( compgen -W "build installation $words" -- "$cur") )
;;
Expand All @@ -46,15 +54,15 @@ _kerl()
agner)
if [ "$COMP_CWORD" -eq 3 ]; then
if [ -f "$HOME/.kerl/otp_builds" ]; then
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
fi
fi
COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
;;
*)
if [ "$COMP_CWORD" -eq 3 ]; then
if [ -f "$HOME/.kerl/otp_builds" ]; then
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
fi
if [ -n "$BUILDS" ]; then
for b in $BUILDS; do
Expand Down
100 changes: 91 additions & 9 deletions kerl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ fi
if [ -n "$KERL_AGNER_AUTOINSTALL" ]; then
_KAA="$KERL_AGNER_AUTOINSTALL"
fi
if [ -n "$KERL_DEPLOY_SSH_OPTIONS" ]; then
_KDSSH="$KERL_DEPLOY_SSH_OPTIONS"
fi
if [ -n "$KERL_DEPLOY_RSYNC_OPTIONS" ]; then
_KDRSYNC="$KERL_DEPLOY_RSYNC_OPTIONS"
fi
KERL_CONFIGURE_OPTIONS=
KERL_DISABLE_AGNER=
KERL_SASL_STARTUP=
Expand All @@ -56,6 +62,12 @@ fi
if [ -n "$_KAA" ]; then
KERL_AGNER_AUTOINSTALL="$_KAA"
fi
if [ -n "$_KDSSH" ]; then
KERL_DEPLOY_SSH_OPTIONS="$_KDSSH"
fi
if [ -n "$_KDRSYNC" ]; then
KERL_DEPLOY_RSYNC_OPTIONS="$_KDRSYNC"
fi

if [ -z "$KERL_SASL_STARTUP" ]; then
INSTALL_OPT=-minimal
Expand Down Expand Up @@ -85,6 +97,7 @@ usage()
echo "Valid commands are:"
echo " build Build specified release or git repository"
echo " install Install the specified release at the given location"
echo " deploy Deploy the specified installation to the given host and location"
echo " update Update agner or the list of available releases from erlang.org"
echo " list List releases, builds and installations"
echo " delete Delete builds and installations"
Expand Down Expand Up @@ -201,6 +214,15 @@ is_valid_installation()
return 1
}

assert_valid_installation()
{
if ! is_valid_installation $1; then
echo "$1 is not a kerl-managed Erlang/OTP installation"
exit 1
fi
return 0
}

do_update_agner()
{
rel=`get_release_from_name $1`
Expand Down Expand Up @@ -462,6 +484,55 @@ ACTIVATE
echo "kerl_deactivate"
}

do_deploy()
{
if [ -z "$1" ]; then
echo "No host given"
exit 1
fi
host=$1

assert_valid_installation "$2"
rel=`get_name_from_install_path "$2"`
path=$2
remotepath=$path

if [ ! -z "$3" ]; then
remotepath=$3
fi

ssh $KERL_DEPLOY_SSH_OPTIONS $host true > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Couldn't ssh to $host"
exit 1
fi

echo "Cloning Erlang/OTP $rel ($path) to $host ($remotepath) ..."

rsync -aqz -e "ssh $KERL_DEPLOY_SSH_OPTIONS" $KERL_DEPLOY_RSYNC_OPTIONS "$path/" "$host:$remotepath/"
if [ $? -ne 0 ]; then
echo "Couldn't rsync Erlang/OTP $rel ($path) to $host ($remotepath)"
exit 1
fi

ssh $KERL_DEPLOY_SSH_OPTIONS $host "cd \"$remotepath\" && env ERL_TOP=\`pwd\` ./Install $INSTALL_OPT \`pwd\` > /dev/null 2>&1"
if [ $? -ne 0 ]; then
echo "Couldn't install Erlang/OTP $rel to $host ($remotepath)"
exit 1
fi

ssh $KERL_DEPLOY_SSH_OPTIONS $host "cd \"$remotepath\" && sed -i -e \"s#$path#\`pwd\`#g\" activate"
if [ $? -ne 0 ]; then
echo "Couldn't completely install Erlang/OTP $rel to $host ($remotepath)"
exit 1
fi

echo "On $host, you can activate this installation running the following command:"
echo ". $remotepath/activate"
echo "Later on, you can leave the installation typing:"
echo "kerl_deactivate"
}

list_print()
{
if [ -f $KERL_BASE_DIR/otp_$1 ]; then
Expand Down Expand Up @@ -600,6 +671,21 @@ case "$1" in
fi
fi
;;
deploy)
if [ $# -lt 2 ]; then
echo "usage: $0 $1 <[user@]host> [directory] [remote_directory]"
exit 1
fi
if [ $# -eq 4 ]; then
do_deploy $2 "$3" "$4"
else
if [ $# -eq 3 ]; then
do_deploy $2 "$3"
else
do_deploy $2 .
fi
fi
;;
update)
if [ $# -lt 2 ]; then
update_usage
Expand Down Expand Up @@ -675,15 +761,11 @@ case "$1" in
fi
;;
installation)
if is_valid_installation "$3"; then
rm -Rf "$3"
escaped=`echo "$3" | sed $SED_OPT -e 's#/$##' -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
assert_valid_installation "$3"
rm -Rf "$3"
escaped=`echo "$3" | sed $SED_OPT -e 's#/$##' -e 's#\/#\\\/#g'`
list_remove $2s "$escaped"
echo "The installation in $3 has been deleted"
;;
*)
echo "Cannot delete $2"
Expand Down

0 comments on commit 095247e

Please sign in to comment.