package: improve init script

This commit is contained in:
Daniel Golle 2016-08-23 17:10:44 +02:00
parent 85b3088c55
commit 6ce434bc9b
1 changed files with 27 additions and 17 deletions

View File

@ -7,6 +7,11 @@ PROG=/usr/bin/wtp
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
# WTP configuration file
@ -33,10 +38,10 @@ application: {
idvendor = 123456;
element = (
{ name = "model"; value = "1.0"; },
{ name = "serial"; value = "2.0"; },
{ name = "id"; value = "3.0"; },
{ name = "revision"; value = "4.0"; },
{ name = "model"; value = "${model}"; },
{ name = "serial"; value = "${uuid}"; },
{ name = "id"; value = "1.0"; },
{ name = "revision"; value = "1.0"; },
{ name = "macaddress"; type = "interface"; value = "eth0"; }
);
};
@ -48,10 +53,10 @@ application: {
];
info = (
{ idvendor = 23456; type = "hardware"; value = "abcde"; },
{ idvendor = 33457; type = "software"; value = "fghil"; },
{ idvendor = 43458; type = "boot"; value = "mnopq"; },
{ idvendor = 53459; type = "other"; value = "qwert"; }
{ idvendor = 23456; type = "hardware"; value = "${DISTRIB_TARGET}"; },
{ idvendor = 33457; type = "software"; value = "${DISTRIB_DESCRIPTION}"; },
{ idvendor = 43458; type = "boot"; value = "${bootver}"; },
{ idvendor = 53459; type = "other"; value = "${linuxver}"; }
);
};
@ -79,18 +84,19 @@ wtp_conf_x509() {
echo
echo " dtlspolicy: {"
echo " cleardatachannel = true;"
echo " dtlsdatachannel = true;"
echo " dtlsdatachannel = false;"
echo " };"
echo
echo " type = \"x509\";"
echo
if [ "$psk" -o "$identity" ]; then
echo " type = \"presharedkey\";"
echo
echo " presharedkey: {"
echo " identity = \"${identity}\";"
echo " pskkey = \"${psk}\";"
echo " };"
fi
if [ "$ca" -o "$cert" -o "$key" ]; then
elif [ "$ca" -o "$cert" -o "$key" ]; then
echo " type = \"x509\";"
echo
echo " x509: {"
echo " calist = \"${ca}\";"
echo " certificate = \"${cert}\";"
@ -213,9 +219,6 @@ EOF
wtp_conf_net() {
cat <<EOF
network: {
#binding = "eth1";
#listen = "";
#port = 0;
transport = "udp";
mtu = 1400;
};
@ -258,6 +261,7 @@ wtp_gen_conf() {
}
wtp_uci_conf() {
[ -e /tmp/etc/wtp.conf ] && return
config_get location "$1" location
config_get country "$1" country
config_get name "$1" name
@ -265,12 +269,18 @@ wtp_uci_conf() {
config_get cert "$1" cert
config_get key "$1" key
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
wtp_gen_conf > /tmp/etc/wtp.conf
}
start_service() {
[ -e /tmp/etc/wtp.conf ] && rm /tmp/etc/wtp.conf
config_load wtp
config_foreach wtp_uci_conf wtp