Skip to content
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

Update uninstall.ab to support user only mode. #82

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions setup/install.ab
Original file line number Diff line number Diff line change
@@ -1,50 +1,22 @@
import { has_failed, includes, exit, chars } from "std"
import { get_os, get_arch, get_place, get_bins_folder } from "./shared.ab"

let name = "AmberNative"
let target = "amber"
let tag = "0.3.1-alpha"
let place = "/opt/amber"
let bins_folder = "/usr/local/bin"
let agent = has_failed("uname -a")
then "unknown"
else unsafe $uname -a$

echo ""

main(args) {
// Determine OS type
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_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"
let os = get_os()
let arch = get_arch()

let user_only_install = includes(args, "--user")
if user_only_install {
let home = $echo \$HOME$ failed {
echo "User installation requested, but unable to retrieve home directory from $HOME environment."
exit(1)
}
if home == "" {
echo "User installation requested, but unable to find home directory."
exit(1)
}
place = "{home}/.local/lib/{arch}/amber"
bins_folder = "{home}/.local/bin"
}
let place = get_place(user_only_install)
let bins_folder = get_bins_folder(user_only_install)

// Check if such directory exists
unsafe $test -d "{place}"$
Expand Down
190 changes: 117 additions & 73 deletions setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,114 +38,158 @@ fi;
__AMBER_FUN_includes21_v1=$(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";
__4_bins_folder="/usr/local/bin";
has_failed__19_v0 "uname -a";
__AMBER_FUN_has_failed19_v0__8=${__AMBER_FUN_has_failed19_v0};
__AMBER_VAL_0=$(uname -a);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__5_agent=$(if [ ${__AMBER_FUN_has_failed19_v0__8} != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_0}"; fi);
echo "";
args=$1
__AMBER_VAL_1=$(uname -s);
function get_os__28_v0 {
__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__20_v0 1;
__AMBER_FUN_exit20_v0__19=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__19} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__8=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__8} > /dev/null 2>&1
fi;
os_type="${__AMBER_VAL_1}";
os=$(if [ $([ "_${os_type}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
__AMBER_VAL_2=$(uname -m);
local os_type="${__AMBER_VAL_0}";
local os=$(if [ $([ "_${os_type}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
__AMBER_FUN_get_os28_v0="${os}";
return 0
};
function get_arch__29_v0 {
__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__20_v0 1;
__AMBER_FUN_exit20_v0__29=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__29} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__22=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__22} > /dev/null 2>&1
fi;
arch_type="${__AMBER_VAL_2}";
local arch_type="${__AMBER_VAL_1}";
__AMBER_ARRAY_0=("arm64" "aarch64");
includes__21_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AMBER_FUN_includes21_v0__31=${__AMBER_FUN_includes21_v0};
arch=$(if [ ${__AMBER_FUN_includes21_v0__31} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
includes__21_v1 "${args}" "--user";
__AMBER_FUN_includes21_v1__35=${__AMBER_FUN_includes21_v1};
user_only_install=${__AMBER_FUN_includes21_v1__35};
if [ ${user_only_install} != 0 ]; then
__AMBER_VAL_3=$(echo $HOME);
__AMBER_STATUS=$?;
__AMBER_FUN_includes21_v0__25=${__AMBER_FUN_includes21_v0};
local arch=$(if [ ${__AMBER_FUN_includes21_v0__25} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
__AMBER_FUN_get_arch29_v0="${arch}";
return 0
};
function get_home__30_v0 {
__AMBER_VAL_2=$(echo $HOME);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "User installation requested, but unable to retrieve home directory from $HOME environment.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__39=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__39} > /dev/null 2>&1
echo "User installation requested, but unable to retrieve home directory from $HOME environment.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__35=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__35} > /dev/null 2>&1
fi;
home="${__AMBER_VAL_3}";
if [ $([ "_${home}" != "_" ]; echo $?) != 0 ]; then
echo "User installation requested, but unable to find home directory.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__43=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__43} > /dev/null 2>&1
local home="${__AMBER_VAL_2}";
if [ $([ "_${home}" != "_" ]; echo $?) != 0 ]; then
echo "User installation requested, but unable to find home directory.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__39=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__39} > /dev/null 2>&1
fi;
__3_place="${home}/.local/lib/${arch}/amber";
__4_bins_folder="${home}/.local/bin"
__AMBER_FUN_get_home30_v0="${home}";
return 0
};
function get_bins_folder__31_v0 {
local user_only=$1
if [ ${user_only} != 0 ]; then
get_home__30_v0 ;
__AMBER_FUN_get_home30_v0__46=${__AMBER_FUN_get_home30_v0};
__AMBER_FUN_get_bins_folder31_v0="${__AMBER_FUN_get_home30_v0__46}/.local/bin";
return 0
else
__AMBER_FUN_get_bins_folder31_v0="/usr/local/bin";
return 0
fi
};
function get_place__32_v0 {
local user_only=$1
if [ ${user_only} != 0 ]; then
get_home__30_v0 ;
__AMBER_FUN_get_home30_v0__54=${__AMBER_FUN_get_home30_v0};
get_arch__29_v0 ;
__AMBER_FUN_get_arch29_v0__54=${__AMBER_FUN_get_arch29_v0};
__AMBER_FUN_get_place32_v0="${__AMBER_FUN_get_home30_v0__54}/.local/lib/${__AMBER_FUN_get_arch29_v0__54}/amber";
return 0
else
__AMBER_FUN_get_place32_v0="/opt/amber";
return 0
fi
}
__0_name="AmberNative";
__1_target="amber";
__2_tag="0.3.1-alpha";
has_failed__19_v0 "uname -a";
__AMBER_FUN_has_failed19_v0__7=${__AMBER_FUN_has_failed19_v0};
__AMBER_VAL_3=$(uname -a);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
test -d "${__3_place}"
__3_agent=$(if [ ${__AMBER_FUN_has_failed19_v0__7} != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_3}"; fi);
echo "";
args=$1
get_os__28_v0 ;
__AMBER_FUN_get_os28_v0__14=${__AMBER_FUN_get_os28_v0};
os=${__AMBER_FUN_get_os28_v0__14};
get_arch__29_v0 ;
__AMBER_FUN_get_arch29_v0__15=${__AMBER_FUN_get_arch29_v0};
arch=${__AMBER_FUN_get_arch29_v0__15};
includes__21_v1 "${args}" "--user";
__AMBER_FUN_includes21_v1__17=${__AMBER_FUN_includes21_v1};
user_only_install=${__AMBER_FUN_includes21_v1__17};
get_place__32_v0 ${user_only_install};
__AMBER_FUN_get_place32_v0__18=${__AMBER_FUN_get_place32_v0};
place=${__AMBER_FUN_get_place32_v0__18};
get_bins_folder__31_v0 ${user_only_install};
__AMBER_FUN_get_bins_folder31_v0__19=${__AMBER_FUN_get_bins_folder31_v0};
bins_folder=${__AMBER_FUN_get_bins_folder31_v0__19};
test -d "${place}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
echo "Amber already installed";
echo "It seems that Amber is already installed on your system. (${__3_place})";
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://docs.amber-lang.com/getting_started/installation#uninstallation)";
exit__20_v0 2;
__AMBER_FUN_exit20_v0__57=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__57} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__29=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__29} > /dev/null 2>&1
fi;
has_failed__19_v0 "curl -V";
__AMBER_FUN_has_failed19_v0__61=${__AMBER_FUN_has_failed19_v0};
if [ ${__AMBER_FUN_has_failed19_v0__61} != 0 ]; then
__AMBER_FUN_has_failed19_v0__33=${__AMBER_FUN_has_failed19_v0};
if [ ${__AMBER_FUN_has_failed19_v0__33} != 0 ]; then
echo "Curl is not installed on your system.";
echo "Please install \`curl\` and try again.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__64=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__64} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__36=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__36} > /dev/null 2>&1
fi;
echo "Installing Amber... 🚀";
sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi);
${sudo} mkdir -p "${__3_place}" > /dev/null 2>&1
${sudo} mkdir -p "${place}" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to create directory for amber.";
if [ ${user_only_install} != 0 ]; then
echo "Please make sure that root user can access ${__3_place} directory."
echo "Please make sure that root user can access ${place} directory."
else
echo "Please make sure that your user can access ${__3_place} directory."
echo "Please make sure that your user can access ${place} directory."
fi;
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__80=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__80} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__52=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__52} > /dev/null 2>&1
fi;
if [ ${user_only_install} != 0 ]; then
mkdir -p "${__4_bins_folder}" > /dev/null 2>&1
mkdir -p "${bins_folder}" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to create directory for amber bin at ${__4_bins_folder}.";
echo "Failed to create directory for amber bin at ${bins_folder}.";
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__85=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__85} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__57=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__57} > /dev/null 2>&1
fi
fi;
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}";
Expand All @@ -155,37 +199,37 @@ if [ $__AMBER_STATUS != 0 ]; then
echo "Curl failed to download amber.";
echo "Something went wrong. Please try again later.";
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__96=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__96} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__68=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__68} > /dev/null 2>&1
fi;
${sudo} mv "${__1_target}" "${__3_place}/${__1_target}"
${sudo} mv "${__1_target}" "${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__20_v0 1;
__AMBER_FUN_exit20_v0__103=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__103} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__75=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__75} > /dev/null 2>&1
fi;
${sudo} chmod +x "${__3_place}/${__1_target}"
${sudo} chmod +x "${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__20_v0 1;
__AMBER_FUN_exit20_v0__109=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__109} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__81=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__81} > /dev/null 2>&1
fi;
${sudo} ln -s "${__3_place}/${__1_target}" "${__4_bins_folder}/${__1_target}"
${sudo} ln -s "${place}/${__1_target}" "${bins_folder}/${__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__20_v0 1;
__AMBER_FUN_exit20_v0__116=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__116} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__88=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__88} > /dev/null 2>&1
fi;
curl -G --data-urlencode "agent=${__5_agent}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" > /dev/null 2>&1
curl -G --data-urlencode "agent=${__3_agent}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
Expand Down
58 changes: 58 additions & 0 deletions setup/shared.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { exit, includes } from "std"

pub fun get_os(): Text {
// Determine OS type
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"

return os
}

pub fun get_arch(): Text {
// Determine architecture
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"

return arch
}

fun get_home(): Text {
let home = $echo \$HOME$ failed {
echo "User installation requested, but unable to retrieve home directory from $HOME environment."
exit(1)
}
if home == "" {
echo "User installation requested, but unable to find home directory."
exit(1)
}
return home
}

pub fun get_bins_folder(user_only: Bool): Text {
if user_only {
return "{get_home()}/.local/bin"
} else {
return "/usr/local/bin"
}
}

pub fun get_place(user_only: Bool): Text {
if user_only {
return "{get_home()}/.local/lib/{get_arch()}/amber"
} else {
return "/opt/amber"
}
}
Loading