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

188 lines
5.3 KiB
INI
Raw Permalink Normal View History

2016-03-25 19:02:03 +01:00
# 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() {
2016-12-28 00:47:15 +01:00
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!'
;;
*)
2016-03-25 19:02:03 +01:00
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!'
2016-12-28 00:47:15 +01:00
;;
esac
2016-03-25 19:02:03 +01:00
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() {
2016-12-28 00:47:15 +01:00
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
2016-03-25 19:02:03 +01:00
while true; do # Repeat until there are no errors
if [[ $TRYAGAIN ]]; then # previous try failed
say
2016-12-28 00:47:15 +01:00
say "$PROBLEM ${2,,}."
2016-03-25 19:02:03 +01:00
say
2016-12-28 00:47:15 +01:00
prompt "$HITANY" Q && return 1
2016-03-25 19:02:03 +01:00
fi
local TRYAGAIN=true
clear
say
2016-12-28 00:47:15 +01:00
say "$INST ${1^^}"
2016-03-25 19:02:03 +01:00
say '------------------------'
2016-12-28 00:47:15 +01:00
say "$WILLINST ${2,,}."
2016-03-25 19:02:03 +01:00
say
2016-12-28 00:47:15 +01:00
prompt "$RUNNOW" || return 0
2016-03-25 19:02:03 +01:00
clear
connectiontest || continue
clear
2016-12-28 00:47:15 +01:00
say "$UPD_SOURCES" 1
2016-03-25 19:02:03 +01:00
sudo pacman -Syu
clear
2016-12-28 00:47:15 +01:00
say "$INSTALLING" 1
2016-03-25 19:02:03 +01:00
sudo pacman -S "${@:3}" || continue
clear
say
2016-12-28 00:47:15 +01:00
say "${2^} $SUCCESFULLY"
2016-03-25 19:02:03 +01:00
say
2016-12-28 00:47:15 +01:00
say "$ANYKEYEXIT"
2016-03-25 19:02:03 +01:00
read -srn1
return 0
done
}