From 87b9255c03f29f02ceaec80cdacd033e1c6b39c1 Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Sun, 15 Feb 2015 16:58:25 +0100 Subject: [PATCH] privoxy: remove upgrade handling, conffile and initscript fixes * remove upgrade handling for version 3.0.21 or older packages. Also fix #726 * added user.action, user.filter and user.trust files to conffiles (might be modified by user on running system) * move permission setting from Makefile (install) to initscript because permissions are overwritten during/inside buildroot Signed-off-by: Christian Schoenebeck --- net/privoxy/Makefile | 129 +++++++--------------------- net/privoxy/files/privoxy.config | 11 +-- net/privoxy/files/privoxy.init | 73 +++++++++++----- net/privoxy/files/privoxy.oldconfig | 33 ------- 4 files changed, 88 insertions(+), 158 deletions(-) delete mode 100644 net/privoxy/files/privoxy.oldconfig diff --git a/net/privoxy/Makefile b/net/privoxy/Makefile index c7c0564a9..76f56156f 100644 --- a/net/privoxy/Makefile +++ b/net/privoxy/Makefile @@ -9,12 +9,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=privoxy PKG_VERSION:=3.0.23 -PKG_RELEASE:=2 +PKG_RELEASE:=3 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-stable-src.tar.gz +PKG_SOURCE:=privoxy-$(PKG_VERSION)-stable-src.tar.gz PKG_SOURCE_URL:=@SF/ijbswa PKG_MD5SUM:=bbe47d5ff1a54d9f9fc93a160532697f -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)-stable +PKG_BUILD_DIR:=$(BUILD_DIR)/privoxy-$(PKG_VERSION)-stable PKG_FIXUP:=autoreconf PKG_INSTALL:=1 @@ -63,116 +63,47 @@ CONFIGURE_ARGS += \ # needed otherwise errors during compile MAKE_FLAGS:= -define Build/Install - $(call Build/Install/Default,) - # rename original sample config from pkg_source to save existing one during install - mv $(PKG_INSTALL_DIR)/etc/privoxy/config $(PKG_INSTALL_DIR)/etc/privoxy/config.privoxy -endef - -# "/etc/privoxy/config" temporary needed if updating from old version define Package/$(PKG_NAME)/conffiles /etc/config/privoxy -/etc/privoxy/config +/etc/privoxy/user.action +/etc/privoxy/user.filter +/etc/privoxy/user.trust endef define Package/$(PKG_NAME)/preinst #!/bin/sh - # if run within buildroot exit - [ -n "$${IPKG_INSTROOT}" ] && exit 0 + [ -n "$${IPKG_INSTROOT}" ] && exit 0 # if run within buildroot exit + # stop service if PKG_UPGRADE [ "$${PKG_UPGRADE}" = "1" ] && /etc/init.d/privoxy stop >/dev/null 2>&1 + exit 0 # supress errors from stop command endef define Package/$(PKG_NAME)/install - $(INSTALL_DIR) $(1)/usr/sbin - $(CP) $(PKG_INSTALL_DIR)/usr/sbin/privoxy $(1)/usr/sbin/ - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/privoxy.init $(1)/etc/init.d/privoxy - $(INSTALL_DIR) $(1)/etc/hotplug.d/iface - $(INSTALL_BIN) ./files/privoxy.hotplug $(1)/etc/hotplug.d/iface/80-privoxy - - $(INSTALL_DIR) $(1)/etc/privoxy - $(CP) $(PKG_INSTALL_DIR)/etc/privoxy/* $(1)/etc/privoxy/ - # temporary needed if updating from old version - # otherwise old config file will be delete by opkg - $(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config - # create .old file to be removed with next pacakge builds during update - $(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config.old - # copy NEW config - $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_CONF) ./files/privoxy.config $(1)/etc/config/privoxy -endef - -define Package/$(PKG_NAME)/postinst - #!/bin/sh - - # if fresh install we don't need old config file in privoxy directory - [ "$${PKG_UPGRADE}" = "0" ] && rm -f /etc/privoxy/config - - # if run within buildroot exit here - [ -n "$${IPKG_INSTROOT}" ] && exit 0 - - # if PKG_UPGRADE then build uci configuration - # from existing(?) old /etc/privoxy/config file - if [ "$${PKG_UPGRADE}" = "1" -a -f /etc/privoxy/config ]; then - - echo "converting OLD config to NEW uci configuration" - - SECTION="privoxy.privoxy" - CFGFILE=/etc/privoxy/config - - echo -n > /etc/config/privoxy # clear/create uci configuration file - cp -f $${CFGFILE} $${CFGFILE}.old # save old configuration - - # cleanup - sed -i 's/^[ \t]*//;s/[ \t]*$$//' $${CFGFILE} # remove invisible chars at beginning and end of lines - sed -i '/^#/d' $${CFGFILE} # remove lines with "#" - sed -i '/^$$/d' $${CFGFILE} # remove empty lines - - uci -q set $${SECTION}="privoxy" # create section - - cat $${CFGFILE} | while read LINE; do - # option is first parameter; uci did not like "-" in option names - OPT=$$(echo $${LINE} | awk '{print $$1}' | sed 's/-/_/g') - VAL=$$(echo $${LINE} | awk '{print $$2}') - case $${OPT} in - # debug 1024 => debug_1024 '1' - debug) - uci -q set $${SECTION}.debug_$${VAL}="1" - ;; - # handle list values; splitted case for better reading - actionsfile|filterfile|listen_address) - uci -q add_list $${SECTION}.$${OPT}="$${VAL}" - ;; - permit_access|deny_access) - uci -q add_list $${SECTION}.$${OPT}="$${VAL}" - ;; - trust_info_url|forward) - uci -q add_list $${SECTION}.$${OPT}="$${VAL}" - ;; - forward_socks4|forward_socks4a) - uci -q add_list $${SECTION}.$${OPT}="$${VAL}" - ;; - forward_socks5|forward_socks5t) - uci -q add_list $${SECTION}.$${OPT}="$${VAL}" - ;; - # all others are normal options - *) - uci -q set $${SECTION}.$${OPT}="$${VAL}" - ;; - esac - done - uci -q commit privoxy # commit changes - rm -f $${CFGFILE} # remove old configuration file + if [ -f $(PKG_INSTALL_DIR)/etc/privoxy/trust ]; then \ + mv -f $(PKG_INSTALL_DIR)/etc/privoxy/trust $(PKG_INSTALL_DIR)/etc/privoxy/user.trust; \ + fi + if [ -f $(PKG_INSTALL_DIR)/etc/privoxy/config ]; then \ + rm -f $(PKG_INSTALL_DIR)/etc/privoxy/config; \ fi - # set permissions to privoxy group - echo "setting permissions" - chgrp -R privoxy /etc/privoxy/* - chmod 664 /etc/privoxy/* - chmod 755 /etc/privoxy/templates - chmod 644 /etc/privoxy/templates/* + $(INSTALL_DIR) \ + $(1)/usr/sbin\ + $(1)/etc/privoxy/templates + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/privoxy $(1)/usr/sbin/ + find $(PKG_INSTALL_DIR)/etc/privoxy/templates -maxdepth 1 -type f \ + -exec $(INSTALL_DATA) -t $(1)/etc/privoxy/templates {} \; + find $(PKG_INSTALL_DIR)/etc/privoxy -maxdepth 1 -type f \ + -exec install -m0664 -t $(1)/etc/privoxy {} \; + + $(INSTALL_DIR) \ + $(1)/etc/init.d \ + $(1)/etc/hotplug.d/iface \ + $(1)/etc/config + $(INSTALL_BIN) ./files/privoxy.init $(1)/etc/init.d/privoxy + $(INSTALL_BIN) ./files/privoxy.hotplug $(1)/etc/hotplug.d/iface/80-privoxy + $(INSTALL_CONF) ./files/privoxy.config $(1)/etc/config/privoxy endef $(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/net/privoxy/files/privoxy.config b/net/privoxy/files/privoxy.config index 50e401f9a..95b6cf10c 100644 --- a/net/privoxy/files/privoxy.config +++ b/net/privoxy/files/privoxy.config @@ -1,13 +1,12 @@ -# this file support all available configuration options of -# Privoxy web-proxy +# this file support all available configuration options of Privoxy web-proxy # the scripts move all options to the final privoxy readable configuration file # # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # !!! privoxy uses "-" in option names but uci only support "_" !!! # !!! privoxy "listen-address" must be uci "listen_address" !!! # !!! !!! -# !!! if you add entries please use !!! -# !!! option for options with one parameter (option confdir) !!! +# !!! if you add entries please use !!! +# !!! option for options with one parameter (option confdir) !!! # !!! list for options with multiple parameters (list listen_address) !!! # !!! !!! # !!! special handling for debug option !!! @@ -19,10 +18,11 @@ config privoxy 'privoxy' option logdir '/var/log' option logfile 'privoxy.log' list filterfile 'default.filter' +# list filterfile 'user.filter' list actionsfile 'match-all.action' list actionsfile 'default.action' # list actionsfile 'user.action' - list listen_address '127.0.0.1:8118' +# list listen_address '127.0.0.1:8118' list listen_address '192.168.1.1:8118' option toggle '1' option enable_remote_toggle '1' @@ -38,6 +38,7 @@ config privoxy 'privoxy' option socket_timeout '300' list permit_access '192.168.1.0/24' option debug_1 '0' + option debug_512 '1' option debug_1024 '0' option debug_4096 '1' option debug_8192 '1' diff --git a/net/privoxy/files/privoxy.init b/net/privoxy/files/privoxy.init index 9b4f3a327..b8d978fc3 100644 --- a/net/privoxy/files/privoxy.init +++ b/net/privoxy/files/privoxy.init @@ -8,9 +8,6 @@ CFGFILE=/var/etc/privoxy.conf CFGTEMP=/var/etc/privoxy.conf.tmp _uci2conf() { - local _LOGDIR="/var/log" # set default - local _LOGFILE="privoxy.log" # set default - # redefined callback for options when calling config_load option_cb() { @@ -19,21 +16,19 @@ _uci2conf() { local __OPT="$1" local __VAL="$2" case $__OPT in - logdir) # logdir handled later - _LOGDIR="$__VAL" ;; - logfile) # logfile handled later - _LOGFILE="$__VAL" ;; + confdir|templdir|temporary_directory|logdir|logfile) + # needs to be handled separately because we need to set permissions + # AND needs to be defined first because of a BUG inside privoxy + # require directories to be defined first inside config + ;; + debug_*) + [ $__VAL -eq 0 ] && return # not set ignore + echo -e "debug\t$(echo $__OPT | sed -e 's#debug_##g')" >> $CFGTEMP ;; *) # detect list options (LENGTH) and ignore echo $__OPT | grep -i "_LENGTH" >/dev/null 2>&1 && return # detect list options (ITEM) and ignore echo $__OPT | grep -i "_ITEM" >/dev/null 2>&1 && __OPT=$(echo $__OPT | sed -e "s#_ITEM.##g") - # filter debug_* - echo $__OPT | grep -i "debug_" >/dev/null 2>&1 && { - [ $__VAL -eq 0 ] && return # not set ignore - __VAL=$(echo $__OPT | sed -e "s#debug_##g") - __OPT="debug" - } # uci only accept "_" but we need "-" local __OPT=$(echo $__OPT | sed -e "s#_#-#g") # write to config @@ -42,9 +37,11 @@ _uci2conf() { esac } + # temporary config file + # privoxy need read access mkdir -m0755 -p /var/etc - echo "" > $CFGTEMP # create tmp config file - chmod 644 $CFGTEMP # garantee that privoxy can read + echo "" > $CFGTEMP + chmod 644 $CFGTEMP chgrp privoxy $CFGTEMP echo '### AUTO-GENERATED CONFIGURATION' >> $CFGTEMP @@ -53,19 +50,53 @@ _uci2conf() { echo '### SEE /etc/config/privoxy INSTEAD' >> $CFGTEMP echo '' >> $CFGTEMP - config_load privoxy # calling above option_cb() - - # write logdir/logfile to config - echo -e "logdir\t$_LOGDIR" >> $CFGTEMP - echo -e "logfile\t$_LOGFILE" >> $CFGTEMP + # confdir + # privoxy needs read access (possibly write access) + _CONFDIR=$(uci -q get privoxy.privoxy.confdir) || _CONFDIR="/etc/privoxy" + chmod 755 $_CONFDIR + chmod 664 $_CONFDIR/* + chgrp privoxy $_CONFDIR $_CONFDIR/* + echo -e "confdir\t$_CONFDIR" >> $CFGTEMP + + # templdir + # privoxy need read access + _TEMPLDIR=$(uci -q get privoxy.privoxy.templdir) # no default needed + if [ -z "$_TEMPLDIR" ]; then + chmod 755 $_CONFDIR/templates + chmod 644 $_CONFDIR/templates/* + chgrp privoxy $_CONFDIR/templates $_CONFDIR/templates/* + else + chmod 755 $_TEMPLDIR + chmod 644 $_TEMPLDIR/* + chgrp privoxy $_TEMPLDIR $_TEMPLDIR/* + echo -e "templdir\t$_TEMPLDIR" >> $CFGTEMP + fi - # create logfile and set permissions + # logdir and logfile + # privoxy needs read/write access + _LOGDIR=$(uci -q get privoxy.privoxy.logdir) || _LOGDIR="/var/log" + _LOGFILE=$(uci -q get privoxy.privoxy.logfile) || _LOGFILE="privoxy.log" + mkdir -m0755 -p $_LOGDIR touch $_LOGDIR/$_LOGFILE chmod 664 $_LOGDIR/$_LOGFILE chown privoxy:privoxy $_LOGDIR/$_LOGFILE + echo -e "logdir\t$_LOGDIR" >> $CFGTEMP + echo -e "logfile\t$_LOGFILE" >> $CFGTEMP + + # temporary-directory + # privoxy needs read/write access + _TMP_DIR=$(uci -q get privoxy.privoxy.temporary_directory) # no default needed + if [ -n "$_TMP_DIR" ]; then + mkdir -m0750 -p $_TMP_DIR + chown privoxy:privoxy $_TMP_DIR + echo -e "temporary-directory\t$_TMP_DIR" >> $CFGTEMP + fi + + config_load privoxy # calling above option_cb() and write the rest into $CFGTEMP # move temp to final privoxy readable configuration mv -f $CFGTEMP $CFGFILE + return 0 } boot() { diff --git a/net/privoxy/files/privoxy.oldconfig b/net/privoxy/files/privoxy.oldconfig deleted file mode 100644 index 9496356dc..000000000 --- a/net/privoxy/files/privoxy.oldconfig +++ /dev/null @@ -1,33 +0,0 @@ -# -# original configuration file used by privoxy -# this is no longer supported by this package -# it's converted and moved to uci configuration -# please look at /etc/config/privoxy -# -confdir /etc/privoxy -logdir /var/log -logfile privoxy.log -filterfile default.filter -actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on. -actionsfile default.action # Main actions file -#actionsfile user.action # User customizations -listen-address 127.0.0.1:8118 -toggle 1 -enable-remote-toggle 1 -enable-remote-http-toggle 0 -enable-edit-actions 1 -enforce-blocks 0 -buffer-limit 4096 -forwarded-connect-retries 0 -accept-intercepted-requests 0 -allow-cgi-request-crunching 0 -split-large-forms 0 -keep-alive-timeout 300 -socket-timeout 300 -permit-access 192.168.1.0/24 -debug 1 # show each GET/POST/CONNECT request -debug 4096 # Startup banner and warnings -debug 8192 # Errors - *we highly recommended enabling this* -#admin-address privoxy-admin@example.com -#proxy-info-url http://www.example.com/proxy-service.html -