forked from AndyTaylorTweet/Pi-Star_Binaries_sbin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pistar-mmdvmhost-module
executable file
·114 lines (114 loc) · 3.27 KB
/
pistar-mmdvmhost-module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#
###############################################################################
# #
# Pi-Star MMDVMHost Module Tool #
# #
# Version 1.0, Code, Design and Development by Andy Taylor (MW0MWZ). #
# #
# Make it simple to turn on/off MMDVMHost modules from the CLI or Cron. #
# #
###############################################################################
#
# Specify some Variables
#
MMDVMCONFIG="/etc/mmdvmhost"
SYSCTL_MMDVMHOST="mmdvmhost"
#
# Check to make sure we are root, and bail out if we are not
#
if [ "$(id -u)" != "0" ]; then
echo -e "You need to be root to run this command...\n"
exit 1
fi
#
# Output some usefull information when no variables are passed
#
if [ -z "$1" ]; then
THIS_SCRIPT=$(basename "$0")
echo "This script needs arguments, the first should be the"
echo "MMDVMHost module you want to turn on/off, and the second"
echo "should be what you want to do with it, either enable or"
echo "dissable."
echo ""
echo "Ex: ${THIS_SCRIPT} D-Star Enable - enable D-Star mode and restart MMDVMHost"
echo "Ex: ${THIS_SCRIPT} D-Star Disable - disable D-Star mode and restart MMDVMHost"
echo ""
echo "Valid module names are D-Star, DMR, YSF, P25 and NXDN"
echo ""
exit 0
fi
#
# Check the first Argument
#
if [ "$1" ]; then
case ${1} in
([Dd]-[Ss][Tt][Aa][Rr])
CUR_STATUS=$(sed -n "/\[D-Star\]/{n;p;}" ${MMDVMCONFIG} | awk -F '=' '{print $2}')
MODULE="D-Star"
;;
([Dd][Mm][Rr])
CUR_STATUS=$(sed -n "/\[DMR\]/{n;p;}" ${MMDVMCONFIG} | awk -F '=' '{print $2}')
MODULE="DMR"
;;
([Yy][Ss][Ff])
CUR_STATUS=$(sed -n "/\[System Fusion\]/{n;p;}" ${MMDVMCONFIG} | awk -F '=' '{print $2}')
MODULE="System Fusion"
;;
([Nn][Xx][Dd][Nn])
CUR_STATUS=$(sed -n "/\[NXDN\]/{n;p;}" ${MMDVMCONFIG} | awk -F '=' '{print $2}')
MODULE="NXDN"
;;
([Pp]25)
CUR_STATUS=$(sed -n "/\[P25\]/{n;p;}" ${MMDVMCONFIG} | awk -F '=' '{print $2}')
MODULE="P25"
;;
*)
# Catch All
echo "Unknown MMDVMHost Module ${1}"
exit 1
;;
esac
fi
#
# Check the second Argument
#
if [ "$2" ]; then
case ${2} in
([Ee][Nn][Aa][Bb][Ll][Ee])
NEW_STATUS="1"
;;
([Dd][Ii][Ss][Aa][Bb][Ll][Ee])
NEW_STATUS="0"
;;
*)
# Catch All
echo "Unknown option ${2}"
exit 1
;;
esac
else
echo "Did you want ${MODULE} to be Enabled or Disabled?"
exit 1
fi
#
# Is this host configured for MMDVMHost
#
! test -r /etc/dstar-radio.dstarrepeater || exit 1
test -r /etc/dstar-radio.mmdvmhost || exit 1
#
# Flight Checks passed... Do some logic
#
if [ "${CUR_STATUS}" == "${NEW_STATUS}" ]; then
# Nothing to do
echo "${MODULE} is already set to ${NEW_STATUS}, nothing to do."
exit 0
else
# Change required, so lets change it...
echo "Setting ${MODULE} to ${NEW_STATUS} and restarting MMDVMHost..."
mount -o remount,rw /
sed -i "/\[${MODULE}\]/{n;s/${CUR_STATUS}/${NEW_STATUS}/}" ${MMDVMCONFIG}
systemctl restart ${SYSCTL_MMDVMHOST}
sleep 2
mount -o remount,ro /
fi