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

feat: (almost) working install script

This commit is contained in:
Natapat Samutpong 2022-01-26 21:41:02 +07:00
parent b78cb3b9a4
commit 32f5f422d3

View file

@ -1,29 +1,37 @@
#!/bin/bash #!/bin/bash
tput sc # --- Initialization ---
set +x
path=$(pwd)
tput smcup # Switch to alternate screen so we preserve the terminal history
tput civis
function clear_print() { trap clean_up INT
tput rc
clean_up() {
tput rmcup
tput cnorm
echo "${1:-Goodbye! o/}"
exit 0
} }
function print_menu() { # --- Displaying ---
print_menu() {
local function_arguments=($@) local function_arguments=($@)
local selected_item="$1" local selected_item="$1"
local menu_items=(${function_arguments[@]:1}) local menu_items=(${function_arguments[@]:1})
local menu_size="${#menu_items[@]}" local menu_size="${#menu_items[@]}"
for (( i = 0; i < $menu_size; ++i )) for (( i = 0; i < $menu_size; ++i )) do
do
if [ "$i" = "$selected_item" ] if [ "$i" = "$selected_item" ]
then then echo -e "\033[2K\e[1m>\e[0m \e[1;33m${menu_items[i]}\e[0m"
echo "* ${menu_items[i]}" else echo -e "\033[2K ${menu_items[i]}"
else
echo " ${menu_items[i]}"
fi fi
done done
} }
function run_menu() { run_menu() {
local function_arguments=($@) local function_arguments=($@)
local selected_item="$1" local selected_item="$1"
@ -31,13 +39,12 @@ function run_menu() {
local menu_size="${#menu_items[@]}" local menu_size="${#menu_items[@]}"
local menu_limit=$((menu_size - 1)) local menu_limit=$((menu_size - 1))
clear_print clear
print_menu "$selected_item" "${menu_items[@]}" print_menu "$selected_item" "${menu_items[@]}"
while read -rsn1 input while read -rsn1 input
do do
case "$input" case "$input" in
in
$'\x1B') $'\x1B')
read -rsn1 -t 0.1 input read -rsn1 -t 0.1 input
if [ "$input" = "[" ] if [ "$input" = "[" ]
@ -49,44 +56,84 @@ function run_menu() {
if [ "$selected_item" -ge 1 ] if [ "$selected_item" -ge 1 ]
then then
selected_item=$((selected_item - 1)) selected_item=$((selected_item - 1))
clear_print clear
print_menu "$selected_item" "${menu_items[@]}" print_menu "$selected_item" "${menu_items[@]}"
fi fi;;
;;
B) # Arrow down B) # Arrow down
if [ "$selected_item" -lt "$menu_limit" ] if [ "$selected_item" -lt "$menu_limit" ]
then then
selected_item=$((selected_item + 1)) selected_item=$((selected_item + 1))
clear_print clear
print_menu "$selected_item" "${menu_items[@]}" print_menu "$selected_item" "${menu_items[@]}"
fi fi;;
;;
esac esac
fi fi
read -rsn5 -t 0.1 # stdin flush # stdin flush
;; read -rsn5 -t 0.1;;
"") # Enter "") # Enter
return "$selected_item" return "$selected_item";;
;;
esac esac
done done
} }
# --- Installation ---
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)
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)
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/"
}
selected_item=0 selected_item=0
menu_items=("Install" "Uninstall" "Exit") menu_opts=("Install" "Uninstall" "Exit")
run_menu "$selected_item" "${menu_items[@]}" run_menu "$selected_item" "${menu_opts[@]}"
menu_result="$?" menu_chosen="$?"
case "$menu_result" case "$menu_chosen" in
in 0) install;;
0) 1) uninstall;;
echo "Install selected" 2) clean_up;;
;;
1)
echo "Uninstall selected"
;;
2)
echo "Goodbye"
;;
esac esac