Add disable services functionality

This commit is contained in:
remittor
2023-11-28 14:46:17 +03:00
parent 23f5b83ad4
commit 968d70c0af
4 changed files with 111 additions and 1 deletions

View File

@@ -216,3 +216,12 @@ CONFIG_PACKAGE_luci-i18n-banip-ru=y
### nlbwmon app (OpenWrt Traffic Usage Monitor)
CONFIG_PACKAGE_luci-app-nlbwmon=y
CONFIG_PACKAGE_luci-i18n-nlbwmon-ru=y
### Disabled services
#DISABLED_SVC=watchcat
#DISABLED_SVC=atftpd
#DISABLED_SVC=sqm
#DISABLED_SVC=ddns
#DISABLED_SVC=nextdns
#DISABLED_SVC=dnscrypt-proxy
#DISABLED_SVC=shadowsocks-libev

90
hook_prepare_rootfs.sh Executable file
View File

@@ -0,0 +1,90 @@
#!/usr/bin/env bash
CURDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOTFSDIR="$1"
TOPDIR="$2"
OUTDIR=
[ -z "$OUTDIR" ] && OUTDIR=$TOPDIR
if [ -t 8 ]; then
BUILD_STATE=true
OUTPUT_PIPE=8
else
BUILD_STATE=false
OUTPUT_PIPE=2
fi
log_msg() {
printf "%s\n" "$1" >&$OUTPUT_PIPE
}
log_err() {
local msg="$1"
local _Y _R _N
if [ "$IS_TTY" == "1" -a "$NO_COLOR" != "1" ]; then
_Y=\\033[33m
_R=\\033[31m
_N=\\033[m
fi
printf "$_R%s$_N\n" "ERROR: $msg" >&$OUTPUT_PIPE
}
die() {
log_err "$1"
exit 1
}
get_param_q() {
local param=$1
local filename="$2"
echo $( grep -o -P "(?<=^$param=').*(')" "$filename" 2>/dev/null )
}
log_msg "hook_prepare_rootfs.sh"
#log_msg "TOPDIR: '$TOPDIR'"
#log_msg "ROOTFSDIR: '$ROOTFSDIR'"
if [ ! -d "$ROOTFSDIR" ]; then
die "RootFS dir not found!"
fi
FW_VER_FN="$ROOTFSDIR/etc/openwrt_release"
if [ ! -f "$FW_VER_FN" ]; then
die "File '/etc/openwrt_release' not found!"
fi
FULL_VERSION=$( get_param_q DISTRIB_RELEASE "$FW_VER_FN" )
#log_msg "FULL_VERSION: '$FULL_VERSION'"
if [ -z "$FULL_VERSION" ]; then
die "Firmware version not found!"
fi
FW_ARCH=$( get_param_q DISTRIB_ARCH "$FW_VER_FN" )
#log_msg "FW_ARCH: '$FW_ARCH'"
if [ -z "$FW_ARCH" ]; then
die "Firmware arch not found!"
fi
DIS_SVC_FN="$TOPDIR/disabled_services.lst"
if [ -f "$DIS_SVC_FN" ]; then
DIS_SVC_LST="$( cat ""$DIS_SVC_FN"" )"
for svc in $DIS_SVC_LST; do
[ -z "$svc" ] && continue
svc_xx=$(find "$ROOTFSDIR/etc/rc.d" -maxdepth 1 -name ???$svc -printf 1 -quit)
if [ -n "$svc_xx" ]; then
log_msg "Service '$svc' disabled."
fi
rm -f "$ROOTFSDIR"/etc/rc.d/S??$svc
rm -f "$ROOTFSDIR"/etc/rc.d/K??$svc
done
fi
IS_SNAPSHOT=false
if echo "$FULL_VERSION" | grep snapshot >/dev/null ; then
IS_SNAPSHOT=true
log_msg "Snapshot detected."
fi

View File

@@ -63,6 +63,12 @@ get_cfg_expkg_url() {
echo "$k"
}
get_cfg_dis_svc_lst() {
local cfg=$1
local k=$( grep -o -P '(?<=^#DISABLED_SVC=).*' "$cfg" 2> /dev/null )
echo "$k"
}
get_cfg_board() {
local cfg=$1
local k=$( grep -o -P "(?<=^CONFIG_TARGET_)[a-z0-9]+(?==y)" "$cfg" 2> /dev/null )

View File

@@ -56,7 +56,12 @@ done
cp -f $CFG $XDIR/__current.config
#cp -f .config current.config
DIS_SVC_FN=$XDIR/disabled_services.lst
rm -f $DIS_SVC_FN
DIS_SVC_LST="$( get_cfg_dis_svc_lst $CFG )"
if [ -n "$DIS_SVC_LST" ]; then
echo $DIS_SVC_LST > $DIS_SVC_FN
fi
make defconfig