152 lines
4.0 KiB
INI
152 lines
4.0 KiB
INI
|
# 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() {
|
||
|
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!'
|
||
|
|
||
|
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() {
|
||
|
while true; do # Repeat until there are no errors
|
||
|
if [[ $TRYAGAIN ]]; then # previous try failed
|
||
|
say
|
||
|
say "There was a problem installing ${2,,}."
|
||
|
say
|
||
|
prompt ' Hit any key to try again, or "q" to quit...' Q && return 1
|
||
|
fi
|
||
|
local TRYAGAIN=true
|
||
|
|
||
|
clear
|
||
|
say
|
||
|
say "INSTALL ${1^^}"
|
||
|
say '------------------------'
|
||
|
say "This script will install ${2,,}."
|
||
|
say
|
||
|
prompt ' Run the installer now?' || return 0
|
||
|
|
||
|
clear
|
||
|
connectiontest || continue
|
||
|
|
||
|
clear
|
||
|
say 'Updating sources...' 1
|
||
|
sudo pacman -Syu
|
||
|
|
||
|
clear
|
||
|
say 'Installing package...' 1
|
||
|
sudo pacman -S "${@:3}" || continue
|
||
|
|
||
|
clear
|
||
|
say
|
||
|
say "${2^} has been installed successfully."
|
||
|
say
|
||
|
say 'Hit any key to exit...'
|
||
|
read -srn1
|
||
|
return 0
|
||
|
done
|
||
|
}
|