1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00
bobbylisp/install.sh

159 lines
4.3 KiB
Bash
Raw Normal View History

2022-01-26 07:49:01 -06:00
#!/bin/bash
2022-01-26 08:41:02 -06:00
# --- Initialization ---
set +x
path=$(pwd)
tput smcup # Switch to alternate screen so we preserve the terminal history
tput civis
2022-01-26 07:49:01 -06:00
2022-01-26 08:49:24 -06:00
trap clean_up_fail INT
2022-01-26 08:41:02 -06:00
clean_up() {
tput rmcup
tput cnorm
echo "${1:-Goodbye! o/}"
exit 0
2022-01-26 07:49:01 -06:00
}
2022-01-26 08:48:24 -06:00
clean_up_fail() {
tput rmcup
tput cnorm
echo "${1:-Installation failed! :(}"
exit 1
}
2022-01-26 08:41:02 -06:00
# --- Displaying ---
print_menu() {
2022-01-28 00:20:20 -06:00
local function_arguments=($@)
2022-01-26 07:49:01 -06:00
2022-01-28 00:20:20 -06:00
local selected_item="$1"
local menu_items=(${function_arguments[@]:1})
local menu_size="${#menu_items[@]}"
2022-01-26 07:49:01 -06:00
2022-01-28 00:20:20 -06:00
for (( i = 0; i < $menu_size; ++i )) do
if [ "$i" = "$selected_item" ]
2022-01-26 08:41:02 -06:00
then echo -e "\033[2K\e[1m>\e[0m \e[1;33m${menu_items[i]}\e[0m"
2022-01-28 00:20:20 -06:00
else echo -e "\033[2K ${menu_items[i]}"
fi
done
2022-01-26 07:49:01 -06:00
}
2022-01-26 08:41:02 -06:00
run_menu() {
2022-01-28 00:20:20 -06:00
local function_arguments=($@)
local selected_item="$1"
local menu_items=(${function_arguments[@]:1})
local menu_size="${#menu_items[@]}"
local menu_limit=$((menu_size - 1))
clear
print_menu "$selected_item" "${menu_items[@]}"
while read -rsn1 input
do
case "$input" in
$'\x1B')
read -rsn1 -t 0.1 input
if [ "$input" = "[" ]
then
read -rsn1 -t 0.1 input
case "$input"
in
A) # Arrow up
if [ "$selected_item" -ge 1 ]
then
selected_item=$((selected_item - 1))
clear
print_menu "$selected_item" "${menu_items[@]}"
fi;;
B) # Arrow down
if [ "$selected_item" -lt "$menu_limit" ]
then
selected_item=$((selected_item + 1))
clear
print_menu "$selected_item" "${menu_items[@]}"
fi;;
esac
fi
2022-01-26 08:41:02 -06:00
# stdin flush
2022-01-28 00:20:20 -06:00
read -rsn5 -t 0.1;;
"") # Enter
return "$selected_item";;
esac
done
2022-01-26 07:49:01 -06:00
}
2022-01-26 08:41:02 -06:00
# --- Installation ---
2022-01-26 08:48:24 -06:00
check_installed() {
2022-01-26 08:49:24 -06:00
if ! [ -x "$(command -v $1)" ]
then clean_up_fail "Please check that you have $1 installed!"
2022-01-26 08:48:24 -06:00
fi
}
2022-01-26 08:41:02 -06:00
install() {
local selected_install_item=0
local install_opts=("Download" "Compile" "Compile(Debug)" "Exit")
run_menu "$selected_install_item" "${install_opts[@]}"
local install_chosen="$?"
case "$install_chosen" in
0) echo "There is no release yet, please hold tight!";;
1)
2022-01-26 08:48:24 -06:00
echo "Testing dependencies..."
check_installed git
check_installed cargo
2022-01-26 08:41:02 -06:00
echo "Setting up folders..."
mkdir -p ~/.cache/
rm -rf ~/.cache/bobbylisp/
echo "Cloning repository..."
cd ~/.cache/
git clone https://github.com/azur1s/bobbylisp
cd ~/.cache/bobbylisp/
echo "Compiling..."
cargo build --release
mv ~/.cache/bobbylisp/target/release/blspc ~/bin/blspc
clean_up "Done! Thanks a lot for trying out Bobbylisp!";;
2)
2022-01-26 08:48:24 -06:00
echo "Testing dependencies..."
check_installed git
check_installed cargo
2022-01-26 08:41:02 -06:00
echo "Setting up folders..."
mkdir -p ~/.cache/
rm -rf ~/.cache/bobbylisp/
echo "Cloning repository..."
cd ~/.cache/
git clone https://github.com/azur1s/bobbylisp
cd ~/.cache/bobbylisp/
echo "Compiling..."
cargo build
mv ~/.cache/bobbylisp/target/debug/blspc ~/bin/blspc
clean_up "Done! Thanks a lot for trying out Bobbylisp!";;
3) clean_up;;
esac
}
uninstall() {
echo "Uninstalling blspc..."
rm ~/bin/blspc -f
rm /usr/bin/blspc -f
sleep 1s
echo "Uninstalling trolley..."
rm ~/bin/trolley -f
rm /usr/bin/trolley -f
sleep 1s
clean_up "Sad to see you go! Goodbye! o/"
}
2022-01-26 07:49:01 -06:00
selected_item=0
2022-01-26 08:41:02 -06:00
menu_opts=("Install" "Uninstall" "Exit")
run_menu "$selected_item" "${menu_opts[@]}"
menu_chosen="$?"
case "$menu_chosen" in
2022-01-28 00:20:20 -06:00
0) install;;
1) uninstall;;
2) clean_up;;
2022-01-26 08:41:02 -06:00
esac