New flag, -D, to delete servers.
This commit is contained in:
parent
f8c2148571
commit
7c2a9dbf2c
58
tojam
58
tojam
@ -22,6 +22,7 @@ help() {
|
|||||||
# Array of command line arguments
|
# Array of command line arguments
|
||||||
declare -A command=(
|
declare -A command=(
|
||||||
[c]="Configure ${0##*/}."
|
[c]="Configure ${0##*/}."
|
||||||
|
[D]="Delete a server."
|
||||||
[h]="This help screen."
|
[h]="This help screen."
|
||||||
[T]="Dedication."
|
[T]="Dedication."
|
||||||
)
|
)
|
||||||
@ -72,24 +73,35 @@ add_server() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
settings() {
|
delete_server() {
|
||||||
echo "Settings coming soon"
|
# Get servers into an array.
|
||||||
|
mapfile -t lines < "${config}/servers.conf"
|
||||||
|
for i in "${lines[@]}" ; do
|
||||||
|
j="${i#\[}"
|
||||||
|
j="${j/\]=\"/: }"
|
||||||
|
j="${j%\"}"
|
||||||
|
menuList+=("$i" "${j}")
|
||||||
|
done
|
||||||
|
server="$(dialog --clear \
|
||||||
|
--backtitle "Tojam" \
|
||||||
|
--no-tags \
|
||||||
|
--ok-label "Delete" \
|
||||||
|
--menu "Select a Ninjam server to be deleted" -1 -1 -1 "${menuList[@]}" --stdout)"
|
||||||
|
menuCode=$?
|
||||||
|
if [ ${menuCode} -eq 1 -o ${menuCode} -eq 255 ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
tmpFile="$(mktemp -t XXXXXX)"
|
||||||
|
grep -vF "$server" "${config}/servers.conf" > "${tmpFile}" || exit 3
|
||||||
|
mv "${tmpFile}" "${config}/servers.conf" || exit 4
|
||||||
|
dialog --msgbox "Server deleted." -1 -1
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Convert the keys of the associative array to a format usable by getopts
|
settings() {
|
||||||
args="${!command[*]}"
|
echo "Settings coming soon"
|
||||||
args="${args//[[:space:]]/}"
|
}
|
||||||
while getopts "${args}" i ; do
|
|
||||||
case "$i" in
|
|
||||||
c) echo "Coming soon" ;;
|
|
||||||
h) help ;;
|
|
||||||
T)
|
|
||||||
echo "For Tony, because he's awesome!"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# Configuration stuff
|
# Configuration stuff
|
||||||
@ -118,6 +130,22 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Convert the keys of the associative array to a format usable by getopts
|
||||||
|
args="${!command[*]}"
|
||||||
|
args="${args//[[:space:]]/}"
|
||||||
|
while getopts "${args}" i ; do
|
||||||
|
case "$i" in
|
||||||
|
c) echo "Coming soon" ;;
|
||||||
|
D) delete_server ;;
|
||||||
|
h) help ;;
|
||||||
|
T)
|
||||||
|
echo "For Tony, because he's awesome!"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
declare -A servers=(
|
declare -A servers=(
|
||||||
[Ninjamer 1]="ninjamer.com"
|
[Ninjamer 1]="ninjamer.com"
|
||||||
[Ninjamer 2]="ninjamer.com:2050"
|
[Ninjamer 2]="ninjamer.com:2050"
|
||||||
|
Loading…
Reference in New Issue
Block a user