vinstaller/etc/functions
2022-02-09 10:55:37 +01:00

178 lines
4.6 KiB
Plaintext

err() {
echo $1
echo "exiting.."
exit 1
}
header() {
if [ "$DEBUG" -ge "1" ]; then
echo please enter enter
read a
if [ "$a" -ge "2" ]; then
set -x
fi
if [ "$a" == "0" ]; then
DEBUG=0
fi
fi
clear
echo "#### $1 ####"
}
addpkg() {
for i in $@; do
pkgs+=( "$i" )
done
}
enable_service() {
for i in $@; do
if ! [ -h /etc/runit/runsvdir/default/${i} ]; then
ln -s /etc/sv/$i /etc/runit/runsvdir/default/
fi
done
}
disable_service() {
for i in $@; do
rm -rf /etc/runit/runsvdir/default/${i}
rm -rf /var/service/${i}
done
}
reset() {
if [ "$1" == "config" ]; then
function config() { :; }
elif [ "$1" == "packages" ]; then
function packages() { :; }
fi
}
input() {
output=""
echo "${1}"
read -r -p "[${2}]: " output
test -z "${output}" && output="${2}"
return 0
}
#multiplechoice "networksystem" "dhcpcd" "networkmanager" "iwd" "none"
multiplechoice() {
output=""
local done=""
local input=("${@}")
#for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do
for i in $(seq 0 "$(( ${#input[@]} - 1 ))"); do
if [[ "${i}" == "0" ]]; then
choices="${input[$i]}"
use="${input[$i]}"
else
choices="${choices}|${input[$i]}"
use+=" ${input[$i]}"
fi
done
while input "[${choices}]: " "${input[0]}"; do
for i in $(seq 0 "${#input[@]}"); do
if [[ "${output}" == "${input[$i]}" ]] || [[ "${output}" == "${input[$i]:0:2}" ]]; then
output="${input[$i]}"
done=1
fi
done
if [[ -z "${done}" ]]; then
echo wronginput "${output}"
echo use these: "${use}"
else
break
fi
done
}
yesno() {
local input=""
local retval=""
local default=""
local q=""
case "${2}" in
Y|y) q="${1} [Y|n]:"; default=y;;
N|n) q="${1} [y|N]:"; default=n;;
esac
while read -r -p "${q} " input; do
test -z "${input}" && input="${default}"
case "${input}" in
y*|Y*|*es*|*ES*|*Es*|*eS*|1)
retval=1
break
;;
n*|N*|0)
retval=""
break
;;
*) wronginput "${input}" "${choices[*]}"
;;
esac
done
if [[ -z "${retval}" ]]; then
return 1
else
return 0
fi
}
readin() {
WHICH="$1"
local -a choice
for i in $(find ./etc/${WHICH}/ -type f | sort); do
choice+=("$(basename $i)")
done
if [ "${#choice[@]}" -gt "1" ]; then
header "$WHICH"
multiplechoice "${choice[@]}"
elif [ "${#choice[@]}" -eq "1" ]; then
output=${choice[0]}
fi
if ! [ "${#choice[@]}" -eq "0" ]; then
if [ -s ./etc/${WHICH}/$output ]; then
if grep -q "packages()" ./etc/${WHICH}/$output; then
. ./etc/${WHICH}/$output
packages
reset packages
fi
if grep -q "config()" ./etc/${WHICH}/$output; then
cp ./etc/${WHICH}/$output $tmp_target
fi
fi
fi
}
ignorepkg() {
for i in $@; do
ignorepkgs+=( "$i" )
done
}
vmkdir() {
mkdir -p /"$1"
chmod 755 /"$1"
}
vinstall() {
src="$1"; tgt="$3"; rights="$2"
if [ "$4" ]; then
cp "${src}" "/${tgt}/${4}"
chmod="/${tgt}/${4}"
else
cp "${src}" "/${tgt}"
chmod="/${tgt}"
fi
chmod -R "${rights}" "${chmod}"
}
vbin() {
cp -rf "$1" /usr/bin/
chmod 0755 /usr/bin/"$(basename $1)"
}