package: improve init script
This commit is contained in:
parent
85b3088c55
commit
6ce434bc9b
@ -7,6 +7,11 @@ PROG=/usr/bin/wtp
|
|||||||
|
|
||||||
|
|
||||||
wtp_conf_header() {
|
wtp_conf_header() {
|
||||||
|
. /etc/openwrt_release
|
||||||
|
model="$(cat /tmp/sysinfo/model)"
|
||||||
|
bootver="$(strings /dev/mtd0 | grep '^U-Boot.*\..*\(.* .*\)$' | head -n1)"
|
||||||
|
[ -z "$bootver" ] && bootver="unknown"
|
||||||
|
linuxver="$(cat /proc/version)"
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
# WTP configuration file
|
# WTP configuration file
|
||||||
|
|
||||||
@ -33,10 +38,10 @@ application: {
|
|||||||
idvendor = 123456;
|
idvendor = 123456;
|
||||||
|
|
||||||
element = (
|
element = (
|
||||||
{ name = "model"; value = "1.0"; },
|
{ name = "model"; value = "${model}"; },
|
||||||
{ name = "serial"; value = "2.0"; },
|
{ name = "serial"; value = "${uuid}"; },
|
||||||
{ name = "id"; value = "3.0"; },
|
{ name = "id"; value = "1.0"; },
|
||||||
{ name = "revision"; value = "4.0"; },
|
{ name = "revision"; value = "1.0"; },
|
||||||
{ name = "macaddress"; type = "interface"; value = "eth0"; }
|
{ name = "macaddress"; type = "interface"; value = "eth0"; }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -48,10 +53,10 @@ application: {
|
|||||||
];
|
];
|
||||||
|
|
||||||
info = (
|
info = (
|
||||||
{ idvendor = 23456; type = "hardware"; value = "abcde"; },
|
{ idvendor = 23456; type = "hardware"; value = "${DISTRIB_TARGET}"; },
|
||||||
{ idvendor = 33457; type = "software"; value = "fghil"; },
|
{ idvendor = 33457; type = "software"; value = "${DISTRIB_DESCRIPTION}"; },
|
||||||
{ idvendor = 43458; type = "boot"; value = "mnopq"; },
|
{ idvendor = 43458; type = "boot"; value = "${bootver}"; },
|
||||||
{ idvendor = 53459; type = "other"; value = "qwert"; }
|
{ idvendor = 53459; type = "other"; value = "${linuxver}"; }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,18 +84,19 @@ wtp_conf_x509() {
|
|||||||
echo
|
echo
|
||||||
echo " dtlspolicy: {"
|
echo " dtlspolicy: {"
|
||||||
echo " cleardatachannel = true;"
|
echo " cleardatachannel = true;"
|
||||||
echo " dtlsdatachannel = true;"
|
echo " dtlsdatachannel = false;"
|
||||||
echo " };"
|
echo " };"
|
||||||
echo
|
echo
|
||||||
echo " type = \"x509\";"
|
|
||||||
echo
|
|
||||||
if [ "$psk" -o "$identity" ]; then
|
if [ "$psk" -o "$identity" ]; then
|
||||||
|
echo " type = \"presharedkey\";"
|
||||||
|
echo
|
||||||
echo " presharedkey: {"
|
echo " presharedkey: {"
|
||||||
echo " identity = \"${identity}\";"
|
echo " identity = \"${identity}\";"
|
||||||
echo " pskkey = \"${psk}\";"
|
echo " pskkey = \"${psk}\";"
|
||||||
echo " };"
|
echo " };"
|
||||||
fi
|
elif [ "$ca" -o "$cert" -o "$key" ]; then
|
||||||
if [ "$ca" -o "$cert" -o "$key" ]; then
|
echo " type = \"x509\";"
|
||||||
|
echo
|
||||||
echo " x509: {"
|
echo " x509: {"
|
||||||
echo " calist = \"${ca}\";"
|
echo " calist = \"${ca}\";"
|
||||||
echo " certificate = \"${cert}\";"
|
echo " certificate = \"${cert}\";"
|
||||||
@ -213,9 +219,6 @@ EOF
|
|||||||
wtp_conf_net() {
|
wtp_conf_net() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
network: {
|
network: {
|
||||||
#binding = "eth1";
|
|
||||||
#listen = "";
|
|
||||||
#port = 0;
|
|
||||||
transport = "udp";
|
transport = "udp";
|
||||||
mtu = 1400;
|
mtu = 1400;
|
||||||
};
|
};
|
||||||
@ -258,6 +261,7 @@ wtp_gen_conf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wtp_uci_conf() {
|
wtp_uci_conf() {
|
||||||
|
[ -e /tmp/etc/wtp.conf ] && return
|
||||||
config_get location "$1" location
|
config_get location "$1" location
|
||||||
config_get country "$1" country
|
config_get country "$1" country
|
||||||
config_get name "$1" name
|
config_get name "$1" name
|
||||||
@ -265,12 +269,18 @@ wtp_uci_conf() {
|
|||||||
config_get cert "$1" cert
|
config_get cert "$1" cert
|
||||||
config_get key "$1" key
|
config_get key "$1" key
|
||||||
config_get host "$1" host
|
config_get host "$1" host
|
||||||
|
config_get uuid "$1" uuid
|
||||||
|
[ -z "$uuid" ] && {
|
||||||
|
uuid="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
|
uci set wtp.@wtp[0].uuid=$uuid
|
||||||
|
uci commit wtp
|
||||||
|
}
|
||||||
mkdir -p /tmp/etc
|
mkdir -p /tmp/etc
|
||||||
wtp_gen_conf > /tmp/etc/wtp.conf
|
wtp_gen_conf > /tmp/etc/wtp.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
|
[ -e /tmp/etc/wtp.conf ] && rm /tmp/etc/wtp.conf
|
||||||
config_load wtp
|
config_load wtp
|
||||||
config_foreach wtp_uci_conf wtp
|
config_foreach wtp_uci_conf wtp
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user