From ce11cd8c1d6c0e6037e3d8bb39ea13fb7650a169 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Tue, 14 May 2013 15:09:56 +0200 Subject: [PATCH] post-install/post-remove are now reasonably complete. --- Makefile | 16 ++++++++++-- add-fw-net.sh | 30 ----------------------- post-install.sh | 43 ++++++++++++++++++++++++++++----- pre-remove.sh => post-remove.sh | 13 ++++++++++ src/TODO | 3 --- 5 files changed, 64 insertions(+), 41 deletions(-) delete mode 100755 add-fw-net.sh rename pre-remove.sh => post-remove.sh (50%) diff --git a/Makefile b/Makefile index 81939d9..92e513a 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,16 @@ ############################################## include $(TOPDIR)/rules.mk +#NOTE: this hack is required to get files included inside a define block, see this link: +#http://stackoverflow.com/questions/3524726/how-to-make-eval-shell-work-in-gnu-make +#The '¤' character must not appear in included scripts. +define newline + + +endef +IncludeWithNewlines = $(subst ¤,$(newline),$(shell cat $1 | tr '\n' '¤')) + + # Name and release number of this package PKG_NAME:=wifibox PKG_VERSION:=0.1.0 @@ -101,9 +111,11 @@ endif endef define Package/wifibox/postinst - #!/bin/sh - touch /.postinst-was-here +$(call IncludeWithNewlines,post-install.sh) endef +define Package/wifibox/postrm +$(call IncludeWithNewlines,post-remove.sh) +endef $(eval $(call BuildPackage,wifibox)) diff --git a/add-fw-net.sh b/add-fw-net.sh deleted file mode 100755 index d2e71ef..0000000 --- a/add-fw-net.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -cfgChanged=0; zoneNum=-1; i=0 - -while true; do - name=`uci get firewall.@zone[$i].name 2>&1` - exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?` - - if [ $exists -eq 0 ]; then break; fi - if [ $name = "lan" ]; then zoneNum=$i; fi - - i=`expr $i + 1` -done - -if [ $zoneNum -gt -1 ]; then - network=`uci get firewall.@zone[$zoneNum].network 2>&1` - hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?` - if [ $hasWlan -eq 1 ]; then - uci set firewall.@zone[$zoneNum].network="lan wlan" - uci commit firewall - /etc/init.d/dnsmasq reload - cfgChanged=1 - fi -fi - -if [ $cfgChanged -eq 1 ]; then - echo "Added network 'wlan' to zone lan" -else - echo "Firewall configuration not changed" -fi diff --git a/post-install.sh b/post-install.sh index 3f5410a..8fbd14a 100755 --- a/post-install.sh +++ b/post-install.sh @@ -1,7 +1,37 @@ -########### NOTE: add an extra '$' in front of all existing ones when copying into Makefile (and remove this line...) - - #!/bin/sh + +addFirewallNet() { + cfgChanged=0; zoneNum=-1; i=0 + + while true; do + name=`uci get firewall.@zone[$i].name 2>&1` + exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?` + + if [ $exists -eq 0 ]; then break; fi + if [ $name = "lan" ]; then zoneNum=$i; fi + + i=`expr $i + 1` + done + + if [ $zoneNum -gt -1 ]; then + network=`uci get firewall.@zone[$zoneNum].network 2>&1` + hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?` + if [ $hasWlan -eq 1 ]; then + uci set firewall.@zone[$zoneNum].network="lan wlan" + uci commit firewall + /etc/init.d/dnsmasq reload + cfgChanged=1 + fi + fi + + if [ $cfgChanged -eq 1 ]; then + echo "Added network 'wlan' to zone lan." + else + echo "Firewall configuration not changed." + fi +} + + if [ ! -f /etc/banner.default ]; then mv /etc/banner /etc/banner.default cat <<-'EOM' > /etc/banner @@ -15,6 +45,7 @@ if [ ! -f /etc/banner.default ]; then . EOM fi + grep '^# DO NOT MODIFY.*wifibox package.$' /root/.profile >/dev/null 2>&1 if [ $? -eq 1 ]; then cat <<-EOM >> /root/.profile @@ -25,10 +56,10 @@ if [ $? -eq 1 ]; then EOM fi -@echo "Enabling wifi device..." +echo "Enabling wifi device..." uci set wireless.@wifi-device[0].disabled=0; uci commit wireless; wifi -./add-fw-net.sh +addFirewallNet -@echo "Adding network interface 'wlan'..." +echo "Adding network interface 'wlan'..." uci set network.wlan=interface; uci commit network; /etc/init.d/network reload diff --git a/pre-remove.sh b/post-remove.sh similarity index 50% rename from pre-remove.sh rename to post-remove.sh index 7cab24a..7105ede 100755 --- a/pre-remove.sh +++ b/post-remove.sh @@ -1,7 +1,20 @@ #!/bin/sh + if [ -f /etc/banner.default ]; then mv /etc/banner.default /etc/banner fi + +rmdir /usr/share/lua/autowifi/ext/www/cgi-bin +rm /usr/share/lua/autowifi/ext/www/admin +rmdir /usr/share/lua/autowifi/ext/www +rmdir /usr/share/lua/autowifi/admin +rmdir /usr/share/lua/autowifi/ext +rmdir /usr/share/lua/autowifi/misc +rmdir /usr/share/lua/autowifi +rmdir /usr/share/lua +rm /www/admin +rmdir /www/cgi-bin + echo "The wifibox banner has been removed. Changes to the root profile however, have" echo "not been reverted, as haven't the wlan firewall zone and the radio0 device state." echo "NOTE: config changes have not been implemented yet." diff --git a/src/TODO b/src/TODO index 1e10cd1..327b931 100644 --- a/src/TODO +++ b/src/TODO @@ -1,7 +1,4 @@ # TODO -- finish postinst and prerm/postrm scripts -- externalize postinst+prerm scripts by doing something like: 'POSTINST_SCRIPT:=$(shell cat postinst.sh)'? - see: http://stackoverflow.com/questions/1435861/computing-makefile-variable-on-assignment - do things right and copy (not link) the init script to init.d (and enable it automatically, which links to it from rc.d with the proper start priority?) as sudo does: '[ -n "$$IPKG_INSTROOT" ] || { /etc/init.d/sudo enable}'; and here: https://forum.openwrt.org/viewtopic.php?pid=85197#p85197