From 2454c8abb7938b768b0ac0c8eaa55f44d416dac2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2014 08:27:51 +0100 Subject: [PATCH] Add gluon-legacy package with legacy upgrade scripts --- .../files/etc/config/gluon-config-mode | 2 +- .../invariant/001-migrate-uci-config | 6 --- .../files/etc/uci-defaults/zzz-gluon-upgrade | 17 ++++++++- package/gluon-legacy/Makefile | 36 ++++++++++++++++++ .../generate/lib/gluon/legacy/legacy-upgrade | 12 ++++++ .../lib/gluon/legacy/legacy-upgrade-late | 3 ++ .../config-mode/legacy/010-migrate-configured | 14 +++++++ .../gluon/upgrade/core/legacy/001-sysconfig | 37 +++++++++++++++++++ .../upgrade/core/legacy/011-gluon-network | 22 +++++++++++ .../gluon/upgrade/core/legacy/020-wireless | 19 ++++++++++ .../lock-password/legacy/010-lock-password | 13 +++++++ .../upgrade/mesh-batman-adv/legacy/010-mesh | 18 +++++++++ .../legacy/010-reset-fastd-config | 22 +++++++++++ .../upgrade/simple-tc/legacy/010-migrate-tc | 19 ++++++++++ package/gluon-mesh-vpn-fastd/fastd.pl | 3 -- 15 files changed, 232 insertions(+), 11 deletions(-) delete mode 100755 package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/001-migrate-uci-config create mode 100644 package/gluon-legacy/Makefile create mode 100755 package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade create mode 100755 package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade-late create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/001-sysconfig create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/011-gluon-network create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/020-wireless create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/lock-password/legacy/010-lock-password create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/mesh-batman-adv/legacy/010-mesh create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config create mode 100755 package/gluon-legacy/generate/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc diff --git a/package/gluon-config-mode/files/etc/config/gluon-config-mode b/package/gluon-config-mode/files/etc/config/gluon-config-mode index ff348bb8..c2d2be2f 100644 --- a/package/gluon-config-mode/files/etc/config/gluon-config-mode +++ b/package/gluon-config-mode/files/etc/config/gluon-config-mode @@ -1,3 +1,3 @@ config wizard - option enabled '1' + option enabled '0' option configured '0' diff --git a/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/001-migrate-uci-config b/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/001-migrate-uci-config deleted file mode 100755 index 657012da..00000000 --- a/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/001-migrate-uci-config +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -OLD_CFG=/etc/config/config_mode -NEW_CFG=/etc/config/gluon-config-mode - -[ -f $OLD_CFG ] && mv $OLD_CFG $NEW_CFG diff --git a/package/gluon-core/files/etc/uci-defaults/zzz-gluon-upgrade b/package/gluon-core/files/etc/uci-defaults/zzz-gluon-upgrade index baf59e8b..ccbbf95e 100755 --- a/package/gluon-core/files/etc/uci-defaults/zzz-gluon-upgrade +++ b/package/gluon-core/files/etc/uci-defaults/zzz-gluon-upgrade @@ -5,6 +5,13 @@ UPGRADE_DIR=/lib/gluon/upgrade VERSION_DIR=/lib/gluon/version +if [ -x /lib/gluon/legacy/legacy-upgrade ] && /lib/gluon/legacy/legacy-upgrade; then + HAS_LEGACY=1 +else + HAS_LEGACY= +fi + + mkdir -p "$VERSION_DIR" @@ -33,7 +40,11 @@ do_component() { local oldversion="$(oldversion_of "$component")" if [ -z "$oldversion" ]; then - do_dir initial + if [ "$HAS_LEGACY" ]; then + do_dir legacy + else + do_dir initial + fi else local v @@ -62,3 +73,7 @@ for component in *; do [ "$component" != 'core' ] || continue do_component "$component" done + +if [ "$HAS_LEGACY" ]; then + /lib/gluon/legacy/legacy-upgrade-late +fi diff --git a/package/gluon-legacy/Makefile b/package/gluon-legacy/Makefile new file mode 100644 index 00000000..e354f376 --- /dev/null +++ b/package/gluon-legacy/Makefile @@ -0,0 +1,36 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-legacy +PKG_VERSION:=1 +PKG_RELEASE:=1.$(GLUON_CONFIG_VERSION) + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/gluon-legacy + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=Legacy update scripts + DEPENDS:=+gluon-legacy +endef + +define Package/gluon-legacy/description + Gluon community wifi mesh firmware framework: legacy update scripts +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/gluon-legacy/install + $(GLUON_GENERATE) ./generate/* $(1)/ +endef + +$(eval $(call BuildPackage,gluon-legacy)) diff --git a/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade b/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade new file mode 100755 index 00000000..9f8ec1fb --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade @@ -0,0 +1,12 @@ +#!/bin/sh + +RET=1 + +for file in @legacy.version_files@; do + if [ -e "$file" ]; then + rm "$file" + RET=0 + fi +done + +exit $RET diff --git a/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade-late b/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade-late new file mode 100755 index 00000000..54419cb4 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/legacy/legacy-upgrade-late @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -f @legacy.old_files@ diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured b/package/gluon-legacy/generate/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured new file mode 100755 index 00000000..23c81fe0 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured @@ -0,0 +1,14 @@ +#!/bin/sh + + +. /lib/functions.sh + + +for config in @legacy.config_mode_configs@; do + if [ "$(uci -q get "$config".configured)" = '1' ]; then + uci_set gluon-config-mode '@wizard[0]' 'configured' '1' + uci_commit gluon-config-mode + + break + fi +done diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/001-sysconfig b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/001-sysconfig new file mode 100755 index 00000000..16964723 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/001-sysconfig @@ -0,0 +1,37 @@ +#!/bin/sh + +. /lib/gluon/functions/sysconfig.sh +. /lib/ar71xx.sh + + +get_primary_mac() { + case "$(ar71xx_board_name)" in + tl-wdr3600|tl-wdr4300) + cat /sys/class/ieee80211/phy1/macaddress + ;; + *) + cat /sys/class/ieee80211/phy0/macaddress + ;; + esac +} + +iface_exists() { + local name="$1" + ip link show dev "${name//.*/}" >/dev/null 2>&1 +} + +remove_bat0() { + sed -r -e 's/(^| )bat0( |$)/ /g' -e 's/^ | $//g' +} + +mesh_ifname="$(uci get 'network.@legacy.mesh_ifname@.ifname' | remove_bat0)" +wan_ifname="$(uci get network.wan.ifname | remove_bat0)" + +if [ -n "$wan_ifname" ] && iface_exists "$wan_ifname"; then + [ -z "$mesh_ifname" ] || sysconfig_set lan_ifname "$mesh_ifname" + sysconfig_set wan_ifname "$wan_ifname" +else + sysconfig_set wan_ifname "$mesh_ifname" +fi + +sysconfig_set primary_mac "$(get_primary_mac)" diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/011-gluon-network b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/011-gluon-network new file mode 100755 index 00000000..dd9c6ca5 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/011-gluon-network @@ -0,0 +1,22 @@ +#!/bin/sh + + +. /lib/functions.sh +. /lib/gluon/functions/sysconfig.sh + + +case "$(ar71xx_board_name)" in +tl-wr1043nd|\ +tl-wdr3600|\ +tl-wdr4300) # fix up duplicate mac addresses + local mainaddr=$(sysconfig primary_mac) + local oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS" + local b2mask=0x02 + + local wanaddr=$(printf "%02x:%s:%s:%02x:%s:%02x" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $(( (0x$6 + 1) % 0x100 )) ) + + uci_set network wan macaddr "$wanaddr" + ;; +esac + +uci_commit network diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/020-wireless b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/020-wireless new file mode 100755 index 00000000..729dc72b --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/core/legacy/020-wireless @@ -0,0 +1,19 @@ +#!/bin/sh + +. /lib/functions.sh + +config_load wireless + +delete_legacy_iface() { + local iface="$1" + + for wifi in @legacy.wifi_names@; do + if [ "$wifi" = "$iface" ]; then + uci_remove wireless "$iface" + break + fi + done +} + +config_foreach delete_legacy_iface 'wifi-iface' +uci_commit wireless diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/lock-password/legacy/010-lock-password b/package/gluon-legacy/generate/lib/gluon/upgrade/lock-password/legacy/010-lock-password new file mode 100755 index 00000000..ce6d59ac --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/lock-password/legacy/010-lock-password @@ -0,0 +1,13 @@ +#!/bin/sh + + +has_root_pwd() { + local pwd=$([ -f "$1" ] && cat "$1") + pwd="${pwd#*root:}" + pwd="${pwd%%:*}" + + test -n "${pwd#[\!x]}" +} + + +has_root_pwd /etc/passwd || has_root_pwd /etc/shadow || passwd -l root diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-batman-adv/legacy/010-mesh b/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-batman-adv/legacy/010-mesh new file mode 100755 index 00000000..dcd12013 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-batman-adv/legacy/010-mesh @@ -0,0 +1,18 @@ +#!/bin/sh + + +. /lib/functions.sh +. /lib/gluon/functions/sysconfig.sh + + +uci_rename network '@legacy.mesh_ifname@' 'client' + +if [ "$(uci_get network client proto)" = 'none' ]; then + uci_remove network client auto + uci_remove network client accept_ra + + uci_set network client proto 'dhcpv6' + uci_set network client reqprefix 'no' +fi + +uci_commit network diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config b/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config new file mode 100755 index 00000000..58d4acf9 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config @@ -0,0 +1,22 @@ +#!/bin/sh + +. /lib/functions.sh + + +SECRET= + + +for config in @legacy.fastd_configs@; do + if [ -z "$SECRET" ]; then + SECRET="$(uci_get fastd "$config" secret)" + fi + + uci_remove fastd "$config" +done + +if [ -n "$SECRET" ]; then + uci_add fastd fastd 'mesh_vpn' + uci_set fastd 'mesh_vpn' 'secret' "$SECRET" +fi + +uci_commit fastd diff --git a/package/gluon-legacy/generate/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc b/package/gluon-legacy/generate/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc new file mode 100755 index 00000000..d75060e7 --- /dev/null +++ b/package/gluon-legacy/generate/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc @@ -0,0 +1,19 @@ +#!/bin/sh + +. /lib/functions.sh + + +for config in @legacy.tc_configs@; do + if uci -q get "$config" >/dev/null; then + uci_add gluon-simple-tc interface 'mesh_vpn' + uci_set gluon-simple-tc 'mesh_vpn' ifname 'mesh-vpn' + + uci_set gluon-simple-tc 'mesh_vpn' enabled "$(uci get "$config".enabled)" + uci_set gluon-simple-tc 'mesh_vpn' limit_ingress "$(uci get "$config".downstream)" + uci_set gluon-simple-tc 'mesh_vpn' limit_egress "$(uci get "$config".upstream)" + + uci_commit gluon-simple-tc + + break + fi +done diff --git a/package/gluon-mesh-vpn-fastd/fastd.pl b/package/gluon-mesh-vpn-fastd/fastd.pl index fbd1a030..cc79f0a7 100644 --- a/package/gluon-mesh-vpn-fastd/fastd.pl +++ b/package/gluon-mesh-vpn-fastd/fastd.pl @@ -25,9 +25,6 @@ add_user gluon-fastd 800 uci_add fastd fastd mesh_vpn -uci_remove fastd mesh_vpn config -uci_remove fastd mesh_vpn config_peer_dir - uci_set fastd mesh_vpn user 'gluon-fastd' uci_set fastd mesh_vpn syslog_level 'verbose' uci_set fastd mesh_vpn interface 'mesh-vpn'