mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-27 04:40:34 +03:00
makefile: Fix conffiles section and other fixes
This commit is contained in:
121
zapret2/Makefile
121
zapret2/Makefile
@@ -72,10 +72,17 @@ define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/zapret2
|
||||
/opt/zapret2/config
|
||||
/opt/zapret2/ipset/
|
||||
/opt/zapret2/init.d/openwrt/custom.d/
|
||||
/opt/zapret2/ipset/zapret-hosts-google.txt
|
||||
/opt/zapret2/ipset/zapret-hosts-user.txt
|
||||
/opt/zapret2/ipset/zapret-hosts-user-exclude.txt
|
||||
/opt/zapret2/ipset/zapret-ip-exclude.txt
|
||||
/opt/zapret2/ipset/zapret-hosts-auto.txt
|
||||
/opt/zapret2/init.d/openwrt/custom.d/10-script.sh
|
||||
/opt/zapret2/init.d/openwrt/custom.d/20-script.sh
|
||||
/opt/zapret2/init.d/openwrt/custom.d/50-script.sh
|
||||
/opt/zapret2/init.d/openwrt/custom.d/60-script.sh
|
||||
/opt/zapret2/init.d/openwrt/custom.d/90-script.sh
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
@@ -109,6 +116,7 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./init.d.sh $(1)/etc/init.d/zapret2
|
||||
$(INSTALL_DATA) ./config.default $(1)/opt/zapret2/config.default
|
||||
$(INSTALL_DATA) ./config.default $(1)/opt/zapret2/config
|
||||
$(INSTALL_DATA) ./ipset/zapret-hosts-google.txt $(1)/opt/zapret2/ipset/zapret-hosts-google.txt
|
||||
$(INSTALL_DATA) ./ipset/zapret-hosts-user.txt $(1)/opt/zapret2/ipset/zapret-hosts-user.txt
|
||||
$(INSTALL_DATA) ./ipset/zapret-hosts-user-exclude.txt $(1)/opt/zapret2/ipset/zapret-hosts-user-exclude.txt
|
||||
@@ -124,13 +132,24 @@ define Package/$(PKG_NAME)/install
|
||||
$(CP) ./custom.d/* $(1)/opt/zapret2/init.d/openwrt/custom.d/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./uci-def-cfg.sh $(1)/etc/uci-defaults/zapret2-uci-def-cfg.sh
|
||||
# install all sh-scripts
|
||||
$(CP) ./*.sh $(1)/opt/zapret2/
|
||||
rm -f $(1)/opt/zapret/init.d.sh
|
||||
# Fix permisions
|
||||
rm -f $(1)/opt/zapret2/init.d.sh
|
||||
# Create empty conf files
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/ipset/zapret-hosts-auto.txt
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/ipset/cust1.txt
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/ipset/cust2.txt
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/ipset/cust3.txt
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/ipset/cust4.txt
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/init.d/openwrt/custom.d/10-script.sh
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/init.d/openwrt/custom.d/20-script.sh
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/init.d/openwrt/custom.d/60-script.sh
|
||||
$(INSTALL_DATA) /dev/null $(1)/opt/zapret2/init.d/openwrt/custom.d/90-script.sh
|
||||
# Fix permissions
|
||||
chmod 644 $(1)/opt/zapret2/ipset/*.txt
|
||||
chmod 644 $(1)/opt/zapret2/ipset_def/*.txt
|
||||
chmod 644 $(1)/opt/zapret2/init.d/openwrt/custom.d/*.sh
|
||||
chmod 644 $(1)/opt/zapret2/config.default
|
||||
chmod 644 $(1)/opt/zapret2/config*
|
||||
chmod 755 $(1)/opt/zapret2/*.sh
|
||||
chmod 755 $(1)/opt/zapret2/$(MAKE_PATH)/*
|
||||
chmod 755 $(1)/opt/zapret2/ip2net/*
|
||||
@@ -141,19 +160,66 @@ define Package/$(PKG_NAME)/preinst
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
if [ -f "/etc/init.d/zapret2" ]; then
|
||||
SCRIPT=$$( readlink /etc/init.d/zapret2 )
|
||||
ZAPRET_DIR=/opt/zapret2
|
||||
ZAPRET_INITD=/etc/init.d/zapret2
|
||||
ZAPRET_CFG=/etc/config/zapret2
|
||||
if [ -f "$${ZAPRET_INITD}" ]; then
|
||||
SCRIPT=$$( readlink "$${ZAPRET_INITD}" )
|
||||
if [ -n "$${SCRIPT}" ]; then
|
||||
echo "Please uninstall original zapret2 utility!"
|
||||
echo "Please uninstall incompatible \"zapret2\" service!"
|
||||
exit 44
|
||||
fi
|
||||
fi
|
||||
if command -v apk >/dev/null; then
|
||||
PKG_MGR="apk"
|
||||
PKG_CHECK="apk info -e "
|
||||
PKG_REMOVE="apk del --force "
|
||||
else
|
||||
PKG_MGR="opkg"
|
||||
PKG_CHECK="opkg status "
|
||||
PKG_REMOVE="opkg remove --force-remove "
|
||||
fi
|
||||
if [ "$${PKG_UPGRADE}" = "1" ]; then
|
||||
# stop service if PKG_UPGRADE
|
||||
if [ -x "/etc/init.d/zapret2" ]; then
|
||||
/etc/init.d/zapret2 running && /etc/init.d/zapret2 stop >/dev/null 2>&1
|
||||
if [ -x "$${ZAPRET_INITD}" ]; then
|
||||
$${ZAPRET_INITD} running && $${ZAPRET_INITD} stop >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
if $${PKG_CHECK} zapret2 >/dev/null 2>&1; then
|
||||
if [ ! -f "/opt/zapret2/sync_config.sh" ]; then
|
||||
echo "Please uninstall incompatible \"zapret2\" package!"
|
||||
exit 47
|
||||
fi
|
||||
if [ -f "$${ZAPRET_CFG}" ] && ! grep -q "run_on_boot" "$${ZAPRET_CFG}"; then
|
||||
echo "Please uninstall incompatible \"zapret2\" package!"
|
||||
exit 48
|
||||
fi
|
||||
fi
|
||||
if $${PKG_CHECK} luci-app-zapret2 >/dev/null 2>&1; then
|
||||
SVC_FILE=/www/luci-static/resources/view/zapret2/service.js
|
||||
if [ ! -f "$${SVC_FILE}" ] || ! grep -Fq "/remittor/zapret-openwrt" "$${SVC_FILE}"; then
|
||||
echo "Please uninstall incompatible \"luci-app-zapret2\" package!"
|
||||
exit 55
|
||||
fi
|
||||
fi
|
||||
if [ -f "$${ZAPRET_CFG}" ] && ! grep -q "run_on_boot" "$${ZAPRET_CFG}"; then
|
||||
if [ -x "$${ZAPRET_INITD}" ]; then
|
||||
$${ZAPRET_INITD} running && $${ZAPRET_INITD} stop >/dev/null 2>&1
|
||||
fi
|
||||
rm -f $${ZAPRET_CFG}
|
||||
rm -f $${ZAPRET_INITD}
|
||||
[ -d "$${ZAPRET_DIR}" ] && rm -rf $${ZAPRET_DIR}
|
||||
echo "All files of the previously installed package have been removed!"
|
||||
fi
|
||||
if $${PKG_CHECK} zapret2-mdig >/dev/null 2>&1; then
|
||||
$${PKG_REMOVE} zapret2-mdig
|
||||
fi
|
||||
if $${PKG_CHECK} zapret2-ip2net >/dev/null 2>&1; then
|
||||
$${PKG_REMOVE} zapret2-ip2net
|
||||
fi
|
||||
if [ ! -d "$${ZAPRET_DIR}" ]; then
|
||||
mkdir -p $${ZAPRET_DIR}
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
@@ -162,14 +228,25 @@ define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
ZAPRET_DIR=/opt/zapret2
|
||||
ZAPRET_INITD=/etc/init.d/zapret2
|
||||
ZAPRET_CFG=/etc/config/zapret2
|
||||
ZAPRET_CONFIG=/opt/zapret2/config
|
||||
ZAPRET_CONFIG_DEF="/opt/zapret2/config.default"
|
||||
# Fix permissions
|
||||
chmod 644 $${ZAPRET_CFG} >/dev/null 2>&1
|
||||
chmod 644 $${ZAPRET_DIR}/ipset/*.txt >/dev/null 2>&1
|
||||
chmod 644 $${ZAPRET_DIR}/ipset_def/*.txt >/dev/null 2>&1
|
||||
chmod 644 $${ZAPRET_DIR}/init.d/openwrt/custom.d/*.sh >/dev/null 2>&1
|
||||
chmod 644 $${ZAPRET_DIR}/config* >/dev/null 2>&1
|
||||
# creating main config if its not exists
|
||||
if [ ! -f "$${ZAPRET_CONFIG}" ]; then
|
||||
cp -f "$${ZAPRET_CONFIG_DEF}" "$${ZAPRET_CONFIG}"
|
||||
fi
|
||||
# remove fake uci-config
|
||||
[ -f "$${ZAPRET_CFG}" ] && [ ! -s "$${ZAPRET_CFG}" ] && rm -f "$${ZAPRET_CFG}"
|
||||
# check existing uci-config
|
||||
[ -f "/etc/config/zapret2" ] && ZAPRET_CFG_EXISTS=1 || ZAPRET_CFG_EXISTS=0
|
||||
[ -f "$${ZAPRET_CFG}" ] && ZAPRET_CFG_EXISTS=1 || ZAPRET_CFG_EXISTS=0
|
||||
# create or merge uci-config
|
||||
/opt/zapret2/uci-def-cfg.sh
|
||||
[ "$${ZAPRET_CFG_EXISTS}" = "1" ] && echo "Config /etc/config/zapret2 merged with default uci-config"
|
||||
@@ -181,13 +258,13 @@ if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
sh -n "$${ZAPRET_CONFIG}" 2>/dev/null || cp -f "$${ZAPRET_CONFIG_DEF}" "$${ZAPRET_CONFIG}"
|
||||
sh -n "$${ZAPRET_CONFIG}" 2>/dev/null || exit 58
|
||||
# enable main service
|
||||
/etc/init.d/zapret2 enable
|
||||
$${ZAPRET_INITD} enable
|
||||
# stop all
|
||||
/etc/init.d/zapret2 stop_fw
|
||||
/etc/init.d/zapret2 stop_daemons
|
||||
$${ZAPRET_INITD} stop_fw >/dev/null 2>&1
|
||||
$${ZAPRET_INITD} stop_daemons >/dev/null 2>&1
|
||||
ps w | grep '/opt/zapret2/nfq2/nfqws2' | grep -v grep | awk '{print $$1}' | xargs -r kill -9
|
||||
# start main service
|
||||
/etc/init.d/zapret2 start
|
||||
$${ZAPRET_INITD} start
|
||||
# restart firewall
|
||||
[ -x /sbin/fw4 ] && fw4 -q restart || fw3 -q restart
|
||||
fi
|
||||
@@ -198,8 +275,10 @@ define Package/$(PKG_NAME)/prerm
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
EXEDIR=/opt/zapret2
|
||||
ZAPRET_DIR=/opt/zapret2
|
||||
ZAPRET_BASE=/opt/zapret2
|
||||
ZAPRET_INITD=/etc/init.d/zapret2
|
||||
ZAPRET_CFG=/etc/config/zapret2
|
||||
ZAPRET_CONFIG=/opt/zapret2/config
|
||||
ZAPRET_CONFIG_DEF="/opt/zapret2/config.default"
|
||||
OPENWRT_FW_INCLUDE=/etc/firewall.zapret2
|
||||
@@ -214,8 +293,8 @@ if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
. "$${ZAPRET_BASE}/common/fwtype.sh"
|
||||
. "$${ZAPRET_BASE}/common/nft.sh"
|
||||
. "$${ZAPRET_BASE}/common/installer.sh"
|
||||
/etc/init.d/zapret2 running && /etc/init.d/zapret2 stop
|
||||
/etc/init.d/zapret2 disable
|
||||
$${ZAPRET_INITD} running && $${ZAPRET_INITD} stop >/dev/null 2>&1
|
||||
$${ZAPRET_INITD} disable >/dev/null 2>&1
|
||||
ps w | grep '/opt/zapret2/nfq2/nfqws2' | grep -v grep | awk '{print $$1}' | xargs -r kill -9
|
||||
remove_openwrt_firewall
|
||||
nft_del_table
|
||||
@@ -228,7 +307,9 @@ define Package/$(PKG_NAME)/postrm
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
[ -f "/etc/config/zapret2-opkg" ] && rm -f "/etc/config/zapret2-opkg"
|
||||
rm -f /etc/config/zapret2-opkg*
|
||||
rm -f /etc/config/zapret2.opkg*
|
||||
rm -f /etc/config/zapret2.apk*
|
||||
[ -f "/opt/zapret2/config" ] && cp -f /opt/zapret2/config "/opt/zapret2/config.backup"
|
||||
#rm -rf /opt/zapret2
|
||||
#echo "Directory /opt/zapret2 removed!"
|
||||
|
||||
Reference in New Issue
Block a user