diff --git a/setup/install.ab b/setup/install.ab index c6dd0bf2..4740631f 100644 --- a/setup/install.ab +++ b/setup/install.ab @@ -1,18 +1,28 @@ -import { hasFailed } from "std" +import { hasFailed, includes, exit } from "std" let name = "AmberNative" let target = "amber" let tag = "0.3.1-alpha" let place = "/opt/amber" -unsafe { +main { // Determine OS type - let os = $uname -s$ == "Darwin" + let os_type = $uname -s$ failed { + echo "Failed to determine OS type." + echo "Please try again or use another download method." + exit(1) + } + let os = os_type == "Darwin" then "macos" else "linux" // Determine architecture - let arch = $uname -m$ == "arm64" + let arch_type = $uname -m$ failed { + echo "Failed to determine architecture." + echo "Please try again or use another download method." + exit(1) + } + let arch = includes(["arm64", "aarch64"], arch_type) then "aarch64" else "x86_64" @@ -20,14 +30,14 @@ unsafe { let url = "https://github.com/Ph0enixKM/{name}/releases/download/{tag}/amber_{os}_{arch}" // Check if such directory exists - $test -d "{place}"$ + unsafe $test -d "{place}"$ if status == 0 { echo "Amber already installed" echo "It seems that Amber is already installed on your system. ({place})" echo "If you want to reinstall Amber, uninstall it first." echo "(Find out more at https://amber.marbl.cc)" - $exit 0$ + exit(2) } echo "Installing Amber" @@ -38,33 +48,57 @@ unsafe { echo "Using ruby as a download method..." $sudo ruby -e "{code}"$ failed { echo "Ruby failed to download amber." - echo "Please try again or use another download method." - $exit 1$ + echo "Something went wrong. Please try again later." + exit(1) } } not hasFailed("curl -v") { echo "Using curl as a download method..." - $curl -o "{target}" "{url}"$ + $curl -o "{target}" "{url}"$ failed { + echo "Curl failed to download amber." + echo "Something went wrong. Please try again later." + exit(1) + } } not hasFailed("wget -V") { echo "Using wget as a download method..." - $wget -O "{target}" "{url}"$ + $wget -O "{target}" "{url}"$ failed { + echo "Wget failed to download amber." + echo "Something went wrong. Please try again later." + exit(1) + } } else { echo "Neither ruby, curl or wget are installed on your system." echo "Please install one of them and try again." - $exit 1$ + exit(1) } } // Create directory for amber - $sudo mkdir "{place}" > /dev/null$ + $sudo mkdir "{place}" > /dev/null$ failed { + echo "Failed to create directory for amber." + echo "Please make sure that root user can access /opt directory." + exit(1) + } // Move zipped version of amber - $sudo mv "{target}" "{place}/{target}"$ + $sudo mv "{target}" "{place}/{target}"$ failed { + echo "Failed to move amber to the installation directory." + echo "Please make sure that root user can access /opt directory." + exit(1) + } // Give permissions to execute amber - $sudo chmod +x "{place}/{target}"$ + $sudo chmod +x "{place}/{target}"$ failed { + echo "Failed to give permissions to execute amber." + echo "Please make sure that root user can access /opt directory." + exit(1) + } // Create amber symbol link - $sudo ln -s "{place}/{target}" "/usr/local/bin/{target}"$ + $sudo ln -s "{place}/{target}" "/usr/local/bin/{target}"$ failed { + echo "Failed to create amber symbol link." + echo "Please make sure that root user can access /usr/local/bin directory." + exit(1) + } // Send success message echo "Amber has been installed successfully. 🎉" } diff --git a/setup/install.sh b/setup/install.sh index 606e6186..7f7484ea 100755 --- a/setup/install.sh +++ b/setup/install.sh @@ -7,25 +7,58 @@ if [ $__AMBER_STATUS != 0 ]; then fi; __AMBER_FUN_hasFailed18_v0=$(echo $__AMBER_STATUS '!=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//'); return 0 +}; +function exit__19_v0 { + local code=$1 + exit "${code}" +__AMBER_STATUS=$?; +if [ $__AMBER_STATUS != 0 ]; then +: +fi +}; +function includes__20_v0 { + local arr=("${!1}") + local value=$2 + [[ "${arr[@]}" =~ "${value}" ]] +__AMBER_STATUS=$?; +if [ $__AMBER_STATUS != 0 ]; then +: +fi; + __AMBER_FUN_includes20_v0=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//'); + return 0 } __0_name="AmberNative"; __1_target="amber"; __2_tag="0.3.1-alpha"; __3_place="/opt/amber"; + __AMBER_VAL_0=$(uname -s); __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to determine OS type."; + echo "Please try again or use another download method."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__13=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__13} > /dev/null 2>&1 fi; - os=$(if [ $([ "_${__AMBER_VAL_0}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi); + os_type="${__AMBER_VAL_0}"; + os=$(if [ $([ "_${os_type}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi); __AMBER_VAL_1=$(uname -m); __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to determine architecture."; + echo "Please try again or use another download method."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__23=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__23} > /dev/null 2>&1 fi; - arch=$(if [ $([ "_${__AMBER_VAL_1}" != "_arm64" ]; echo $?) != 0 ]; then echo "aarch64"; else echo "x86_64"; fi); + arch_type="${__AMBER_VAL_1}"; + __AMBER_ARRAY_0=("arm64" "aarch64"); + includes__20_v0 __AMBER_ARRAY_0[@] "${arch_type}"; + __AMBER_FUN_includes20_v0__25=${__AMBER_FUN_includes20_v0}; + arch=$(if [ ${__AMBER_FUN_includes20_v0__25} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi); url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}"; - test -d "${__3_place}" + test -d "${__3_place}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then : @@ -35,74 +68,92 @@ fi; echo "It seems that Amber is already installed on your system. (${__3_place})"; echo "If you want to reinstall Amber, uninstall it first."; echo "(Find out more at https://amber.marbl.cc)"; - exit 0 -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -: -fi + exit__19_v0 2; + __AMBER_FUN_exit19_v0__40=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__40} > /dev/null 2>&1 fi; echo "Installing Amber"; hasFailed__18_v0 "ruby -v"; - __AMBER_FUN_hasFailed18_v0__36=${__AMBER_FUN_hasFailed18_v0}; + __AMBER_FUN_hasFailed18_v0__46=${__AMBER_FUN_hasFailed18_v0}; hasFailed__18_v0 "curl -v"; - __AMBER_FUN_hasFailed18_v0__45=${__AMBER_FUN_hasFailed18_v0}; + __AMBER_FUN_hasFailed18_v0__55=${__AMBER_FUN_hasFailed18_v0}; hasFailed__18_v0 "wget -V"; - __AMBER_FUN_hasFailed18_v0__49=${__AMBER_FUN_hasFailed18_v0}; - if [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__36} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then + __AMBER_FUN_hasFailed18_v0__63=${__AMBER_FUN_hasFailed18_v0}; + if [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__46} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then code="require \"open-uri\"; open(\"${__1_target}\", \"wb\") do |file|; file << open(\"${url}\").read; end"; echo "Using ruby as a download method..."; sudo ruby -e "${code}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then echo "Ruby failed to download amber."; - echo "Please try again or use another download method."; - exit 1 -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -: -fi + echo "Something went wrong. Please try again later."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__52=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__52} > /dev/null 2>&1 fi -elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__45} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then +elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__55} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then echo "Using curl as a download method..."; curl -o "${__1_target}" "${url}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Curl failed to download amber."; + echo "Something went wrong. Please try again later."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__60=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__60} > /dev/null 2>&1 fi -elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__49} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then +elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0__63} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then echo "Using wget as a download method..."; wget -O "${__1_target}" "${url}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Wget failed to download amber."; + echo "Something went wrong. Please try again later."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__68=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__68} > /dev/null 2>&1 fi else echo "Neither ruby, curl or wget are installed on your system."; echo "Please install one of them and try again."; - exit 1 -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -: -fi + exit__19_v0 1; + __AMBER_FUN_exit19_v0__74=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__74} > /dev/null 2>&1 fi; sudo mkdir "${__3_place}" > /dev/null __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to create directory for amber."; + echo "Please make sure that root user can access /opt directory."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__82=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__82} > /dev/null 2>&1 fi; sudo mv "${__1_target}" "${__3_place}/${__1_target}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to move amber to the installation directory."; + echo "Please make sure that root user can access /opt directory."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__88=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__88} > /dev/null 2>&1 fi; sudo chmod +x "${__3_place}/${__1_target}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to give permissions to execute amber."; + echo "Please make sure that root user can access /opt directory."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__94=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__94} > /dev/null 2>&1 fi; sudo ln -s "${__3_place}/${__1_target}" "/usr/local/bin/${__1_target}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to create amber symbol link."; + echo "Please make sure that root user can access /usr/local/bin directory."; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__100=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__100} > /dev/null 2>&1 fi; echo "Amber has been installed successfully. 🎉" \ No newline at end of file diff --git a/setup/uninstall.ab b/setup/uninstall.ab index 400f69d5..93d9cdd0 100644 --- a/setup/uninstall.ab +++ b/setup/uninstall.ab @@ -1,11 +1,21 @@ -unsafe { - let place = "/opt/amber" +import { exit } from "std" - $test -d "{place}" > /dev/null$ +let place = "/opt/amber" - if $echo \$?$ == "0" { - $sudo rm -rf "{place}"$ - $sudo rm "/usr/local/bin/amber"$ +main { + unsafe $test -d "{place}" > /dev/null$ + + if status == 0 { + $sudo rm -rf "{place}"$ failed { + echo "Failed to remove Amber from {place}" + echo "Make sure root has the correct permissions to access this directory" + exit(1) + } + $sudo rm "/usr/local/bin/amber"$ failed { + echo "Failed to remove Amber from /usr/local/bin" + echo "Make sure root has the correct permissions to access this directory" + exit(1) + } echo "Uninstalled Amber successfully 🎉" } else { diff --git a/setup/uninstall.sh b/setup/uninstall.sh index 479838f2..0e89197e 100755 --- a/setup/uninstall.sh +++ b/setup/uninstall.sh @@ -1,24 +1,36 @@ - place="/opt/amber"; - test -d "${place}" > /dev/null +function exit__19_v0 { + local code=$1 + exit "${code}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then : -fi; - __AMBER_VAL_0=$(echo $?); - __AMBER_STATUS=$?; +fi +} +__0_place="/opt/amber"; + + test -d "${__0_place}" > /dev/null +__AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then : fi; - if [ $([ "_${__AMBER_VAL_0}" != "_0" ]; echo $?) != 0 ]; then - sudo rm -rf "${place}" + if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then + sudo rm -rf "${__0_place}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to remove Amber from ${__0_place}"; + echo "Make sure root has the correct permissions to access this directory"; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__12=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__12} > /dev/null 2>&1 fi; sudo rm "/usr/local/bin/amber" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then -: + echo "Failed to remove Amber from /usr/local/bin"; + echo "Make sure root has the correct permissions to access this directory"; + exit__19_v0 1; + __AMBER_FUN_exit19_v0__17=${__AMBER_FUN_exit19_v0}; + echo ${__AMBER_FUN_exit19_v0__17} > /dev/null 2>&1 fi; echo "Uninstalled Amber successfully 🎉" else diff --git a/src/std/main.ab b/src/std/main.ab index ebb390c8..273cd6d3 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -94,3 +94,8 @@ pub fun hasFailed(command: Text): Bool { pub fun exit(code: Num): Null { unsafe $exit "{code}"$ } + +pub fun includes(arr, value) { + unsafe $[[ "\$\{{nameof arr}[@]}" =~ "{value}" ]]$ + return status == 0 +} diff --git a/src/tests/validity.rs b/src/tests/validity.rs index 865a4062..52452532 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -772,9 +772,13 @@ fn test_std_library() { // Parse text into a number echo parse(\"123\")? // Parse text into a number - do some code if failed - echo parse(\"XDDDDabc123\") failed { + parse(\"XDDDDabc123\") failed { echo \"Parsing Failed\" } + // Check if array includes certain word + echo includes([\"hello\", \"world\"], \"hello\") + // Check if array does not include certain word + echo includes([\"hello\", \"world\"], \"other\") } "; test_amber!(code, vec![ @@ -791,6 +795,8 @@ fn test_std_library() { "hello universe", "123", "Parsing Failed", + "1", + "0", ].join("\n")); }