Skip to content

Commit

Permalink
Merge pull request #78 from boushley/support-user-only-install
Browse files Browse the repository at this point in the history
Support user only install
  • Loading branch information
Ph0enixKM authored May 22, 2024
2 parents d1b6852 + 27a7fa5 commit 90550c7
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 49 deletions.
57 changes: 45 additions & 12 deletions setup/install.ab
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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 {
main(args) {
// Determine OS type
let os_type = $uname -s$ failed {
echo "Failed to determine OS type."
Expand All @@ -31,8 +32,19 @@ main {
then "aarch64"
else "x86_64"

// Set the download link
let url = "https://github.com/Ph0enixKM/{name}/releases/download/{tag}/amber_{os}_{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"
}

// Check if such directory exists
unsafe $test -d "{place}"$
Expand All @@ -54,33 +66,51 @@ main {

echo "Installing Amber... 🚀"

// Make the directories we need first to ensure we have permissions before downloading any files
// this decreases the chance that our script results in partial installation leaving assets behind
let sudo = user_only_install then "" else "sudo"
// Create directory for amber
silent ${sudo} mkdir -p "{place}"$ failed {
echo "Failed to create directory for amber."
if user_only_install {
echo "Please make sure that root user can access {place} directory."
} else {
echo "Please make sure that your user can access {place} directory."
}
exit(1)
}
if user_only_install {
silent $mkdir -p "{bins_folder}"$ failed {
echo "Failed to create directory for amber bin at {bins_folder}."
exit(1)
}
}

// Set the download link
let url = "https://github.com/Ph0enixKM/{name}/releases/download/{tag}/amber_{os}_{arch}"

// Download amber
silent $curl -L -o "{target}" "{url}"$ failed {
echo "Curl failed to download amber."
echo "Something went wrong. Please try again later."
exit(1)
}

// Create directory for amber
silent $sudo mkdir "{place}"$ 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}"$ failed {
${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}"$ failed {
${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}"$ failed {
${sudo} ln -s "{place}/{target}" "{bins_folder}/{target}"$ failed {
echo "Failed to create amber symbol link."
echo "Please make sure that root user can access /usr/local/bin directory."
exit(1)
Expand All @@ -92,4 +122,7 @@ main {
// Send success message
echo "Amber has been installed successfully. 🎉"
echo "> Now you can use amber by typing `amber` in your terminal."
if user_only_install {
echo "> Since you requested a user only install with `--user` ensure that ~/.local/bin is in your \\$PATH."
}
}
126 changes: 89 additions & 37 deletions setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,40 @@ fi;
__AMBER_FUN_includes21_v0=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
function includes__21_v1 {
local arr=$1
local value=$2
[[ "${arr[@]}" =~ "${value}" ]]
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
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__7=${__AMBER_FUN_has_failed19_v0};
__AMBER_FUN_has_failed19_v0__8=${__AMBER_FUN_has_failed19_v0};
__AMBER_VAL_0=$(uname -a);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__4_agent=$(if [ ${__AMBER_FUN_has_failed19_v0__7} != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_0}"; 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);
__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__18=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__18} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__19=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__19} > /dev/null 2>&1
fi;
os_type="${__AMBER_VAL_1}";
os=$(if [ $([ "_${os_type}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
Expand All @@ -58,15 +70,36 @@ 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__28=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__28} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__29=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__29} > /dev/null 2>&1
fi;
arch_type="${__AMBER_VAL_2}";
__AMBER_ARRAY_0=("arm64" "aarch64");
includes__21_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AMBER_FUN_includes21_v0__30=${__AMBER_FUN_includes21_v0};
arch=$(if [ ${__AMBER_FUN_includes21_v0__30} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}";
__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=$?;
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
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
fi;
__3_place="${home}/.local/lib/${arch}/amber";
__4_bins_folder="${home}/.local/bin"
fi;
test -d "${__3_place}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
Expand All @@ -78,68 +111,87 @@ fi;
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__45=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__45} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__57=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__57} > /dev/null 2>&1
fi;
has_failed__19_v0 "curl -V";
__AMBER_FUN_has_failed19_v0__49=${__AMBER_FUN_has_failed19_v0};
if [ ${__AMBER_FUN_has_failed19_v0__49} != 0 ]; then
__AMBER_FUN_has_failed19_v0__61=${__AMBER_FUN_has_failed19_v0};
if [ ${__AMBER_FUN_has_failed19_v0__61} != 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__52=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__52} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__64=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__64} > /dev/null 2>&1
fi;
echo "Installing Amber... 🚀";
curl -L -o "${__1_target}" "${url}" > /dev/null 2>&1
sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi);
${sudo} mkdir -p "${__3_place}" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Curl failed to download amber.";
echo "Something went wrong. Please try again later.";
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."
else
echo "Please make sure that your user can access ${__3_place} directory."
fi;
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__61=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__61} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__80=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__80} > /dev/null 2>&1
fi;
sudo mkdir "${__3_place}" > /dev/null 2>&1
if [ ${user_only_install} != 0 ]; then
mkdir -p "${__4_bins_folder}" > /dev/null 2>&1
__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.";
echo "Failed to create directory for amber bin at ${__4_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
fi
fi;
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}";
curl -L -o "${__1_target}" "${url}" > /dev/null 2>&1
__AMBER_STATUS=$?;
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__68=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__68} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__96=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__96} > /dev/null 2>&1
fi;
sudo mv "${__1_target}" "${__3_place}/${__1_target}"
${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__20_v0 1;
__AMBER_FUN_exit20_v0__74=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__74} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__103=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__103} > /dev/null 2>&1
fi;
sudo chmod +x "${__3_place}/${__1_target}"
${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__20_v0 1;
__AMBER_FUN_exit20_v0__80=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__80} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__109=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__109} > /dev/null 2>&1
fi;
sudo ln -s "${__3_place}/${__1_target}" "/usr/local/bin/${__1_target}"
${sudo} ln -s "${__3_place}/${__1_target}" "${__4_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__86=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__86} > /dev/null 2>&1
__AMBER_FUN_exit20_v0__116=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__116} > /dev/null 2>&1
fi;
curl -G --data-urlencode "agent=${__4_agent}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" > /dev/null 2>&1
curl -G --data-urlencode "agent=${__5_agent}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
echo "Amber has been installed successfully. 🎉";
echo "> Now you can use amber by typing \`amber\` in your terminal."
echo "> Now you can use amber by typing \`amber\` in your terminal.";
if [ ${user_only_install} != 0 ]; then
echo "> Since you requested a user only install with \`--user\` ensure that ~/.local/bin is in your \$PATH."
fi

0 comments on commit 90550c7

Please sign in to comment.