forked from bol-van/zapret
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bol-van
committed
Feb 15, 2022
1 parent
b7aa3a8
commit 9566773
Showing
35 changed files
with
3,093 additions
and
1,994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
exists() | ||
{ | ||
which "$1" >/dev/null 2>/dev/null | ||
} | ||
existf() | ||
{ | ||
type "$1" >/dev/null 2>/dev/null | ||
} | ||
whichq() | ||
{ | ||
which $1 2>/dev/null | ||
} | ||
exist_all() | ||
{ | ||
while [ -n "$1" ]; do | ||
exists "$1" || return 1 | ||
shift | ||
done | ||
return 0 | ||
} | ||
on_off_function() | ||
{ | ||
# $1 : function name on | ||
# $2 : function name off | ||
# $3 : 0 - off, 1 - on | ||
local F="$1" | ||
[ "$3" = "1" ] || F="$2" | ||
shift | ||
shift | ||
shift | ||
"$F" "$@" | ||
} | ||
contains() | ||
{ | ||
# check if substring $2 contains in $1 | ||
[ "${1#*$2}" != "$1" ] | ||
} | ||
find_str_in_list() | ||
{ | ||
[ -n "$1" ] && { | ||
for v in $2; do | ||
[ "$v" = "$1" ] && return 0 | ||
done | ||
} | ||
return 1 | ||
} | ||
end_with_newline() | ||
{ | ||
local c=$(tail -c 1) | ||
[ "$c" = "" ] | ||
} | ||
make_separator_list() | ||
{ | ||
# $1 - var name to receive result | ||
# $2 - separator | ||
# $3,$4,... - elements | ||
local var="$1" sep="$2" i | ||
|
||
shift; shift | ||
while [ -n "$1" ]; do | ||
if [ -n "$i" ] ; then | ||
i=$i$sep$1 | ||
else | ||
i=$1 | ||
fi | ||
shift | ||
done | ||
eval $var=$i | ||
} | ||
make_comma_list() | ||
{ | ||
# $1 - var name to receive result | ||
# $2,$3,... - elements | ||
local var="$1" | ||
shift | ||
make_separator_list $var , "$@" | ||
} | ||
|
||
is_linked_to_busybox() | ||
{ | ||
local IFS F P | ||
|
||
IFS=: | ||
for path in $PATH; do | ||
F=$path/$1 | ||
P="$(readlink $F)" | ||
if [ -z "$P" ] && [ -x $F ] && [ ! -L $F ]; then return 1; fi | ||
[ "${P%busybox*}" != "$P" ] && return | ||
done | ||
} | ||
get_dir_inode() | ||
{ | ||
local dir="$1" | ||
[ -L "$dir" ] && dir=$(readlink "$dir") | ||
ls -id "$dir" | awk '{print $1}' | ||
} | ||
|
||
linux_min_version() | ||
{ | ||
# $1 - major ver | ||
# $2 - minor ver | ||
local V1=$(sed -nre 's/^Linux version ([0-9]+)\.[0-9]+.*$/\1/p' /proc/version) | ||
local V2=$(sed -nre 's/^Linux version [0-9]+\.([0-9]+).*$/\1/p' /proc/version) | ||
[ -n "$V1" -a -n "$V2" ] && [ "$V1" -gt "$1" -o "$V1" -eq "$1" -a "$V2" -ge "$2" ] | ||
} | ||
linux_get_subsys() | ||
{ | ||
local INIT=$(sed 's/\x0/\n/g' /proc/1/cmdline | head -n 1) | ||
|
||
[ -L "$INIT" ] && INIT=$(readlink "$INIT") | ||
INIT=$(basename "$INIT") | ||
if [ -f "/etc/openwrt_release" ] && [ "$INIT" = "procd" ] ; then | ||
SUBSYS=openwrt | ||
else | ||
# generic linux | ||
SUBSYS= | ||
fi | ||
} | ||
openwrt_fw3() | ||
{ | ||
[ ! -x /sbin/fw4 -a -x /sbin/fw3 ] | ||
} | ||
openwrt_fw4() | ||
{ | ||
[ -x /sbin/fw4 ] | ||
} | ||
openwrt_fw3_integration() | ||
{ | ||
[ "$FWTYPE" = iptables ] && openwrt_fw3 | ||
} | ||
|
||
create_dev_stdin() | ||
{ | ||
[ -e /dev/stdin ] || ln -s /proc/self/fd/0 /dev/stdin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
read_yes_no() | ||
{ | ||
# $1 - default (Y/N) | ||
local A | ||
read A | ||
[ -z "$A" ] || ([ "$A" != "Y" ] && [ "$A" != "y" ] && [ "$A" != "N" ] && [ "$A" != "n" ]) && A=$1 | ||
[ "$A" = "Y" ] || [ "$A" = "y" ] || [ "$A" = "1" ] | ||
} | ||
ask_yes_no() | ||
{ | ||
# $1 - default (Y/N or 0/1) | ||
# $2 - text | ||
local DEFAULT=$1 | ||
[ "$1" = "1" ] && DEFAULT=Y | ||
[ "$1" = "0" ] && DEFAULT=N | ||
[ -z "$DEFAULT" ] && DEFAULT=N | ||
printf "$2 (default : $DEFAULT) (Y/N) ? " | ||
read_yes_no $DEFAULT | ||
} | ||
ask_yes_no_var() | ||
{ | ||
# $1 - variable name for answer : 0/1 | ||
# $2 - text | ||
local DEFAULT | ||
eval DEFAULT="\$$1" | ||
if ask_yes_no "$DEFAULT" "$2"; then | ||
eval $1=1 | ||
else | ||
eval $1=0 | ||
fi | ||
} | ||
ask_list() | ||
{ | ||
# $1 - mode var | ||
# $2 - space separated value list | ||
# $3 - (optional) default value | ||
local M_DEFAULT | ||
eval M_DEFAULT="\$$1" | ||
local M_ALL=$M_DEFAULT | ||
local M="" | ||
local m | ||
|
||
[ -n "$3" ] && { find_str_in_list "$M_DEFAULT" "$2" || M_DEFAULT="$3" ;} | ||
|
||
n=1 | ||
for m in $2; do | ||
echo $n : $m | ||
n=$(($n+1)) | ||
done | ||
printf "your choice (default : $M_DEFAULT) : " | ||
read m | ||
[ -n "$m" ] && M=$(echo $2 | cut -d ' ' -f$m 2>/dev/null) | ||
[ -z "$M" ] && M="$M_DEFAULT" | ||
echo selected : $M | ||
eval $1="\"$M\"" | ||
|
||
[ "$M" != "$M_OLD" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_root() | ||
{ | ||
local exe | ||
echo \* checking privileges | ||
[ $(id -u) -ne "0" ] && { | ||
echo root is required | ||
exe="$EXEDIR/$(basename "$0")" | ||
exists sudo && exec sudo "$exe" | ||
exists su && exec su root -c "$exe" | ||
echo su or sudo not found | ||
exitp 2 | ||
} | ||
} |
Oops, something went wrong.