Skip to content

New installer #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
44 changes: 33 additions & 11 deletions installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
######################################################

set -o errexit
# set -o xtrace
set -o xtrace
################################################
# CONSTANTS
################################################

REPO="arturo"
VERSION="full"

for cmd in $@; do
for cmd in "$@"; do
case $cmd in
--nightly|-n) REPO="nightly";;
--mini|-m) VERSION="mini";;
Expand All @@ -30,17 +30,18 @@ API_URL="https://api.github.com/repos/arturo-lang/${REPO}/releases"
# HELPERS
################################################

# shellcheck disable=SC2034
RED='\e[0;31m'
GREEN='\e[1;32m'
# shellcheck disable=SC2034
BLUE='\e[0;34m'
MAGENTA='\e[1;35m'
CYAN='\e[1;36m'
GRAY='\e[0;90m'
CLEAR='\e[0m'

printColorized() {
NC='\e[0m'
printf "${1}${2}${NC}"
printf "${1}${2}${CLEAR}"
}

panic() {
Expand Down Expand Up @@ -126,7 +127,7 @@ cleanup_tmp_directory() {
}

command_exists(){
type "$1" &> /dev/null
type "$1" > /dev/null 2>&1
}

animate_progress(){
Expand All @@ -152,18 +153,18 @@ verifyOS(){
case "$OSTYPE" in
linux*) currentOS="linux" ;;
darwin*) currentOS="macos" ;;
cygwin*) currentOS="windows-msys2" ;;
msys*) currentOS="windows-msys2" ;;
cygwin*) currentOS="windows" ;;
msys*) currentOS="windows" ;;
solaris*) currentOS="solaris" ;;
freebsd*) currentOS="freebsd" ;;
bsd*) currentOS="bsd" ;;
*)
if [ `uname` = "Linux" ]; then
if [ "$(uname)" = "Linux" ]; then
currentOS="linux"
elif [ `uname` = "FreeBSD" ]; then
elif [ "$(uname)" = "FreeBSD" ]; then
currentOS="freebsd"
else
currentOS="Unknown ($OSTYPE / `uname`)"
currentOS="Unknown ($OSTYPE / $(uname))"
fi ;;
esac

Expand All @@ -174,15 +175,19 @@ verifyShell(){
case "$SHELL" in
*/bin/zsh)
currentShell="zsh" ;
# shellcheck disable=SC2088
shellRcFile="~/.zshrc" ;;
*/bin/bash)
currentShell="bash" ;
# shellcheck disable=SC2088
shellRcFile="~/.bashrc or ~/.profile" ;;
*/bin/sh)
currentShell="sh" ;
# shellcheck disable=SC2088
shellRcFile="~/.profile" ;;
*)
currentShell="unrecognized" ;
# shellcheck disable=SC2088
shellRcFile="~/.profile" ;;
esac

Expand Down Expand Up @@ -223,7 +228,9 @@ download_arturo() {
--output "$ARTURO_TMP_DIR/arturo.tar.gz" \
--silent \
--show-error
}

unpack_tar() {
# This piece of code is using traditional option style due
# to compatibility issues between `tar`'s versions.
# Long versions are accepted for `GNU's tar`, and for others ones
Expand All @@ -237,6 +244,13 @@ download_arturo() {
tar -zxf "$ARTURO_TMP_DIR/arturo.tar.gz" -C $ARTURO_TMP_DIR
}

unpack_zip() {
# It seems that `unzip` doesn't provide a long version of its options.
#
# -d: directory to which to extract files.
unzip "$ARTURO_TMP_DIR/arturo.zip" -d "$ARTURO_TMP_DIR"
}

install_arturo() {
create_directory $HOME/.arturo/bin
create_directory $HOME/.arturo/lib
Expand All @@ -259,14 +273,20 @@ main() {
verifyOS
verifyShell

if [ "$currentOS" = "linux" ] || [ "$currentOS" = "macos" ] || [ "$currentOS" = "windows-msys2" ]; then
if [ "$currentOS" = "linux" ] || [ "$currentOS" = "macos" ]; then
section "Checking prerequisites..."
install_prerequisites

section "Downloading..."
download_arturo

section "Installing..."
if [ "$currentOS" = "linux" ]; then
unpack_tar
else
unpack_zip
fi

install_arturo

section "Cleaning up..."
Expand All @@ -277,6 +297,8 @@ main() {
section "Done!"
eecho ""
showFooter
elif [ "$currentOS" = "windows" ]; then
panic "Cannot continue. Try to install via install.ps1";
else
panic "Cannot continue. Unfortunately your OS is not supported by this auto-installer.";
fi
Expand Down