2022-02-06 22:12:28 +01:00
|
|
|
err() {
|
|
|
|
echo $1
|
|
|
|
echo "exiting.."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-02-07 03:58:13 +01:00
|
|
|
input_old() {
|
2022-02-06 22:12:28 +01:00
|
|
|
local input
|
|
|
|
local found="0"
|
|
|
|
echo "$1 $2"
|
|
|
|
read input
|
|
|
|
for i in $2; do
|
|
|
|
if [ "$i" == "$input" ]; then
|
|
|
|
found=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$found" == "0" ]; then
|
|
|
|
err "$input: $3"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
output="$input"
|
|
|
|
}
|
|
|
|
|
|
|
|
header() {
|
2022-02-07 17:10:39 +01:00
|
|
|
if [ "$DEBUG" ]; then
|
2022-02-07 17:12:12 +01:00
|
|
|
echo please enter enter
|
2022-02-07 17:10:39 +01:00
|
|
|
read
|
|
|
|
fi
|
2022-02-07 02:34:12 +01:00
|
|
|
clear
|
2022-02-06 22:12:28 +01:00
|
|
|
echo "#### $1"
|
2022-02-07 02:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addpkg() {
|
|
|
|
for i in $@; do
|
2022-02-07 02:39:08 +01:00
|
|
|
pkgs+=( "$i" )
|
2022-02-07 02:34:12 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_service() {
|
2022-02-07 18:17:40 +01:00
|
|
|
for i in $@; do
|
2022-02-07 18:38:05 +01:00
|
|
|
if ! [ -h /etc/runit/runsvdir/default/${i} ]; then
|
2022-02-07 18:22:59 +01:00
|
|
|
ln -s /etc/sv/$i /etc/runit/runsvdir/default/
|
|
|
|
fi
|
2022-02-07 18:17:40 +01:00
|
|
|
done
|
2022-02-07 03:32:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
2022-02-07 16:56:04 +01:00
|
|
|
if [ "$1" == "config" ]; then
|
|
|
|
function config() { :; }
|
|
|
|
elif [ "$1" == "packages" ]; then
|
|
|
|
function packages() { :; }
|
2022-02-07 03:32:29 +01:00
|
|
|
fi
|
2022-02-07 03:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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=("${@}")
|
2022-02-07 04:01:08 +01:00
|
|
|
#for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do
|
2022-02-07 04:06:47 +01:00
|
|
|
for i in $(seq 0 "$(( ${#input[@]} - 1 ))"); do
|
2022-02-07 04:01:58 +01:00
|
|
|
if [[ "${i}" == "0" ]]; then
|
2022-02-07 03:58:13 +01:00
|
|
|
choices="${input[$i]}"
|
|
|
|
use="${input[$i]}"
|
|
|
|
else
|
|
|
|
choices="${choices}|${input[$i]}"
|
|
|
|
use+=" ${input[$i]}"
|
|
|
|
fi
|
|
|
|
done
|
2022-02-07 04:02:45 +01:00
|
|
|
while input "[${choices}]: " "${input[0]}"; do
|
|
|
|
for i in $(seq 0 "${#input[@]}"); do
|
2022-02-07 03:58:13 +01:00
|
|
|
if [[ "${output}" == "${input[$i]}" ]] || [[ "${output}" == "${input[$i]:0:2}" ]]; then
|
2022-02-07 04:06:47 +01:00
|
|
|
output="${input[$i]}"
|
2022-02-07 03:58:13 +01:00
|
|
|
done=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ -z "${done}" ]]; then
|
|
|
|
echo wronginput "${output}"
|
|
|
|
echo use these: "${use}"
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
}
|
2022-02-07 04:09:57 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-02-07 17:58:29 +01:00
|
|
|
|
|
|
|
readin() {
|
|
|
|
WHICH="$1"
|
2022-02-07 18:14:20 +01:00
|
|
|
header "$WHICH"
|
2022-02-07 18:19:25 +01:00
|
|
|
local -a choice
|
2022-02-08 16:59:29 +01:00
|
|
|
for i in $(find ./etc/${WHICH}/ -type f | sort); do
|
2022-02-07 17:58:29 +01:00
|
|
|
choice+=("$(basename $i)")
|
|
|
|
done
|
|
|
|
if [ "${#choice[@]}" -gt "1" ]; then
|
|
|
|
multiplechoice "${choice[@]}"
|
|
|
|
elif [ "${#choice[@]}" -eq "1" ]; then
|
|
|
|
output=${choice[0]}
|
|
|
|
fi
|
|
|
|
if ! [ "${#choice[@]}" -eq "0" ]; then
|
|
|
|
. ./etc/${WHICH}/$output
|
|
|
|
packages
|
|
|
|
reset packages
|
|
|
|
cp ./etc/${WHICH}/$output $tmp_target
|
|
|
|
fi
|
|
|
|
}
|