Skip to content

Commit aaf684a

Browse files
committed
add custom-alert command
1 parent 9b62bde commit aaf684a

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

lgsm/modules/alert.sh

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ fn_alert_log() {
2727
} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | tee -a "${alertlog}" > /dev/null 2>&1
2828
}
2929

30+
fn_alert_custom() {
31+
fn_script_log_info "Sending custom alert: Custom alert from ${selfname}."
32+
alertaction="${customalerttitle}"
33+
alertemoji="📢"
34+
alertsound="1"
35+
alertmessage="${customalertmessage}"
36+
# Green
37+
alertcolourhex="#6600CC"
38+
alertcolourdec="6684876"
39+
}
40+
3041
fn_alert_test() {
3142
fn_script_log_info "Sending alert: Testing LinuxGSM Alert. No action to be taken"
3243
alertaction="Tested"
@@ -206,6 +217,8 @@ elif [ "${alert}" == "monitor-session" ]; then
206217
fn_alert_monitor_session
207218
elif [ "${alert}" == "monitor-query" ]; then
208219
fn_alert_monitor_query
220+
elif [ "${alert}" == "custom" ]; then
221+
fn_alert_custom
209222
elif [ "${alert}" == "test" ]; then
210223
fn_alert_test
211224
elif [ "${alert}" == "update" ]; then

lgsm/modules/command_custom_alert.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# LinuxGSM command_custom_alert.sh module
3+
# Author: Daniel Gibbs
4+
# Contributors: http://linuxgsm.com/contrib
5+
# Website: https://linuxgsm.com
6+
# Description: Sends a custom alert.
7+
8+
commandname="CUSTOM-ALERT"
9+
commandaction="Custom Alert"
10+
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
11+
fn_firstcommand_set
12+
13+
check.sh
14+
15+
if [ -n "${userinput2}" ]; then
16+
customalertmessage="${userinput2}"
17+
else
18+
fn_print_header
19+
fn_print_information_nl "Send a custom alert."
20+
echo ""
21+
customalertmessage=$(fn_prompt_message "alert message: ")
22+
fi
23+
24+
# optional: custom alert title
25+
if [ -n "${userinput3}" ]; then
26+
customalerttitle="${userinput3}"
27+
else
28+
customalerttitle="Custom Alert"
29+
fi
30+
31+
info_game.sh
32+
alert="custom"
33+
alert.sh
34+
35+
core_exit.sh

lgsm/modules/core_getopt.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cmd_details=("dt;details" "command_details.sh" "Display server information.")
1919
cmd_postdetails=("pd;postdetails" "command_postdetails.sh" "Post details to termbin.com (removing passwords).")
2020
cmd_backup=("b;backup" "command_backup.sh" "Create backup archives of the server.")
2121
cmd_update_linuxgsm=("ul;update-lgsm;uf;update-modules" "command_update_linuxgsm.sh" "Check and apply any LinuxGSM updates.")
22+
cmd_custom_alert=("ca;custom-alert" "command_custom_alert.sh" "Send a customizable alert.")
2223
cmd_test_alert=("ta;test-alert" "command_test_alert.sh" "Send a test alert.")
2324
cmd_monitor=("m;monitor" "command_monitor.sh" "Check server status and restart if crashed.")
2425
cmd_skeleton=("sk;skeleton" "command_skeleton.sh" "Create a skeleton directory.")
@@ -60,7 +61,7 @@ cmd_dev_clear_modules=("cm;clear-modules" "command_dev_clear_modules.sh" "Delete
6061

6162
### Set specific opt here.
6263

63-
currentopt=("${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" "${cmd_skeleton[@]}")
64+
currentopt=("${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_custom_alert[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" "${cmd_skeleton[@]}")
6465

6566
# Update LinuxGSM.
6667
currentopt+=("${cmd_update_linuxgsm[@]}")

lgsm/modules/core_modules.sh

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ command_postdetails.sh() {
9696
fn_fetch_module
9797
}
9898

99+
command_custom_alert.sh() {
100+
modulefile="${FUNCNAME[0]}"
101+
fn_fetch_module
102+
}
103+
99104
command_test_alert.sh() {
100105
modulefile="${FUNCNAME[0]}"
101106
fn_fetch_module

linuxgsm.sh

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ configdirserver="${configdir}/${gameservername}"
4848
configdirdefault="${lgsmdir}/config-default"
4949
userinput="${1}"
5050
userinput2="${2}"
51+
userinput3="${3}"
5152

5253
## GitHub Branch Select
5354
# Allows for the use of different function files

0 commit comments

Comments
 (0)