mabox-pipemenus/usr/bin/mabox-include.cfg

188 lines
5.3 KiB
INI
Executable File

# cbpp-include.cfg - Variables and functions commonly used in custom scripts for
# CrunchBang GNU/Linux <http://crunchbanglinux.org/>.
# Ported to #!++ <https://crunchbangplusplus.org>
# by Ben Young <computermouth@crunchbangplusplus.org>
# Ported to Manjaro <https://manjaro.github.io/>
# by Daniel Napora <napcok@gmail.com>
# Usage: say text [delayAfterText]
say() {
fold -s -w 76 <<< "$1" | sed 's/^/ /' # wraps text nicely and adds two leading spaces
sleep "${2-0}"
}
# Usage: prompt text [Y | N | Q]
prompt() {
local answer prompt default
if [[ ${2^} = Q* ]]; then
#say "$1"
read -srn1 -p "$1" answer
echo
[[ ${answer,} = 'q' ]] && return 0 || return 1
fi
if [[ ! $2 || ${2^} = Y* ]]; then
prompt='Y/n'
default='Y'
elif [[ ${2^} = N* ]]; then
prompt='y/N'
default='N'
fi
while true; do
read -r -p "$1 [$prompt] " answer
[[ ! $answer ]] &&
answer=$default
if [[ ${answer^} = Y* ]]; then
say
return 0
elif [[ ${answer^} = N* ]]; then
say
return 1
fi
done
}
# Check the connection by downloading a file from ftp.debian.org. No disk space used.
# Usage: connectiontest [attempts]
# If attempt count is not specified or 0, then it will loop forever and exit(!) your main program with 1 exit status.
connectiontest() {
case $LANG in
pl*)
local TEXT_CHECKING='Sprawdzanie połączenia internetowego...'
local TEXT_FAILED='Brak połączenia internetowego!'
local TEXT_ASK_RETRY=$'\n\nTen skrypt wymaga działającego połączenia internetowego. Skonfiguruj połączenie internetowe, a następnie wciśnij dowolny klawisz, aby kontynuować, aby wyjść wciśnij "q".'
local TEXT_ABORT='Skrypt przerwany.'
local TEXT_OK='Test połączenia internetowego zakończył się powodzeniem!'
;;
*)
local TEXT_CHECKING='Checking internet connection...'
local TEXT_FAILED='Internet connection test failed!'
local TEXT_ASK_RETRY=$'\n\nThis script requires a working internet connection. Please configure your internet connection, then hit any key to continue, else hit "q" to quit.'
local TEXT_ABORT='Script aborted.'
local TEXT_OK='Internet connection test passed!'
;;
esac
local -i i attempts=${1-0}
for (( i=0; i < attempts || attempts == 0; i++ )); do
say "$TEXT_CHECKING"
if wget -O - 'http://ftp.debian.org/debian/README' &> /dev/null; then
say "$TEXT_OK" 1
return 0
fi
say "$TEXT_FAILED"
if (( i == attempts - 1 )); then # if last attempt
return 1
elif prompt "$TEXT_ASK_RETRY" Q; then # if user wants to quit
say "$TEXT_ABORT" 2
(( attempts == 0 )) && exit 1 || return 1
fi
clear
done
}
menuStart() {
echo ' <openbox_pipe_menu>'
}
# Usage: menuItem label command
menuItem() {
echo " <item label=\"$1\">"
echo ' <action name="Execute">'
echo ' <command>'
echo " $2"
echo ' </command>'
echo ' </action>'
echo ' </item>'
}
# Usage: menuSeparator [label]
menuSeparator() {
if [[ $1 ]]; then
echo " <separator label=\"$1\"/>"
else
echo ' <separator/>'
fi
}
# Usage menuSubmenu id label # http://openbox.org/wiki/Help:Menus
menuSubmenu() {
echo " <menu id=\"$1\" label=\"$2\">"
}
menuSubmenuEnd() {
echo ' </menu>'
}
menuEnd() {
echo ' </openbox_pipe_menu>'
}
# Usage: promptInstall title description package...
promptInstall() {
case $LANG in
pl*)
PROBLEM="Wystąpił problem podczas instalowania"
HITANY=" Wciśnij dowolny klawisz aby spróbować ponownie, lub 'q' aby wyjść"
INST="INSTALACJA"
WILLINST="Ten skrypt zainstaluje"
RUNNOW=" Uruchomić instalowanie?"
UPD_SOURCES="Aktualizowanie źródeł..."
INSTALLING="Instalowanie pakietu..."
SUCCESFULLY="został zainstalowany."
ANYKEYEXIT="Wciśnij dowolny klawisz aby wyjść..."
;;
*)
PROBLEM="There was a problem installing"
HITANY=" Hit any key to try again, or 'q' to quit..."
INST="INSTALL"
WILLINST="This script will install"
RUNNOW=" Run the installer now?"
UPD_SOURCES="Updating sources..."
INSTALLING="Installing package..."
SUCCESFULLY="has been installed successfully."
ANYKEYEXIT="Hit any key to exit..."
;;
esac
while true; do # Repeat until there are no errors
if [[ $TRYAGAIN ]]; then # previous try failed
say
say "$PROBLEM ${2,,}."
say
prompt "$HITANY" Q && return 1
fi
local TRYAGAIN=true
clear
say
say "$INST ${1^^}"
say '------------------------'
say "$WILLINST ${2,,}."
say
prompt "$RUNNOW" || return 0
clear
connectiontest || continue
clear
say "$UPD_SOURCES" 1
sudo pacman -Syu
clear
say "$INSTALLING" 1
sudo pacman -S "${@:3}" || continue
clear
say
say "${2^} $SUCCESFULLY"
say
say "$ANYKEYEXIT"
read -srn1
return 0
done
}