Skip to content

Commit

Permalink
feat: add new std function and fix linux arm64 bad installation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Nov 3, 2023
1 parent 5bd596c commit 678f996
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 64 deletions.
64 changes: 49 additions & 15 deletions setup/install.ab
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
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"

// Set the download link
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"
Expand All @@ -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. 🎉"
}
117 changes: 84 additions & 33 deletions setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
:
Expand All @@ -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. 🎉"
22 changes: 16 additions & 6 deletions setup/uninstall.ab
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
30 changes: 21 additions & 9 deletions setup/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/std/main.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit 678f996

Please sign in to comment.