forked from fabianishere/udm-iptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinst
executable file
·104 lines (82 loc) · 2.7 KB
/
postinst
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
#!/bin/sh -e
# Copyright (C) 2022 Fabian Mastenbroek.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# Source debconf library.
. /usr/share/debconf/confmodule
# Substitute a debconf answer into a configuration file with the syntax of
# /etc/udm-iptv.conf
replace_conf() {
file="$1"
setting="$2"
value="$3";
if grep -q "^${setting}=" "$file"; then
value="$(echo "$value" | sed -e 's,[\@],\\&,g')"
sed -i -re "s@^(${setting}=).*@\1\"${value}\"@" "$file"
else
echo >> "$file"
echo "${setting}=\"${value}\"" >> "$file"
fi
}
# Remove a debconf answer from a configuration file with the syntax of
# /etc/udm-iptv.conf
remove_conf() {
file="$1"
setting="$2"
if grep -q "^${setting}=" "$file"; then
sed -i -re "/^${setting}=.*$/d" "$file"
fi
}
CONFIGFILE=/etc/udm-iptv.conf
tmpconf=$(mktemp -t iptv.XXXX.conf)
# Copy original configuration into temp file
cp "$CONFIGFILE" "$tmpconf" || true
db_get udm-iptv/wan-interface
replace_conf "$tmpconf" "IPTV_WAN_INTERFACE" "$RET"
db_get udm-iptv/wan-vlan
replace_conf "$tmpconf" "IPTV_WAN_VLAN" "$RET"
db_get udm-iptv/wan-vlan-interface
replace_conf "$tmpconf" "IPTV_WAN_VLAN_INTERFACE" "$RET"
db_get udm-iptv/wan-vlan-mac
if [ -n "$RET" ]; then
replace_conf "$tmpconf" "IPTV_WAN_VLAN_MAC" "$RET"
else
remove_conf "$tmpconf" "IPTV_WAN_VLAN_MAC"
fi
db_get udm-iptv/wan-ranges
replace_conf "$tmpconf" "IPTV_WAN_RANGES" "$(echo "$RET" | tr ',' ' ')"
db_get udm-iptv/wan-dhcp
if [ "$RET" = "false" ]; then
replace_conf "$tmpconf" "IPTV_WAN_DHCP" "$RET"
else
remove_conf "$tmpconf" "IPTV_WAN_DHCP"
fi
db_get udm-iptv/wan-dhcp-options
replace_conf "$tmpconf" "IPTV_WAN_DHCP_OPTIONS" "$RET"
db_get udm-iptv/wan-static-ip
if [ -n "$RET" ]; then
replace_conf "$tmpconf" "IPTV_WAN_STATIC_IP" "$RET"
else
remove_conf "$tmpconf" "IPTV_WAN_STATIC_IP"
fi
db_get udm-iptv/lan-interfaces
replace_conf "$tmpconf" "IPTV_LAN_INTERFACES" "$(echo "$RET" | tr ',' ' ')"
db_get udm-iptv/igmpproxy-program
replace_conf "$tmpconf" "IPTV_IGMPPROXY_PROGRAM" "$RET"
db_get udm-iptv/igmpproxy-quickleave
value="false"
if [ "$RET" = "false" ]; then
value="true"
fi
replace_conf "$tmpconf" "IPTV_IGMPPROXY_DISABLE_QUICKLEAVE" "$value"
db_get udm-iptv/igmpproxy-debug
replace_conf "$tmpconf" "IPTV_IGMPPROXY_DEBUG" "$RET"
db_get udm-iptv/igmpproxy-igmp-version
replace_conf "$tmpconf" "IPTV_IGMPPROXY_IGMP_VERSION" "$RET"
# Replace file with updated configuration
mv "$tmpconf" "$(readlink -f "$CONFIGFILE")"
#DEBHELPER#
exit 0