Add utils

This commit is contained in:
urban
2023-08-27 10:00:10 +02:00
parent a2528ce87b
commit 1e46cb2178
3 changed files with 177 additions and 1 deletions

View File

@@ -1 +1,79 @@
#!/bin/bash
p() {
echo -e " » $1"
}
p_user() {
echo -e " $1"
}
p_err(){
echo -e " \033[31m»\033[0m $1"
}
p_fatal(){
echo -e " \033[31m» $1\033[0m"
}
p_ok(){
echo -e " \033[32m»\033[0m $1"
}
p_warn(){
echo -e " \033[33m!\033[0m $1"
}
gum(){
~/go/bin/gum $@
}
msg() {
echo ""
echo -e "$(cat ../messages/$1)"
echo ""
}
ask_yes_or_no(){
echo -e " \033[33m?\033[0m $1"
result=$(gum choose --cursor=    Yes No)
if [[ $result == "Yes" ]]; then
p_user "Yes"
return 0
fi
p_user "No"
return 1
}
spin_it(){
local msg=$1
shift
local command=$@
local hash=$(echo -n "$command" | md5sum | awk '{print $1}')
local logfile="/tmp/shuriken/$hash.txt"
"$@" > $logfile 2>&1 &
chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ")
pid=$!
while kill -0 $pid 2> /dev/null; do
for char in "${chars[@]}"; do
echo -ne "\r$char"
sleep 0.1
done
done
wait $pid
exit_status=$?
echo -ne "\r\033[K"
if [ $exit_status -eq 0 ]; then
p $msg
else
p_fatal "$msg [FATAL ERROR]"
p_fatal "--- BEGIN ERROR DUMP ---"
awk '{print " \033[31m " $0 "\033[0m"}' $logfile
p_fatal "--- END ERROR DUMP ---"
exit 1
fi
if [ $VERBOSE -eq 1 ]; then
awk '{print " ‣ " $0}' $logfile
echo ""
fi
}

12
build.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
echo -e "Script to build Shuriken"
echo "#!/bin/bash" > install.sh
echo "# File generated automatically by build.sh. Do not modify" >> install.sh
echo "# DO NOT MODIFY" >> install.sh
echo "" >> install.sh
cat Scripts/utils.sh >> install.sh
echo -e "\n\n" >> install.sh
cat Scripts/installer.sh >> install.sh
chmod +x install.sh
echo "Finished"

86
install.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/bash
# File generated automatically by build.sh. Do not modify
# DO NOT MODIFY
#!/bin/bash
p() {
echo -e " » $1"
}
p_user() {
echo -e " $1"
}
p_err(){
echo -e " \033[31m»\033[0m $1"
}
p_fatal(){
echo -e " \033[31m» $1\033[0m"
}
p_ok(){
echo -e " \033[32m»\033[0m $1"
}
p_warn(){
echo -e " \033[33m!\033[0m $1"
}
gum(){
~/go/bin/gum $@
}
msg() {
echo ""
echo -e "$(cat ../messages/$1)"
echo ""
}
ask_yes_or_no(){
echo -e " \033[33m?\033[0m $1"
result=$(gum choose --cursor=    Yes No)
if [[ $result == "Yes" ]]; then
p_user "Yes"
return 0
fi
p_user "No"
return 1
}
spin_it(){
local msg=$1
shift
local command=$@
local hash=$(echo -n "$command" | md5sum | awk '{print $1}')
local logfile="/tmp/shuriken/$hash.txt"
"$@" > $logfile 2>&1 &
chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ")
pid=$!
while kill -0 $pid 2> /dev/null; do
for char in "${chars[@]}"; do
echo -ne "\r$char"
sleep 0.1
done
done
wait $pid
exit_status=$?
echo -ne "\r\033[K"
if [ $exit_status -eq 0 ]; then
p $msg
else
p_fatal "$msg [FATAL ERROR]"
p_fatal "--- BEGIN ERROR DUMP ---"
awk '{print " \033[31m " $0 "\033[0m"}' $logfile
p_fatal "--- END ERROR DUMP ---"
exit 1
fi
if [ $VERBOSE -eq 1 ]; then
awk '{print " ‣ " $0}' $logfile
echo ""
fi
}