mirror of
https://github.com/aljazceru/shurikenpi.io.git
synced 2025-12-17 06:04:23 +01:00
Add utils
This commit is contained in:
@@ -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
12
build.sh
Executable 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
86
install.sh
Executable 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user