From f93e9b818fdcaaaf3f2aaba1bd4ab4503eea17dd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 5 Jul 2014 20:11:41 +0200 Subject: [PATCH] Split gluon-setup-mode package out of gluon-config-mode gluon-config-mode retains the luci frontend, all setup scripts and config is moved to the new package. --- package/gluon-config-mode/Makefile | 6 +-- .../files/etc/config/gluon-config-mode | 3 -- .../etc/hotplug.d/button/50-gluon-config-mode | 29 -------------- .../config-mode/invariant/010-config-ifname | 17 --------- .../controller/gluon-config-mode/index.lua | 8 ++-- .../legacy/010-migrate-configured | 8 ++-- .../lib/lua/luci/controller/admin/index.lua | 12 +++--- package/gluon-setup-mode/Makefile | 38 +++++++++++++++++++ .../files/etc/config/gluon-setup-mode | 3 ++ .../etc/hotplug.d/button/50-gluon-setup-mode | 29 ++++++++++++++ .../files/etc/init.d/gluon-setup-mode} | 36 +++++++++--------- .../files/lib/gluon/setup-mode}/ash-login | 0 .../lib/gluon/setup-mode}/www/cgi-bin/luci | 0 .../lib/gluon/setup-mode}/www/index.html | 0 .../lib/gluon/setup-mode}/www/luci-static | 0 .../invariant/010-setup-mode-migrate | 18 +++++++++ .../setup-mode/invariant/011-setup-ifname | 20 ++++++++++ 17 files changed, 143 insertions(+), 84 deletions(-) delete mode 100644 package/gluon-config-mode/files/etc/config/gluon-config-mode delete mode 100755 package/gluon-config-mode/files/etc/hotplug.d/button/50-gluon-config-mode delete mode 100755 package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/010-config-ifname rename package/gluon-legacy/files/lib/gluon/upgrade/{config-mode => setup-mode}/legacy/010-migrate-configured (59%) create mode 100644 package/gluon-setup-mode/Makefile create mode 100644 package/gluon-setup-mode/files/etc/config/gluon-setup-mode create mode 100755 package/gluon-setup-mode/files/etc/hotplug.d/button/50-gluon-setup-mode rename package/{gluon-config-mode/files/etc/init.d/gluon-config-mode => gluon-setup-mode/files/etc/init.d/gluon-setup-mode} (52%) rename package/{gluon-config-mode/files/lib/gluon/config-mode => gluon-setup-mode/files/lib/gluon/setup-mode}/ash-login (100%) rename package/{gluon-config-mode/files/lib/gluon/config-mode => gluon-setup-mode/files/lib/gluon/setup-mode}/www/cgi-bin/luci (100%) rename package/{gluon-config-mode/files/lib/gluon/config-mode => gluon-setup-mode/files/lib/gluon/setup-mode}/www/index.html (100%) rename package/{gluon-config-mode/files/lib/gluon/config-mode => gluon-setup-mode/files/lib/gluon/setup-mode}/www/luci-static (100%) create mode 100755 package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/010-setup-mode-migrate create mode 100755 package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/011-setup-ifname diff --git a/package/gluon-config-mode/Makefile b/package/gluon-config-mode/Makefile index 2d045b17..5a11faad 100644 --- a/package/gluon-config-mode/Makefile +++ b/package/gluon-config-mode/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-config-mode -PKG_VERSION:=3 +PKG_VERSION:=4 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) @@ -13,8 +13,8 @@ include $(GLUONDIR)/include/package.mk define Package/gluon-config-mode SECTION:=gluon CATEGORY:=Gluon - TITLE:=Luci based config mode for user friendly setup of new meshnodes - DEPENDS:=+gluon-luci-core +gluon-lock-password +gluon-node-info +gluon-simple-tc +uhttpd +dnsmasq +ip + TITLE:=Luci based config mode for user friendly setup of new mesh nodes + DEPENDS:=+gluon-luci-core +gluon-setup-mode +gluon-lock-password +gluon-node-info +gluon-simple-tc endef define Package/gluon-config-mode/description diff --git a/package/gluon-config-mode/files/etc/config/gluon-config-mode b/package/gluon-config-mode/files/etc/config/gluon-config-mode deleted file mode 100644 index c2d2be2f..00000000 --- a/package/gluon-config-mode/files/etc/config/gluon-config-mode +++ /dev/null @@ -1,3 +0,0 @@ -config wizard - option enabled '0' - option configured '0' diff --git a/package/gluon-config-mode/files/etc/hotplug.d/button/50-gluon-config-mode b/package/gluon-config-mode/files/etc/hotplug.d/button/50-gluon-config-mode deleted file mode 100755 index 7648cd69..00000000 --- a/package/gluon-config-mode/files/etc/hotplug.d/button/50-gluon-config-mode +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - - -wait=3 - - -wait_config_mode() { - sleep $wait - uci set 'gluon-config-mode.@wizard[0].enabled=1' - uci commit gluon-config-mode - reboot -} - - -if [ "$BUTTON" = wps -o "$BUTTON" = reset ]; then - case "$ACTION" in - pressed) - wait_config_mode & - PID=$! - echo $PID > /tmp/.wait_config_mode - ;; - released) - if [ -r /tmp/.wait_config_mode ]; then - kill $(cat /tmp/.wait_config_mode) - rm /tmp/.wait_config_mode - fi - ;; - esac -fi diff --git a/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/010-config-ifname b/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/010-config-ifname deleted file mode 100755 index ce54a9b3..00000000 --- a/package/gluon-config-mode/files/lib/gluon/upgrade/config-mode/invariant/010-config-ifname +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -. /lib/gluon/functions/sysconfig.sh -. /lib/ar71xx.sh - - -sysconfig_isset config_ifname && exit 0 - - -case "$(ar71xx_board_name)" in - nanostation-m) - sysconfig_set config_ifname "$(sysconfig wan_ifname || sysconfig lan_ifname)" - ;; - *) - sysconfig_set config_ifname "$(sysconfig lan_ifname || sysconfig wan_ifname)" - ;; -esac diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/gluon-config-mode/index.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/gluon-config-mode/index.lua index d8b21b88..def9d401 100644 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/gluon-config-mode/index.lua +++ b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/gluon-config-mode/index.lua @@ -21,7 +21,7 @@ local meshvpn_name = "mesh_vpn" function index() local uci_state = luci.model.uci.cursor_state() - if uci_state:get_first("gluon-config-mode", "wizard", "running", "0") == "1" then + if uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1" then local root = node() if not root.target then root.target = alias("gluon-config-mode") @@ -57,9 +57,9 @@ function action_reboot() pubkey = configmode.get_fastd_pubkey(meshvpn_name) end - uci:set("gluon-config-mode", uci:get_first("gluon-config-mode", "wizard"), "configured", "1") - uci:save("gluon-config-mode") - uci:commit("gluon-config-mode") + uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", "1") + uci:save("gluon-setup-mode") + uci:commit("gluon-setup-mode") local hostname = uci:get_first("system", "system", "hostname") diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured b/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured similarity index 59% rename from package/gluon-legacy/files/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured rename to package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured index 18bdaf19..f4a59570 100755 --- a/package/gluon-legacy/files/lib/gluon/upgrade/config-mode/legacy/010-migrate-configured +++ b/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured @@ -9,11 +9,11 @@ local c = uci.cursor() for _, config in ipairs(site.legacy.config_mode_configs) do local old = c:get_first(config, 'wizard', 'configured') if old == '1' then - local wizard = c:get_first('gluon-config-mode', 'wizard') - c:set('gluon-config-mode', wizard, 'configured', '1') + local setup_mode = c:get_first('gluon-setup-mode', 'setup_mode') + c:set('gluon-setup-mode', setup_mode, 'configured', '1') - c:save('gluon-config-mode') - c:commit('gluon-config-mode') + c:save('gluon-setup-mode') + c:commit('gluon-setup-mode') break end diff --git a/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/index.lua b/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/index.lua index 2ff5281c..4d9883ca 100644 --- a/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/index.lua +++ b/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/index.lua @@ -17,10 +17,10 @@ module("luci.controller.admin.index", package.seeall) function index() local uci_state = luci.model.uci.cursor_state() - local configmode = uci_state:get_first("gluon-config-mode", "wizard", "running", "0") == "1" + local setup_mode = uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1" - -- Disable gluon-luci-admin when configmode is not enabled - if not configmode then + -- Disable gluon-luci-admin when setup mode is not enabled + if not setup_mode then return end @@ -32,8 +32,8 @@ function index() local page = entry({"admin"}, alias("admin", "index"), "Expert Mode", 10) page.sysauth = "root" - if configmode then - -- force root to be logged in when running in configmode + if setup_mode then + -- force root to be logged in when running in setup_mode page.sysauth_authenticator = function() return "root" end else page.sysauth_authenticator = "htmlauth" @@ -42,7 +42,7 @@ function index() entry({"admin", "index"}, cbi("admin/remote"), "Remotezugriff", 1).ignoreindex = true - if not configmode then + if not setup_mode then entry({"admin", "logout"}, call("action_logout"), "Logout") end end diff --git a/package/gluon-setup-mode/Makefile b/package/gluon-setup-mode/Makefile new file mode 100644 index 00000000..e8d4fe52 --- /dev/null +++ b/package/gluon-setup-mode/Makefile @@ -0,0 +1,38 @@ +# Copyright (C) 2012 Nils Schneider +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-setup-mode +PKG_VERSION:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(GLUONDIR)/include/package.mk + +define Package/gluon-setup-mode + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=Setup mode + DEPENDS:=+uhttpd +dnsmasq +ip +endef + +define Package/gluon-setup-mode/description + Offline mode to perform basic setup in a secure manner. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/gluon-setup-mode/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,gluon-setup-mode)) diff --git a/package/gluon-setup-mode/files/etc/config/gluon-setup-mode b/package/gluon-setup-mode/files/etc/config/gluon-setup-mode new file mode 100644 index 00000000..c652728f --- /dev/null +++ b/package/gluon-setup-mode/files/etc/config/gluon-setup-mode @@ -0,0 +1,3 @@ +config setup_mode + option enabled '0' + option configured '0' diff --git a/package/gluon-setup-mode/files/etc/hotplug.d/button/50-gluon-setup-mode b/package/gluon-setup-mode/files/etc/hotplug.d/button/50-gluon-setup-mode new file mode 100755 index 00000000..9a1ccf2f --- /dev/null +++ b/package/gluon-setup-mode/files/etc/hotplug.d/button/50-gluon-setup-mode @@ -0,0 +1,29 @@ +#!/bin/sh + + +wait=3 + + +wait_setup_mode() { + sleep $wait + uci set 'gluon-setup-mode.@setup_mode[0].enabled=1' + uci commit gluon-setup-mode + reboot +} + + +if [ "$BUTTON" = wps -o "$BUTTON" = reset ]; then + case "$ACTION" in + pressed) + wait_setup_mode & + PID=$! + echo $PID > /tmp/.wait_setup_mode + ;; + released) + if [ -r /tmp/.wait_setup_mode ]; then + kill $(cat /tmp/.wait_setup_mode) + rm /tmp/.wait_setup_mode + fi + ;; + esac +fi diff --git a/package/gluon-config-mode/files/etc/init.d/gluon-config-mode b/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode similarity index 52% rename from package/gluon-config-mode/files/etc/init.d/gluon-config-mode rename to package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode index e613f7b1..6abff8eb 100755 --- a/package/gluon-config-mode/files/etc/init.d/gluon-config-mode +++ b/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode @@ -3,10 +3,10 @@ START=12 -CONFIG_MODE_ADDR=192.168.1.1 -CONFIG_MODE_NETMASK=255.255.255.0 +SETUP_MODE_ADDR=192.168.1.1 +SETUP_MODE_NETMASK=255.255.255.0 -CONFIG_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254 +SETUP_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254 delete_interface() { @@ -25,7 +25,7 @@ check_enable() { setup_network() { ( - export UCI_CONFIG_DIR=/var/gluon/config-mode/config + export UCI_CONFIG_DIR=/var/gluon/setup-mode/config mkdir -p "$UCI_CONFIG_DIR" @@ -34,12 +34,12 @@ setup_network() { config_load network config_foreach delete_interface interface - uci_add network interface config - uci_set network config ifname "$(sysconfig config_ifname)" - uci_set network config type 'bridge' - uci_set network config proto 'static' - uci_set network config ipaddr "$CONFIG_MODE_ADDR" - uci_set network config netmask "$CONFIG_MODE_NETMASK" + uci_add network interface setup + uci_set network setup ifname "$(sysconfig setup_ifname)" + uci_set network setup type 'bridge' + uci_set network setup proto 'static' + uci_set network setup ipaddr "$SETUP_MODE_ADDR" + uci_set network setup netmask "$SETUP_MODE_NETMASK" uci_commit network @@ -58,22 +58,22 @@ start() { . /lib/gluon/functions/sysconfig.sh enable=0 - config_load gluon-config-mode - config_foreach check_enable wizard + config_load gluon-setup-mode + config_foreach check_enable setup_mode if [ "$enable" = '1' ]; then - lua -luci -e 'require "luci.model.uci"; uci_state=luci.model.uci.cursor_state(); uci_state:section("gluon-config-mode", "wizard", nil, { running = "1" }); uci_state:save("gluon-config-mode")' - uci set 'gluon-config-mode.@wizard[0].enabled=0' - uci commit gluon-config-mode + lua -luci -e 'require "luci.model.uci"; uci_state=luci.model.uci.cursor_state(); uci_state:section("gluon-setup-mode", "setup_mode", nil, { running = "1" }); uci_state:save("gluon-setup-mode")' + uci set 'gluon-setup-mode.@setup_mode[0].enabled=0' + uci commit gluon-setup-mode setup_network - /usr/sbin/telnetd -l /lib/gluon/config-mode/ash-login + /usr/sbin/telnetd -l /lib/gluon/setup-mode/ash-login /etc/init.d/dropbear start - /usr/sbin/uhttpd -h /lib/gluon/config-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80 + /usr/sbin/uhttpd -h /lib/gluon/setup-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80 - /usr/sbin/dnsmasq -p 0 -F $CONFIG_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router + /usr/sbin/dnsmasq -p 0 -F $SETUP_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router /etc/init.d/led start diff --git a/package/gluon-config-mode/files/lib/gluon/config-mode/ash-login b/package/gluon-setup-mode/files/lib/gluon/setup-mode/ash-login similarity index 100% rename from package/gluon-config-mode/files/lib/gluon/config-mode/ash-login rename to package/gluon-setup-mode/files/lib/gluon/setup-mode/ash-login diff --git a/package/gluon-config-mode/files/lib/gluon/config-mode/www/cgi-bin/luci b/package/gluon-setup-mode/files/lib/gluon/setup-mode/www/cgi-bin/luci similarity index 100% rename from package/gluon-config-mode/files/lib/gluon/config-mode/www/cgi-bin/luci rename to package/gluon-setup-mode/files/lib/gluon/setup-mode/www/cgi-bin/luci diff --git a/package/gluon-config-mode/files/lib/gluon/config-mode/www/index.html b/package/gluon-setup-mode/files/lib/gluon/setup-mode/www/index.html similarity index 100% rename from package/gluon-config-mode/files/lib/gluon/config-mode/www/index.html rename to package/gluon-setup-mode/files/lib/gluon/setup-mode/www/index.html diff --git a/package/gluon-config-mode/files/lib/gluon/config-mode/www/luci-static b/package/gluon-setup-mode/files/lib/gluon/setup-mode/www/luci-static similarity index 100% rename from package/gluon-config-mode/files/lib/gluon/config-mode/www/luci-static rename to package/gluon-setup-mode/files/lib/gluon/setup-mode/www/luci-static diff --git a/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/010-setup-mode-migrate b/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/010-setup-mode-migrate new file mode 100755 index 00000000..9d3b9b0a --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/010-setup-mode-migrate @@ -0,0 +1,18 @@ +#!/usr/bin/lua + +local site = require 'gluon.site_config' +local uci = require 'luci.model.uci' + +local c = uci.cursor() + + +local old = c:get_first('gluon-config-mode', 'wizard', 'configured') +if old == '1' then + local setup_mode = c:get_first('gluon-setup-mode', 'setup_mode') + c:set('gluon-setup-mode', setup_mode, 'configured', '1') + + c:save('gluon-setup-mode') + c:commit('gluon-setup-mode') +end + +os.remove('/etc/config/gluon-config-mode') diff --git a/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/011-setup-ifname b/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/011-setup-ifname new file mode 100755 index 00000000..f9f33a70 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/upgrade/setup-mode/invariant/011-setup-ifname @@ -0,0 +1,20 @@ +#!/bin/sh + +. /lib/gluon/functions/sysconfig.sh +. /lib/gluon/functions/model.sh + + +sysconfig_isset setup_ifname && exit 0 + + +case "$(get_board_name)" in + nanostation-m) + sysconfig_set setup_ifname "$(sysconfig config_ifname || sysconfig wan_ifname || sysconfig lan_ifname)" + ;; + *) + sysconfig_set setup_ifname "$(sysconfig config_ifname || sysconfig lan_ifname || sysconfig wan_ifname)" + ;; +esac + +# Remove the old sysconfig setting +sysconfig_unset config_ifname