├── .gitignore ├── LICENSE ├── README.md ├── install └── kiex /.gitignore: -------------------------------------------------------------------------------- 1 | .??*.swp 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2016 Taylor Carpenter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | kiex - Elixir version manager 2 | ==== 3 | 4 | Kiex allows you to easily build and switch between different [Elixir](http://elixir-lang.org/) versions. 5 | 6 | It supports setting the default (global) Elixir version as well as per shell/project versions. 7 | 8 | Everything is self-contained under ~/.kiex. 9 | 10 | Usage is based *lightly* on [RVM](http://rvm.io), [kerl](https://github.com/spawngrid/kerl), and [rbenv](https://github.com/sstephenson/rbenv). 11 | 12 | *NOTE:* Some Erlang source builds are broken. [See below](#notes). 13 | 14 | ### Install 15 | 16 | **Prerequisites:** bash, curl, erlang, git, make, openssl 17 | 18 | Run the following to get up and running: 19 | 20 | ``` 21 | \curl -sSL https://raw.githubusercontent.com/taylor/kiex/master/install | bash -s 22 | ``` 23 | 24 | which will install in $HOME/.kiex. 25 | 26 | ### Usage 27 | 28 | List installed versions 29 | * ``` kiex list ``` 30 | 31 | List known releases 32 | * ``` kiex list known ``` (or ``` kiex list releases ```) 33 | 34 | List current branches 35 | * ``` kiex list branches ``` 36 | 37 | Install a known release or branch. 38 | * ``` kiex install 0.12.5 ``` 39 | 40 | Use specific elixir version 41 | * ``` kiex use 0.12.5 ``` -- Sets the elixir version for current shell. 42 | 43 | Create an alias for the specified elixir version 44 | * ``` kiex alias 0.12.5 0.12 ``` 45 | 46 | Use sub-shell with specific elixir version 47 | * ``` kiex shell 0.12.5 ``` -- Starts sub-shell with given elixir version. Exiting shell goes to default. 48 | 49 | Set default elixir version 50 | * ``` kiex default 0.12.5 ``` 51 | 52 | Uninstall kiex and elixirs 53 | * ``` kiex implode ``` -- This removes all versions of elixir installed by kiex as well as all kiex components 54 | 55 | Upgrade kiex 56 | * ``` kiex selfupdate ``` -- pull down latest updates for kiex 57 | - Can also re-curl 58 | 59 | ### Sourcing elixir into your path 60 | 61 | After installing your preferred version of elixir and setting it as your default you can use kiex scripts to 62 | put your default elixir bin into your path. One way to do this is to add the following line into your rc file: 63 | 64 | ``` 65 | [[ -s "$HOME/.kiex/scripts/kiex" ]] && source "$HOME/.kiex/scripts/kiex" 66 | ``` 67 | 68 | ### Design philosophy 69 | 70 | * KISS 71 | * Sane defaults 72 | * Self-contained 73 | * Single-purpose 74 | 75 | 76 | #### Comparison Q&A 77 | 78 | How is it like exenv (rbenv)? 79 | * Super light and simple 80 | * Focus on installing & managing one piece of software: Elixir 81 | 82 | How is it not like exenv? 83 | * Does not use shims 84 | * Includes elixir build component 85 | 86 | How is it like Kerl? 87 | * Minimal command set 88 | * Retrieves, builds, installs and manages different releases 89 | 90 | How is it not like Kerl? 91 | * Not as flexible on install path 92 | * Dynamically gets release list instead of caching 93 | * Build and install actions are not separated 94 | 95 | How is it like RVM? 96 | * Sane defaults 97 | * Uses Unix PATH to manage binary to use 98 | 99 | How is it not like RVM? 100 | * No function over-loading 101 | * Does not manage/install extra software and prereqs 102 | 103 | 104 | ### Platforms/Shells tested 105 | 106 | Operating Systems: 107 | * Arch 108 | * CentOS 109 | * Debian 110 | * FreeBSD 111 | * OS X/Darwin 112 | * Ubuntu 113 | 114 | Shells: 115 | * bash 116 | * csh 117 | * tcsh 118 | * zsh 119 | 120 | Erlang installs: 121 | * erlang-solutions 122 | * erlang.org 123 | * kerl 124 | * Debian apt, FreeBSD pkg, OS X brew 125 | 126 | ### Alternatives and References 127 | 128 | Alternatives: 129 | * [exenv](https://github.com/mururu/exenv) + [elixir-build](https://github.com/mururu/elixir-build) 130 | * [edwb](https://github.com/clutchanalytics/edwb) 131 | * [asdf](https://github.com/HashNuke/asdf) extendable version manager for multiple languages (eg. ruby, erlang, elixir) 132 | 133 | Related tools: 134 | * [kerl](https://github.com/spawngrid/kerl) - Easy building and installing of Erlang/OTP instances 135 | * [kex](https://github.com/d0rc/kex) - Build any tagged release of Erlang/OTP or Elixir from git 136 | * [heroku-buildpack-elixir](https://github.com/goshakkk/heroku-buildpack-elixir) - Elixir buildpack for Heroku 137 | - [heroku-buildpack-erlang](https://github.com/archaelus/heroku-buildpack-erlang) - Erlang/OTP buildpack for Heroku 138 | * [erln8](https://github.com/metadave/erln8) - Erlang/OTP version manager (builds from git source) 139 | * [robisonsantos/evm](https://github.com/robisonsantos/evm) - Erlang Version Manager (from erlang.org tarballs) 140 | 141 | 142 | ### Limitations 143 | 144 | * Does not build erlang 145 | * Does not build Dynamo or any other elixir app 146 | * Same build directory used for every build (saving space vs keeping build env around) 147 | * No uninstall option for installed elixir versions 148 | * No per-directory/project config file. 149 | - You can hack it in by adding kiex use to .rvmrc or friends ;P 150 | 151 | 152 | 153 | ### Notes 154 | 155 | Some erlang builds (including default kerl) are unusuable on current CentOS and Fedora distros as a result of an OpenSSL update. -- 2014/03/31 156 | 157 | Various bugs reported: 158 | * https://bugzilla.redhat.com/show_bug.cgi?id=1023017 159 | * https://groups.google.com/forum/#!topic/erlang-programming/wW6Uuz4VO2w 160 | * https://github.com/basho/rebar/issues/375 161 | * https://bugs.ruby-lang.org/issues/9065 162 | 163 | A update to OTP crypto https://github.com/RoadRunnr/otp/commit/8837c1be2ba8a3c123df3f5a87003daa9aac6539 164 | 165 | ### TODO 166 | 167 | * Merge install script into kiex script as an install function 168 | * Cleanup build output (extra git info etc) 169 | * Maybe print source line with use command 170 | * Add active command (or similar) to show current elixir 171 | - Already in list command - this would be the single version 172 | - Maybe show source line? 173 | * Add sourceline or similar command to show source line to use? 174 | * Maybe add dynamo install and setup for MIX_PATH 175 | - how to tie to elixir used? gemset like? 176 | - use dynamo tags? 177 | * Look at elixir-build for ideas, collaboration 178 | 179 | ### License 180 | 181 | See [LICENSE file](LICENSE) 182 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | \curl -sSL https://raw.githubusercontent.com/taylor/kiex/master/kiex | bash -s install_kiex 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /kiex: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # custom kiex installation directory 4 | if [[ -z "$KIEX_HOME" ]]; then 5 | KIEX_HOME="$HOME/.kiex" 6 | fi 7 | 8 | KIEX_BIN_PATH="$KIEX_HOME/bin/kiex" 9 | KIEX_SCRIPTS_PATH="$KIEX_HOME/scripts" 10 | 11 | base_path="$KIEX_HOME" 12 | build_path="${base_path}/builds" 13 | elixirs_path="${base_path}/elixirs" 14 | elixirs_source_path="${base_path}/elixirs" 15 | mix_archives_path="${base_path}/mix/archives" 16 | mix_archives_source_path="${base_path}/mix/archives" 17 | kiex_url=${kiex_url:="https://raw.githubusercontent.com/taylor/kiex/master/kiex"} 18 | cached_release_list="$KIEX_HOME/.cached_release_list" 19 | cached_branch_list="$KIEX_HOME/.cached_branch_list" 20 | 21 | USER_AGENT="kiex-elixir-installer" 22 | 23 | SYSTEM=$(uname -s) 24 | 25 | AUTH_HEADER=() 26 | if [ -n "$KIEX_OAUTH_TOKEN" ]; then 27 | AUTH_HEADER=(-H "Authorization: token ${KIEX_OAUTH_TOKEN}") 28 | fi 29 | 30 | # Running bash -l from csh does not change $SHELL 31 | if [ -z "$USERSHELL" ] ; then 32 | USERSHELL=$(basename $SHELL) 33 | fi 34 | 35 | if [ "$SYSTEM" = "Linux" ] ; then 36 | if ( command -v lsb_release >/dev/null 2>&1 ; ) ; then 37 | lsb_id=$(lsb_release -s -i) 38 | case $lsb_id in 39 | Ubuntu) DISTRO="Ubuntu" ;; 40 | Centos) DISTRO="Centos" ;; 41 | Gentoo) DISTRO="Gentoo" ;; 42 | Arch) DISTRO="Arch" ;; 43 | Fedora) DISTRO="Fedora" ;; 44 | *) DISTRO="$lsb_id" ;; 45 | esac 46 | elif (( "$(grep -ic arch /etc/os-release)" > 0 )) ; then 47 | DISTRO="Arch" 48 | elif (( "$(grep -ic Fedora /etc/os-release)" > 0 )) ; then 49 | DISTRO="Fedora" 50 | elif (( "$(grep -ic Ubuntu /etc/issue)" > 0 )) ; then 51 | DISTRO="Ubuntu" 52 | elif (( "$(grep -ic Centos /etc/issue)" > 0 )) ; then 53 | DISTRO="Centos" 54 | elif [[ -f /etc/gentoo-release ]] ; then 55 | DISTRO="Gentoo" 56 | else 57 | echo "Unknown Linux distribution" 58 | fi 59 | elif [ "$SYSTEM" = "FreeBSD" ] ; then 60 | DISTRO=FreeBSD 61 | elif [ "$SYSTEM" = "Darwin" ] ; then 62 | #DISTRO=$(uname -r) 63 | DISTRO=OSX 64 | else 65 | echo "Unsupported system $SYSTEM" 66 | exit 1 67 | fi 68 | 69 | INSTALL_KIEX=0 70 | if [ "$1" = "install_kiex" ] ; then 71 | INSTALL_KIEX=1 72 | elif [ "$1" = "install" -a "$2" = "kiex" ] ; then 73 | INSTALL_KIEX=1 74 | fi 75 | 76 | if [ "$INSTALL_KIEX" = 1 ] ; then 77 | if [ -x $KIEX_HOME/bin/kiex ] ; then 78 | exec "$KIEX_HOME/bin/kiex" selfupdate 79 | else 80 | mkdir -p "${KIEX_HOME}/bin" 81 | \curl -sSL ${AUTH_HEADER[*]} -o "$KIEX_HOME/bin/kiex" $kiex_url 82 | chmod +x "$KIEX_HOME/bin/kiex" 83 | 84 | echo "Running initial environment setup" 85 | exec "$KIEX_HOME/bin/kiex" setup 86 | fi 87 | 88 | exit 0 89 | fi 90 | 91 | 92 | ###################################### 93 | ###################################### 94 | 95 | function usage() { 96 | me=$(basename $0) 97 | #echo "$me |use >" 98 | echo "$me commands:" 99 | printf "%b" " list - shows currently installed Elixirs\n" 100 | printf "%b" " list known - shows available Elixir releases\n" 101 | printf "%b" " list branches - shows available Elixir branches\n" 102 | printf "%b" " install - installs the given release version\n" 103 | printf "%b" " uninstall - uninstalls the given release version\n" 104 | printf "%b" " alias - creates an alias for the given version\n" 105 | printf "%b" " unalias - removes an alias\n" 106 | printf "%b" " use [--default] - uses the given version for this shell\n" 107 | printf "%b" " shell - uses the given version for this shell\n" 108 | printf "%b" " default - sets the default version to be used\n" 109 | # printf "%b" " setup - install kiex into \$KIEX_HOME\n" 110 | printf "%b" " selfupdate - updates kiex itself\n" 111 | printf "%b" " implode - removes kiex and all installed Elixirs\n" 112 | printf "%b" " reset - resets default Elixir version to null\n" 113 | } 114 | 115 | 116 | # NOTE: work-around for differences in readlink on BSD and Linux 117 | # Based on the Stack Overflow answer http://stackoverflow.com/a/1116890 118 | function readlink_f() { 119 | TARGET_FILE="$1" 120 | 121 | cd "$(dirname "$TARGET_FILE")" 122 | 123 | TARGET_FILE=`basename "$TARGET_FILE"` 124 | 125 | # Iterate down a (possible) chain of symlinks 126 | while [ -L "$TARGET_FILE" ] ; do 127 | TARGET_FILE=`readlink "$TARGET_FILE"` 128 | cd `dirname "$TARGET_FILE"` 129 | TARGET_FILE=`basename "$TARGET_FILE"` 130 | done 131 | 132 | # Compute the canonicalized name by finding the physical path 133 | # for the directory we're in and appending the target file. 134 | PHYS_DIR=`pwd -P` 135 | RESULT="${PHYS_DIR}/${TARGET_FILE}" 136 | echo $RESULT 137 | } 138 | 139 | function check_erlang_release() { 140 | init_erlang_release_var 141 | 142 | r="${erlang_release[0]}" 143 | c="${erlang_release[1]}" 144 | cn="${erlang_release[2]}" 145 | 146 | #echo "erlang release: ${erlang_release[*]}, r: $r, c: $c, n: $cn" 147 | #elixir_req_str="Elixir requires Erlang ${erlang_min_release_full} or later" 148 | 149 | if [ -z "$r" ] ; then 150 | echo "Failed to extract the erlang release!" 1>&2 151 | false 152 | elif [[ -n "$erlang_max_release" ]] && (( $r > $erlang_max_release )) ; then 153 | false 154 | elif (( $r > $erlang_min_release )) ; then 155 | true 156 | elif (( $r < $erlang_min_release )) ; then 157 | false 158 | elif (( $r == $erlang_min_release )) ; then 159 | if [ -z "$erlang_min_release_canidate" ] ; then 160 | true 161 | elif [ -n "$erlang_min_release_canidate" -a -z "$c" ] ; then 162 | false 163 | elif [ "$erlang_min_release_canidate" == "A" -a "$c" == "B" ] ; then 164 | true 165 | elif [ "$erlang_min_release_canidate" == "$c" ] ; then 166 | if [ -n "$erlang_min_release_canidate_n" ] ; then 167 | if [ -z "$cn" ] ; then 168 | false 169 | elif (( $cn < $erlang_min_release_canidate_n )) ; then 170 | false 171 | else 172 | true 173 | fi 174 | else 175 | true 176 | fi 177 | else 178 | # unknown character after release... 179 | false 180 | fi 181 | fi 182 | } 183 | 184 | function init_erlang_release_var() { 185 | if [ "$SYSTEM" = "Linux" ] ; then 186 | ERL_EXEC_PATH="$(dirname $(readlink -f $(which erl 2> /dev/null)))" 187 | #ERL_EXEC_PATH might show the path to the 'erl' executable in the 188 | #erlang/bin or /erlang/erts-*/bin folder. 189 | if [ -e $ERL_EXEC_PATH/../releases/RELEASES ] ; then 190 | erlang_release_file="$ERL_EXEC_PATH/../releases/RELEASES" 191 | else 192 | erlang_release_file="$ERL_EXEC_PATH/../../releases/RELEASES" 193 | fi 194 | elif [ "$SYSTEM" = "Darwin" -o "$SYSTEM" = "FreeBSD" ] ; then 195 | erlang_release_file="$(dirname "$(readlink_f "$(which erl 2> /dev/null)")")/../releases/RELEASES" 196 | else 197 | echo "Unknown system $SYSTEM" 198 | return 1 199 | fi 200 | 201 | if [ ! -e "$erlang_release_file" ] ; then 202 | echo "Failed to find the erlang release file!" 1>&2 203 | return 1 204 | fi 205 | 206 | erlang_release=($(grep -v '^%' "$erlang_release_file" | awk -F, 'NR==1 {gsub(/"/,"",$3);print $3}' | sed 's/R\([0-9]*\)\([A-Z]\)/\1 \2 /')) 207 | } 208 | 209 | function bin_found() { 210 | if [ -z "$1" ] ; then 211 | false 212 | elif [ -z "$(which $1 2> /dev/null)" ] ; then 213 | echo "ERROR: $1 not found in \$PATH" 1>&2 214 | false 215 | else 216 | true 217 | fi 218 | } 219 | 220 | function exit_on_unmet_prereqs() { 221 | deps_check 222 | if [ ! "$?" = 0 ] 223 | then 224 | exit 1 225 | fi 226 | } 227 | 228 | function erlang_req_info() { 229 | if [ -n "$erlang_max_release" ] ; then 230 | echo "That Elixir requires Erlang ${erlang_min_release_full} or later but before ${erlang_before_release_full}" 231 | else 232 | echo "That Elixir requires Erlang ${erlang_min_release_full} or later" 233 | fi 234 | 235 | echo "Erlang installation choices:" 236 | echo " * Download - https://www.erlang-solutions.com/downloads/download-erlang-otp" 237 | echo " http://www.erlang.org/download.html" 238 | echo " * Kerl - https://github.com/kerl/kerl" 239 | echo " * Package manager -" 240 | echo " Arch: See AUR package," 241 | echo " FreeBSD: pkg install erlang" 242 | echo " OS X: brew install erlang" 243 | echo " Ubuntu/Debian/CentOS see erlang-solutions.com" 244 | } 245 | 246 | function deps_check() { 247 | error=0 248 | errors=0 249 | 250 | bin=erl 251 | ( bin_found $bin && check_erlang_release ) || error=1 252 | [[ $error = 1 ]] && erlang_req_info 253 | errors=$(( $errors + $error )) 254 | 255 | error=0 256 | bin=git 257 | bin_found $bin || error=1 258 | [[ $error = 1 ]] && echo " Install $bin and try again" 259 | errors=$(( $errors + $error )) 260 | 261 | error=0 262 | if [ "$SYSTEM" = "FreeBSD" ] ; then 263 | bin=gmake 264 | bin_found $bin || error=1 265 | [[ $error = 1 ]] && echo " Install $bin and try again" 266 | errors=$(( $errors + $error )) 267 | fi 268 | 269 | if [ ! "$errors" = 0 ] ; then false ; else true ; fi 270 | } 271 | 272 | # TODO: add csh/tcsh support. test zsh support 273 | function create_kiex_env_script() { 274 | ## Backup the current scripts 275 | D=$(date +%Y%m%d.%H%M) 276 | if [ -d ../scripts ] ; then 277 | cp ../scripts/kiex ../scripts/kiex.bak-$D 278 | cp ../scripts/kiex.bash ../scripts/kiex.bash.bak-$D 279 | cp ../scripts/kiex.csh ../scripts/kiex.csh.bak-$D 280 | cp ../scripts/kiex.fish ../scripts/kiex.fish.bak-$D 281 | fi 282 | 283 | ## Generic loader 284 | cat <<"EOF"> "$KIEX_SCRIPTS_PATH/kiex" 285 | ## load correct version for this \$SHELL 286 | ( ( env | grep '^SHELL=' | grep -qic '/csh$' ) && ( set | grep -qc '^BASH=' ; test $? -gt 0 ) ) \ 287 | && source $KIEX_HOME/scripts/kiex.csh \ 288 | || source $KIEX_HOME/scripts/kiex.bash 289 | EOF 290 | 291 | ## Bash and Zsh 292 | cat <<"EOF"> "$KIEX_SCRIPTS_PATH/kiex.bash" 293 | KIEX_HOME="$KIEX_HOME" 294 | export PATH=$KIEX_HOME/bin:$PATH 295 | [[ -f $KIEX_HOME/elixirs/.default ]] && source $KIEX_HOME/elixirs/.default 296 | 297 | function kiex() { 298 | if [ "$1" = "use" ] ; then 299 | #eval "$($KIEX_HOME/bin/kiex $*|grep source)" 300 | source_line="$(USERSHELL=notcsh $KIEX_HOME/bin/kiex $*|grep source)" 301 | if [ -z "$source_line" ] ; then 302 | echo "Failed to $*" 303 | return 1 304 | else 305 | eval "$source_line" 306 | shift 307 | echo "Using $*" 308 | fi 309 | else 310 | $KIEX_HOME/bin/kiex $* 311 | fi 312 | } 313 | EOF 314 | 315 | ## CSH 316 | cat <<"EOF"> "$KIEX_SCRIPTS_PATH/kiex.csh" 317 | set KIEX_HOME="$KIEX_HOME" 318 | setenv PATH "$KIEX_HOME/bin:$PATH" 319 | 320 | if ( -f $KIEX_HOME/elixirs/.default.csh ) then 321 | source $KIEX_HOME/elixirs/.default.csh 322 | endif 323 | EOF 324 | 325 | ## Fish 326 | cat <<"EOF"> "$KIEX_SCRIPTS_PATH/kiex.fish" 327 | set KIEX_HOME $KIEX_HOME 328 | set -gx PATH $KIEX_HOME/bin $PATH 329 | 330 | if test -f $KIEX_HOME/elixirs/.default.fish 331 | source $KIEX_HOME/elixirs/.default.fish 332 | end 333 | EOF 334 | } 335 | 336 | function setup() { 337 | quiet=0 338 | update=0 339 | if [ "$1" = "quiet" ] ; then 340 | quiet=1 341 | shift 342 | fi 343 | if [ "$1" = "update" ] ; then 344 | echo "Updating the kiex installation in $KIEX_HOME" 345 | update=1 346 | fi 347 | 348 | grep -sv '^#' ~/.bashrc | grep -isq kiex 349 | [[ $? = 0 ]] && in_bashrc=$HOME/.bashrc 350 | grep -sv '^#' ~/.profile | grep -isq kiex 351 | [[ $? = 0 ]] && in_profile=$HOME/.profile 352 | grep -sv '^#' ~/.bash_profile | grep -isq kiex 353 | [[ $? = 0 ]] && in_bash_profile=$HOME/.bash_profile 354 | grep -sv '^#' ~/.zshrc | grep -isq kiex 355 | [[ $? = 0 ]] && in_zshrc=$HOME/.zshrc 356 | grep -sv '^#' ~/.zsh_profile | grep -isq kiex 357 | [[ $? = 0 ]] && in_zsh_profile=$HOME/.zsh_profile 358 | 359 | str="" 360 | for s in $in_bashrc $in_profile $in_bash_profile $in_zshrc $in_zsh_profile ; do 361 | [[ -z "$str" ]] && str="$s" || str="${str}, $s" 362 | done 363 | if [ -z "$str" ] ; then 364 | echo " Kiex sourcing line not found in ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.zshrc, or ~/.zsh_profile" 365 | source_line_found=0 366 | else 367 | echo " Kiex sourcing line found in: ${str}" 368 | source_line_found=1 369 | fi 370 | 371 | mkdir -p "$KIEX_HOME/"{bin,builds,elixirs,scripts} 372 | mkdir -p "${KIEX_HOME}/mix/archives" 373 | 374 | create_kiex_env_script 375 | 376 | typeset elixirs 377 | 378 | elixirs=($( 379 | cd "$elixirs_path" 380 | find . -maxdepth 1 -mindepth 1 -type d 2> /dev/null | sort 381 | )) 382 | 383 | for version in "${elixirs[@]//.\/}" 384 | do 385 | if [[ ! -x "$elixirs_path/$version/bin/elixir" ]] 386 | then 387 | continue 388 | fi 389 | mkdir -p "${mix_archives_path}/${version}" 390 | create_env_file "${version/elixir-/}" 391 | done 392 | 393 | if [ $source_line_found = 0 ] ; then 394 | echo " Add the following to your shell's config file (.bashrc/.zshrc/.cshrc):" 395 | echo " test -s \"\$KIEX_HOME/scripts/kiex\" && source \"\$KIEX_HOME/scripts/kiex\"" 396 | fi 397 | 398 | if [ "$update" = 1 ] ; then 399 | echo "kiex installed in $KIEX_HOME is now updated ☺ " 400 | else 401 | echo "kiex has been installed in $KIEX_HOME ☺ " 402 | fi 403 | } 404 | 405 | function self_update_reloaded() { 406 | cd "$KIEX_HOME/bin" 407 | setup quiet update 408 | } 409 | 410 | function self_update() { 411 | # if [ "$SYSTEM" = "Linux" ] ; then 412 | # mypath=$(dirname $(readlink -f $0)) 413 | # elif [ "$SYSTEM" = "Darwin" ] ; then 414 | # mypath=$(dirname $(readlink_f $0)) 415 | # else 416 | # echo "Unknown system $SYSTEM" 417 | # return 1 418 | # fi 419 | 420 | # cd $mypath 421 | 422 | cd "$KIEX_HOME/bin" 423 | 424 | D=$(date +%Y%m%d.%H%M) 425 | cp kiex kiex.bak-$D 426 | 427 | mkdir -p "$KIEX_HOME/bin" 428 | \curl -L ${AUTH_HEADER[*]} -H "User-Agent: $USER_AGENT" -sSL -o "$KIEX_HOME/bin/kiex" "$kiex_url" 429 | chmod +x "$KIEX_HOME/bin/kiex" 430 | #exec $KIEX_HOME/bin/kiex setup update 431 | exec $KIEX_HOME/bin/kiex selfupdatereloaded 432 | 433 | #setup quiet 434 | 435 | #curl -qs -o kiex "$kiex_url" 436 | #chmod +x kiex 437 | #echo "kiex installed in $mypath is now updated" 438 | #echo "kiex installed in $KIEX_HOME is now updated ☺ " 439 | } 440 | 441 | function kiex_implode() { 442 | echo -n "Type YES to remove the kiex install and all elixirs: " 443 | read resp 444 | if [ ! "$resp" = "YES" ] ; then 445 | echo "Aborting!" 446 | exit 0 447 | fi 448 | 449 | if [ -d "$KIEX_HOME" ] ; then 450 | rm -rf "$KIEX_HOME" 451 | fi 452 | 453 | echo "You can now remove the kiex source lines from your startup script. It looks like:" 454 | echo " test -s \"\$KIEX_HOME/scripts/kiex\" && source \"\$KIEX_HOME/scripts/kiex\"" 455 | echo " or" 456 | echo " [[ -s \"\$KIEX_HOME/scripts/kiex\" ]] && source \"\$KIEX_HOME/scripts/kiex\"" 457 | } 458 | 459 | 460 | function get_elixir_branches() { 461 | # TODO: add cache support 462 | # x=$(curl -i -H "User-Agent: $USER_AGENT" -H "Accept: application/json" -qs https://api.github.com/repos/elixir-lang/elixir/branches |grep '"name":|ETag:') 463 | x=$(\curl -i ${AUTH_HEADER[*]} -H "User-Agent: $USER_AGENT" -H "Accept: application/json" -qs https://api.github.com/repos/elixir-lang/elixir/branches |grep '"name":') 464 | x=$(echo $x | tr ',' '\n' |grep name\":|sed 's/.*name":"\([^"]*\)"/\1/') 465 | #x=${x//\"name\":/} 466 | #x=${x//[\",]/} 467 | #x=${x//v/} 468 | 469 | echo "$x" | sed 's/^/ /' 470 | } 471 | 472 | function list_branches() { 473 | echo "Getting the available branches from https://github.com/elixir-lang/elixir/branches" 474 | echo 475 | elixir_branches=$(get_elixir_branches) 476 | 477 | echo "Current Elixir branches: " 478 | printf "%b" "${elixir_branches}\n" 479 | } 480 | 481 | # function get_cached_elixir_releases() { 482 | # tail -n +2 $cached_release_list 483 | # } 484 | # 485 | # function get_cached_releases_etag() { 486 | # xetag=$(grep "^#Etag:" $cached_release_list) 487 | # echo ${xetag//#Etag:} 488 | # } 489 | # 490 | # function update_release_cache() { 491 | # x="$*" 492 | # xetag=$(echo $x|grep ETag) 493 | # xetag=${xetag//ETag: /} 494 | # xetag=${xetag//"/} 495 | # new_etag=${xetag//ETag: /} 496 | # cached_etag=$(get_cached_releases_etag) 497 | # echo "$x" 498 | # } 499 | 500 | function get_known_elixir_releases() { 501 | # TODO: finish adding caching support with etags 502 | # xetag=$(curl -i -H "User-Agent: $USER_AGENT" -qs https://api.github.com/repos/elixir-lang/elixir/releases |grep "^ETag") 503 | # etag=${xetag//Etag: "/} 504 | # 505 | # x=$(curl -i -H "User-Agent: $USER_AGENT" -H "Accept: application/json" -qs https://api.github.com/repos/elixir-lang/elixir/releases |grep '"tag_name":|ETag') 506 | # xetag=$(echo $x|grep ETag) 507 | # x=$(echo $x|grep -v ETag) 508 | 509 | x=$(\curl -i ${AUTH_HEADER[*]} -H "User-Agent: $USER_AGENT" -H 'Accept: application/json' -qs "https://api.github.com/repos/elixir-lang/elixir/releases?per_page=100" | tr ',' '\n' | grep '"tag_name":') 510 | x=${x//\"tag_name\":/} 511 | x=${x//[\",]/} 512 | x=${x//v/} 513 | 514 | # update_release_cache "$x" 515 | echo "$x" | sed 's/^/ /' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n 516 | } 517 | 518 | function get_latest_elixir_release() { 519 | x=$(curl -i ${AUTH_HEADER[*]} -H "User-Agent: $USER_AGENT" -H 'Accept: application/json' -qs https://api.github.com/repos/elixir-lang/elixir/releases/latest | tr ',' '\n' | grep '"tag_name":' | sed -E 's/"tag_name":"v(.+)"$/\1/') 520 | 521 | echo "$x" 522 | } 523 | 524 | function list_known() { 525 | echo "Getting the available releases from https://github.com/elixir-lang/elixir/releases" 526 | echo 527 | elixir_releases=$(get_known_elixir_releases) 528 | #elixir_releases=$x 529 | 530 | echo "Known Elixir releases: " 531 | printf "%b" "${elixir_releases}\n" 532 | } 533 | 534 | function get_latest() { 535 | echo "Getting the latest release from https://github.com/elixir-lang/elixir/releases/latest" 536 | # add empty line 537 | echo 538 | local latest_release=$(get_latest_elixir_release) 539 | echo "Latest release is ${latest_release}" 540 | # add empty line 541 | echo 542 | read -p "Do you want to install it? [y/n]" -n 1 -r 543 | 544 | if [[ $REPLY =~ ^[Yy]$ ]] 545 | then 546 | install_elixir $latest_release 547 | fi 548 | } 549 | 550 | function valid_known_release() { 551 | ver="$1" 552 | get_known_elixir_releases | grep -q "$1$" 2> /dev/null 553 | echo $? 554 | } 555 | 556 | function valid_branch() { 557 | ver="$1" 558 | get_elixir_branches | grep -q "$1" 2> /dev/null 559 | echo $? 560 | } 561 | 562 | function exit_on_invalid_version() { 563 | version="$1" 564 | 565 | if [ ! "$(valid_known_release ${version})" = 0 -a ! "$(valid_branch ${version})" = 0 ] ; then 566 | echo "Unknown Elixir '$version' ☹ " 567 | echo -e "Try\n\tkiex list known -- known releases\n\tkiex list branches -- current branches" 568 | exit 1 569 | fi 570 | } 571 | 572 | function install_elixir() { 573 | ver="$1" 574 | ver=${ver//v/} 575 | major=${ver%%.[0-9]*} 576 | mp=${ver#[0-9]*.} 577 | minor=${mp%.*[0-9]} 578 | patch=${ver##*[0-9].} 579 | if (( $major >= 1 )) || (( $minor > 12 )) || (( $ver == "master" )); then 580 | need_erl_17=1 581 | fi 582 | 583 | if [ "$need_erl_17" = 1 ] ; then 584 | erlang_min_release_full="R17" 585 | erlang_min_release=17 586 | erlang_min_release_canidate="" 587 | erlang_min_release_canidate_n="" 588 | else 589 | erlang_min_release_full="R16B" 590 | erlang_min_release=16 591 | erlang_before_release_full=R17 592 | erlang_max_release=16 593 | erlang_min_release_canidate="B" 594 | erlang_min_release_canidate_n="" 595 | fi 596 | 597 | version="$1" 598 | 599 | exit_on_invalid_version "$1" 600 | exit_on_unmet_prereqs 601 | init_erlang_release_var 602 | 603 | suffix="${version}-${erlang_release}" 604 | 605 | install_path="${elixirs_path}/elixir-${suffix}" 606 | 607 | cd "$build_path" 608 | echo "Downloading elixir version ${version}" 609 | git clone https://github.com/elixir-lang/elixir.git elixir-git 2> /dev/null 610 | cd elixir-git 611 | echo "Installing elixir version ${version} into ${install_path}" 612 | git checkout -f master 613 | git fetch -t 614 | # TODO: deal with conflicts between branches and tags 615 | git branch -la |grep -q "origin/${version}" 616 | if [ "$?" = 0 ] ; then 617 | git checkout -b "${version}" -f "origin/${version}" || git checkout "${version}" 618 | git pull origin "${version}" 619 | else 620 | git checkout -b "v${version}" -f "v${version}" || git checkout "v${version}" 621 | git pull origin "v${version}" 622 | fi 623 | 624 | if [ "$SYSTEM" = "FreeBSD" ] ; then 625 | MAKE=gmake 626 | else 627 | MAKE=make 628 | fi 629 | $MAKE clean compile 630 | mkdir -p "$install_path" 631 | # elixir make install does not work under *csh 632 | $MAKE "PREFIX=$install_path" install 633 | 634 | if [ ! "$?" = 0 ] ; then 635 | echo "Problem with Elixir build. Aborting!" 636 | echo "Please report via https://github.com/taylor/kiex/issues/new" 637 | echo " Include the operating system, erlang version, and shell being used" 638 | exit 1 639 | fi 640 | 641 | # For MIX_ARCHIVES - http://elixir-lang.org/docs/master/mix/Mix.Tasks.Archive.html 642 | mkdir -p "${mix_archives_path}/elixir-${suffix}" 643 | 644 | echo "Installed Elixir version $version" 645 | create_env_file "$suffix" 646 | 647 | echo "Load with:" 648 | echo " kiex use ${suffix} " 649 | echo "or load the elixir environment file with: " 650 | printf "%b" " " 651 | 652 | case $(basename $SHELL) in 653 | fish) 654 | printf "%b" "source ${elixirs_source_path}/.elixir-${suffix}.env.fish\n" 655 | ;; 656 | csh|tcsh) 657 | printf "%b" "source ${elixirs_source_path}/.elixir-${suffix}.env.csh\n" 658 | ;; 659 | *) 660 | printf "%b" "source ${elixirs_source_path}/elixir-${suffix}.env\n" 661 | ;; 662 | esac 663 | } 664 | 665 | function uninstall_elixir() { 666 | typeset version delete_version current_elixir default_elixir iexpath x1 667 | typeset alias_file alias_name target_file target_name target_alias_list a 668 | 669 | version="$1" 670 | delete_version=$(find_elixir_ver "$version") 671 | 672 | if [[ -z "$delete_version" ]]; then 673 | echo "Elixir version '$version' not found." 674 | exit 1 675 | fi 676 | 677 | if [[ -e "$elixirs_path"/.default ]]; then 678 | default_elixir="elixir-$(source $elixirs_path/.default ; echo $ELIXIR_VERSION)" 679 | fi 680 | 681 | iexpath=$(which iex 2> /dev/null) 682 | if [[ -n "${iexpath}" ]]; then 683 | x1=${iexpath/$elixirs_path\/} 684 | current_elixir=${x1/\/bin\/iex} 685 | fi 686 | 687 | if [[ "$delete_version" == "$current_elixir" ]]; then 688 | echo "'$version' is the current version of Elixir." 689 | echo "Please set kiex to use another version of Elixir and try again." 690 | exit 1 691 | fi 692 | 693 | if [[ "$delete_version" == "$default_elixir" ]]; then 694 | reset_elixir > /dev/null 695 | fi 696 | 697 | # remove aliases 698 | pushd "$elixirs_path" > /dev/null 699 | target_alias_list="" 700 | for alias_file in $(find . -maxdepth 1 -mindepth 1 -type l -name ".elixir-*") 701 | do 702 | alias_name="${alias_file//.\/.elixir-}" 703 | target_file="$(readlink $alias_file)" 704 | target_name="$(basename $target_file .env)" 705 | 706 | target_alias_list_name="ealiases__${target_name//[^[:alnum:]]/}" 707 | target_alias_list=${!target_alias_list_name} 708 | if [[ -z "$target_alias_list" ]]; then 709 | target_alias_list="$alias_name" 710 | else 711 | target_alias_list="$target_alias_list $alias_name" 712 | fi 713 | printf -v "ealiases__${target_name//[^[:alnum:]]/}" %s "$target_alias_list" 714 | done 715 | popd > /dev/null 716 | 717 | target_alias_list_name="ealiases__${delete_version//[^[:alnum:]]/}" 718 | target_alias_list=${!target_alias_list_name} 719 | for a in $target_alias_list; do 720 | remove_alias "$a" 721 | done 722 | 723 | # remove the actual files 724 | rm -f "$KIEX_HOME/elixirs/.$delete_version.env."*sh* 725 | rm -Rf "$KIEX_HOME/elixirs/$delete_version" 726 | rm -f "$KIEX_HOME/elixirs/$delete_version.env"* 727 | rm -Rf "$KIEX_HOME/mix/archives/$delete_version" 728 | } 729 | 730 | function create_env_file() { 731 | new_ver="$1" 732 | new_file="${elixirs_path}/elixir-${new_ver}.env" 733 | new_path="${elixirs_path}/elixir-${new_ver}/bin" 734 | new_mix_path="${elixirs_path}/elixir-${new_ver}/ebin" 735 | 736 | if [ -f "$new_file" ] ; then 737 | mv -f "$new_file" "${new_file}.old" 738 | fi 739 | ## Bash and Zsh 740 | cat < $new_file 741 | export ELIXIR_VERSION="$new_ver" 742 | export PATH="${elixirs_source_path}/elixir-${new_ver}/bin:\$PATH" 743 | export MIX_ARCHIVES="${mix_archives_source_path}/elixir-${new_ver}" 744 | EOF 745 | 746 | # TODO: add MIX_PATH maybe? 747 | #export MIX_PATH="${elixirs_source_path}/dynamo-${new_ver}/ebin:\$MIX_PATH" 748 | #export MIX_PATH="${elixirs_source_path}/elixir-${new_ver}/ebin:\$MIX_PATH" 749 | 750 | ## CSH 751 | new_file="${elixirs_path}/.elixir-${new_ver}.env.csh" 752 | if [ -f "$new_file" ] ; then 753 | mv -f "$new_file" "${new_file}.old" 754 | fi 755 | cat < $new_file 756 | setenv ELIXIR_VERSION "$new_ver" 757 | setenv PATH "${elixirs_source_path}/elixir-${new_ver}/bin:\$PATH" 758 | setenv MIX_ARCHIVES "${mix_archives_source_path}/elixir-${new_ver}" 759 | EOF 760 | 761 | ## Fish 762 | new_file="${elixirs_path}/.elixir-${new_ver}.env.fish" 763 | if [ -f "$new_file" ] ; then 764 | mv -f "$new_file" "${new_file}.old" 765 | fi 766 | cat < $new_file 767 | set -gx ELIXIR_VERSION $new_ver 768 | set -gx PATH ${elixirs_source_path}/elixir-${new_ver}/bin \$PATH 769 | set -gx MIX_ARCHIVES ${mix_archives_source_path}/elixir-${new_ver} 770 | EOF 771 | } 772 | 773 | function find_elixir_ver() { 774 | target_elixir="$1" 775 | # default to not found (1) 776 | found="" 777 | 778 | elixirs=($( 779 | cd "$elixirs_path" 780 | find . -maxdepth 1 -mindepth 1 -type d 2> /dev/null | sort 781 | )) 782 | 783 | #TODO: reset version to nothing if problems arise 784 | for version in "${elixirs[@]//.\/}" 785 | do 786 | if [[ ! -x "$elixirs_path/$version/bin/elixir" ]] 787 | then 788 | continue 789 | elif [[ ! -f "$elixirs_path/${version}.env" ]] 790 | then 791 | continue 792 | elif [ ! "$version" = "$target_elixir" -a ! "${version}" = "elixir-${target_elixir}" ] 793 | then 794 | continue 795 | else 796 | found=yes 797 | break 798 | fi 799 | done 800 | if [ -n "$found" ] ; then 801 | echo $version 802 | else 803 | echo "" 804 | fi 805 | } 806 | 807 | function use_elixir() { 808 | target_elixir="$1" 809 | version=$(find_elixir_ver "$target_elixir") 810 | 811 | [[ -z $version ]] && version=$(get_version_from_alias "$target_elixir"); 812 | 813 | if [ -z "$version" ] ; then 814 | echo "Elixir version $target_elixir not found. Try kiex install $target_elixir" 815 | exit 1 816 | fi 817 | 818 | echo "To switch elixir versions for your current shell run: " 819 | printf "%b" " " 820 | if [ "$USERSHELL" = "fish" ] ; then 821 | printf "%b" "source ${elixirs_source_path}/.${version}.env.fish\n" 822 | elif [ "$USERSHELL" = "csh" ] ; then 823 | printf "%b" "source ${elixirs_source_path}/.${version}.env.csh\n" 824 | else 825 | printf "%b" "source ${elixirs_source_path}/${version}.env\n" 826 | fi 827 | } 828 | 829 | function get_version_from_alias() { 830 | local alias="$1" 831 | local version_installed="" 832 | local symlink_path="${elixirs_path}/.elixir-$alias" 833 | 834 | if [[ -L $symlink_path ]]; then 835 | local origin_path=$(readlink "$symlink_path") 836 | local origin_version=$(basename "$origin_path" | grep -oh "[0-9]*\.[0-9]*\.[0-9]*") 837 | local version_installed=$(find_elixir_ver "$origin_version") 838 | fi 839 | 840 | echo "$version_installed" 841 | } 842 | 843 | function create_alias() { 844 | local source_version="$1" 845 | local alias_name="$2" 846 | local version_installed=$(find_elixir_ver "$source_version") 847 | 848 | if [[ ! -z $version_installed ]]; then 849 | ln -fs ${elixirs_path}/$version_installed.env ${elixirs_path}/.elixir-$alias_name 850 | else 851 | echo "Elixir $source_version is not installed" 852 | fi 853 | } 854 | 855 | function remove_alias() { 856 | local alias_name="$1" 857 | local symlink_path="${elixirs_path}/.elixir-$alias_name" 858 | 859 | if [[ -L "$symlink_path" ]]; then 860 | rm -f "$symlink_path" 861 | else 862 | echo "Alias '$alias_name' does not exist." 863 | fi 864 | } 865 | 866 | function elixir_subshell() { 867 | target_elixir="$1" 868 | version=$(find_elixir_ver "$target_elixir") 869 | 870 | if [ -z "$version" ] ; then 871 | echo "Elixir version $target_elixir not found. Try installing it" 872 | exit 1 873 | fi 874 | 875 | echo "Starting sub-shell with elixir version $version" 876 | source "${elixirs_path}/${version}.env" 877 | # NOTE: Using a login shell will use a default kiex elixir... 878 | exec $SHELL 879 | } 880 | 881 | function set_default_elixir() { 882 | target_elixir="$1" 883 | version=$(find_elixir_ver "$target_elixir") 884 | 885 | if [ -z "$version" ] ; then 886 | echo "Elixir version $target_elixir not found. Try installing it" 887 | exit 1 888 | fi 889 | 890 | if [ -e ${elixirs_path}/.default ] ; then 891 | if [ -L ${elixirs_path}/.default ] ; then 892 | rm ${elixirs_path}/.default 893 | rm ${elixirs_path}/.default.csh 894 | rm ${elixirs_path}/.default.fish 895 | else 896 | echo "The file ${elixirs_path}/.default should not exists! Fix and try again." 897 | exit 1 898 | fi 899 | fi 900 | ln -s "${elixirs_path}/${version}.env" "${elixirs_path}/.default" 901 | ln -s "${elixirs_path}/.${version}.env.csh" "${elixirs_path}/.default.csh" 902 | ln -s "${elixirs_path}/.${version}.env.fish" "${elixirs_path}/.default.fish" 903 | echo "Default Elixir version set to $version" 904 | #echo "Load right now with: kiex use $version" 905 | } 906 | 907 | function reset_elixir() { 908 | if [ -e ${elixirs_path}/.default ] ; then 909 | if [ -L ${elixirs_path}/.default ] ; then 910 | rm ${elixirs_path}/.default 911 | rm ${elixirs_path}/.default.csh 912 | rm ${elixirs_path}/.default.fish 913 | else 914 | echo "The file ${elixirs_path}/.default should not exists! Fix and try again." 915 | exit 1 916 | fi 917 | fi 918 | echo "Reset default Elixir version." 919 | } 920 | 921 | function list_elixirs() { 922 | typeset current_elixir elixirs version selected system_elixir system_version \ 923 | default_elixir string binary 924 | typeset alias_file alias_name target_file target_name target_alias_list 925 | 926 | if [ -e "$elixirs_path"/.default ] ; then 927 | default_elixir="elixir-$(source $elixirs_path/.default ; echo $ELIXIR_VERSION)" 928 | fi 929 | 930 | iexpath=$(which iex 2> /dev/null) 931 | if [ -n "${iexpath}" ] ; then 932 | #v=$(iex --version 2> /dev/null|grep -v 'Warning: could not run') 933 | x1=${iexpath/$elixirs_path\/} 934 | current_elixir=${x1/\/bin\/iex} 935 | #current_elixir="elixir-${v/Elixir /}" 936 | fi 937 | 938 | elixirs=($( 939 | cd "$elixirs_path" 940 | find . -maxdepth 1 -mindepth 1 -type d 2> /dev/null | sort 941 | #find . -maxdepth 1 -mindepth 1 -type d | sed -e 's#./##g' 942 | )) 943 | 944 | pushd "$elixirs_path" > /dev/null 945 | target_alias_list="" 946 | for alias_file in $(find . -maxdepth 1 -mindepth 1 -type l -name ".elixir-*") 947 | do 948 | alias_name="${alias_file//.\/.elixir-}" 949 | target_file="$(readlink $alias_file)" 950 | target_name="$(basename $target_file .env)" 951 | 952 | target_alias_list_name="ealiases__${target_name//[^[:alnum:]]/}" 953 | target_alias_list=${!target_alias_list_name} 954 | if [[ -z "$target_alias_list" ]]; then 955 | target_alias_list="$alias_name" 956 | else 957 | target_alias_list="$target_alias_list $alias_name" 958 | fi 959 | printf -v "ealiases__${target_name//[^[:alnum:]]/}" %s "$target_alias_list" 960 | done 961 | popd > /dev/null 962 | 963 | #for version in "${elixirs//.\/}" 964 | for version in "${elixirs[@]//.\/}" 965 | do 966 | if [[ ! -x "$elixirs_path/$version/bin/elixir" ]] 967 | then 968 | continue 969 | fi 970 | 971 | if [[ "$version" = "$current_elixir" && "$version" = "$default_elixir" ]] 972 | then 973 | printf "%b" "=* " 974 | elif [[ "$version" = "$current_elixir" ]] 975 | then 976 | printf "%b" "=> " 977 | elif [[ "$version" = "$default_elixir" ]] 978 | then 979 | printf "%b" " * " 980 | else 981 | printf "%b" " " 982 | fi 983 | 984 | printf "%b" "$version" 985 | target_alias_list_name="ealiases__${version//[^[:alnum:]]/}" 986 | target_alias_list=${!target_alias_list_name} 987 | [[ -n "$target_alias_list" ]] && printf " [%b]" "$target_alias_list" 988 | printf "%b" "\n" 989 | done 990 | 991 | if (( ${#elixirs[@]} == 0 )) 992 | then 993 | printf "%b" " 994 | # No kiex elixirs installed yet. Try 'kiex install '. 995 | " 996 | else 997 | if [[ -z "${default_elixir}" ]] 998 | then 999 | printf "%b" " 1000 | # Default elixir not set. Try 'kiex default '. 1001 | " 1002 | fi 1003 | printf "%b" " 1004 | # => - current 1005 | # =* - current && default 1006 | # * - default 1007 | " 1008 | fi 1009 | 1010 | printf "%b" "\n" 1011 | } 1012 | 1013 | function validate_install() { 1014 | if [ ! -d "${base_path}/builds" \ 1015 | -o ! -d "${base_path}/elixirs" \ 1016 | -o ! -d "${base_path}/scripts" \ 1017 | -o ! -d "${base_path}/bin" \ 1018 | ] ; then 1019 | 1020 | echo "Please run $me setup" 1021 | exit 1 1022 | #setup 1023 | fi 1024 | } 1025 | 1026 | ################################# 1027 | ################################# 1028 | 1029 | action="$1" 1030 | if [ ${#} -gt 0 ] ; then 1031 | shift 1032 | fi 1033 | 1034 | if [ -z "$action" ] ; then 1035 | usage 1036 | exit 0 1037 | fi 1038 | 1039 | 1040 | 1041 | if [ ! "$action" = "setup" ] ; then 1042 | validate_install 1043 | elif [ ! "$action" = "install" -a "$1" = "kiex" ] ; then 1044 | validate_install 1045 | fi 1046 | 1047 | case $action in 1048 | list) 1049 | if [ -z "$1" ] 1050 | then 1051 | printf "%b" "\nkiex elixirs\n\n" 1052 | list_elixirs 1053 | elif [ "$1" = "known" -o "$1" = "releases" ] 1054 | then 1055 | list_known 1056 | elif [ "$1" = "branches" ] 1057 | then 1058 | list_branches 1059 | else 1060 | usage 1061 | exit 1 1062 | fi 1063 | ;; 1064 | install) 1065 | [[ -z "$1" ]] && usage && exit 1 1066 | if [ "$1" = "kiex" ] ; then 1067 | setup 1068 | echo "kiex has been installed in $KIEX_HOME" 1069 | echo "Add the following to your shell's config file (.bash_profile/.profile):" 1070 | echo " [[ -s \"\$KIEX_HOME/scripts/kiex\" ]] && source \"\$KIEX_HOME/scripts/kiex\"" 1071 | exit 1072 | fi 1073 | if [ "$1" = "latest" ] ; then 1074 | get_latest 1075 | exit 1076 | fi 1077 | install_elixir "$1" 1078 | ;; 1079 | uninstall) 1080 | [[ -z "$1" ]] && usage && exit 1 1081 | uninstall_elixir "$1" 1082 | ;; 1083 | use) 1084 | [[ -z "$1" ]] && usage && exit 1 1085 | if [ "$2" = "--default" -o "$2" = "-default" ] ; then 1086 | set_default_elixir "$1" 1087 | fi 1088 | use_elixir "$1" 1089 | ;; 1090 | default) 1091 | [[ -z "$1" ]] && usage && exit 1 1092 | set_default_elixir "$1" 1093 | ;; 1094 | reset) 1095 | reset_elixir 1096 | ;; 1097 | shell) 1098 | [[ -z "$1" ]] && usage && exit 1 1099 | elixir_subshell "$1" 1100 | ;; 1101 | envfile) 1102 | [[ -z "$1" ]] && exit 1 1103 | create_env_file "$1" 1104 | ;; 1105 | selfupdate|update_self) 1106 | self_update 1107 | exit 0 1108 | ;; 1109 | selfupdatereloaded) 1110 | self_update_reloaded 1111 | exit 0 1112 | ;; 1113 | implode) 1114 | kiex_implode 1115 | exit 0 1116 | ;; 1117 | depscheck|checkdeps) 1118 | deps_check 1119 | [[ $? = 0 ]] && echo "Dependencies met" || ( echo "Dependencies not met" && exit_on_unmet_prereqs ) 1120 | ;; 1121 | setup|reinstall) 1122 | setup 1123 | exit 1124 | ;; 1125 | alias) 1126 | [[ -z "$1" ]] || [[ -z "$2" ]] && usage && exit 1 1127 | create_alias "$1" "$2" 1128 | exit 1129 | ;; 1130 | unalias) 1131 | [[ -z "$1" ]] && usage && exit 1 1132 | remove_alias "$1" 1133 | exit 1134 | ;; 1135 | *) 1136 | usage 1137 | exit 1138 | ;; 1139 | esac 1140 | --------------------------------------------------------------------------------