mirror of
https://github.com/hectorm/hblock.git
synced 2026-04-22 23:16:36 +05:30
Removed GNU-isms from build system
This commit is contained in:
parent
dd966c1446
commit
7940c7b392
10 changed files with 173 additions and 143 deletions
13
BSDmakefile
Executable file
13
BSDmakefile
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
# pmake might add -J (private)
|
||||
FLAGS=${.MAKEFLAGS:C/\-J ([0-9]+,?)+//W}
|
||||
|
||||
all: .DEFAULT
|
||||
.DEFAULT:
|
||||
@which gmake >/dev/null 2>&1 || \
|
||||
(printf '%s\n' \
|
||||
"GMake is required to build hBlock." \
|
||||
"Install it and try again." \
|
||||
&& exit 1)
|
||||
@gmake ${.FLAGS} ${.TARGETS}
|
||||
104
Makefile
104
Makefile
|
|
@ -5,11 +5,7 @@ PREFIX = $(DESTDIR)/usr/local
|
|||
BINDIR = $(PREFIX)/bin
|
||||
SYSCONFDIR = $(DESTDIR)/etc
|
||||
|
||||
SYSTEMCTL := $(shell which systemctl)
|
||||
|
||||
MKFILE_RELPATH := $(shell printf -- '%s' "$(MAKEFILE_LIST)" | sed 's|^\ ||')
|
||||
MKFILE_ABSPATH := $(shell readlink -f -- '$(MKFILE_RELPATH)')
|
||||
MKFILE_DIR := $(shell dirname -- '$(MKFILE_ABSPATH)')
|
||||
SYSTEMCTL := $(shell which systemctl 2>&1)
|
||||
|
||||
define DEFAULT_HOSTS
|
||||
127.0.0.1 localhost $(shell uname -n)
|
||||
|
|
@ -23,25 +19,10 @@ ff02::3 ip6-allhosts
|
|||
endef
|
||||
export DEFAULT_HOSTS
|
||||
|
||||
.PHONY: all \
|
||||
install uninstall \
|
||||
build \
|
||||
build-hosts \
|
||||
build-domains \
|
||||
build-adblock \
|
||||
build-rpz \
|
||||
build-dnsmasq \
|
||||
build-unbound \
|
||||
build-android \
|
||||
build-windows \
|
||||
stats \
|
||||
stats-tlds \
|
||||
stats-suffixes \
|
||||
index \
|
||||
clean
|
||||
|
||||
.PHONY: all
|
||||
all: build index
|
||||
|
||||
.PHONY: build
|
||||
build: \
|
||||
build-hosts \
|
||||
build-domains \
|
||||
|
|
@ -52,67 +33,85 @@ build: \
|
|||
build-android \
|
||||
build-windows
|
||||
|
||||
.PHONY: build-hosts
|
||||
build-hosts: dist/hosts
|
||||
dist/hosts:
|
||||
mkdir -p dist/
|
||||
"$(MKFILE_DIR)"/hblock -O dist/hosts
|
||||
mkdir -p ./dist/
|
||||
./hblock -O ./dist/hosts
|
||||
|
||||
.PHONY: build-domains
|
||||
build-domains: build-hosts dist/hosts_domains.txt
|
||||
dist/hosts_domains.txt:
|
||||
"$(MKFILE_DIR)"/resources/alt-formats/domains.sh dist/hosts > dist/hosts_domains.txt
|
||||
./resources/alt-formats/domains.sh ./dist/hosts > ./dist/hosts_domains.txt
|
||||
|
||||
.PHONY: build-adblock
|
||||
build-adblock: build-hosts dist/hosts_adblock.txt
|
||||
dist/hosts_adblock.txt:
|
||||
"$(MKFILE_DIR)"/resources/alt-formats/adblock.sh dist/hosts > dist/hosts_adblock.txt
|
||||
./resources/alt-formats/adblock.sh ./dist/hosts > ./dist/hosts_adblock.txt
|
||||
|
||||
.PHONY: build-rpz
|
||||
build-rpz: build-hosts dist/hosts_rpz.txt
|
||||
dist/hosts_rpz.txt:
|
||||
"$(MKFILE_DIR)"/resources/alt-formats/rpz.sh dist/hosts > dist/hosts_rpz.txt
|
||||
./resources/alt-formats/rpz.sh ./dist/hosts > ./dist/hosts_rpz.txt
|
||||
|
||||
.PHONY: build-dnsmasq
|
||||
build-dnsmasq: build-hosts dist/hosts_dnsmasq.conf
|
||||
dist/hosts_dnsmasq.conf:
|
||||
"$(MKFILE_DIR)"/resources/alt-formats/dnsmasq.sh dist/hosts > dist/hosts_dnsmasq.conf
|
||||
./resources/alt-formats/dnsmasq.sh ./dist/hosts > ./dist/hosts_dnsmasq.conf
|
||||
|
||||
.PHONY: build-unbound
|
||||
build-unbound: build-hosts dist/hosts_unbound.conf
|
||||
dist/hosts_unbound.conf:
|
||||
"$(MKFILE_DIR)"/resources/alt-formats/unbound.sh dist/hosts > dist/hosts_unbound.conf
|
||||
./resources/alt-formats/unbound.sh ./dist/hosts > ./dist/hosts_unbound.conf
|
||||
|
||||
.PHONY: build-android
|
||||
build-android: build-hosts dist/hosts_android.zip
|
||||
dist/hosts_android.zip:
|
||||
cd "$(MKFILE_DIR)"/resources/alt-formats/android/ && zip -r "$(CURDIR)"/dist/hosts_android.zip ./
|
||||
cd dist/ && zip -r hosts_android.zip hosts
|
||||
cd ./resources/alt-formats/android/ && zip -r "$(CURDIR)"/dist/hosts_android.zip ./
|
||||
cd ./dist/ && zip -r ./hosts_android.zip ./hosts
|
||||
|
||||
.PHONY: build-windows
|
||||
build-windows: build-hosts dist/hosts_windows.zip
|
||||
dist/hosts_windows.zip:
|
||||
cd "$(MKFILE_DIR)"/resources/alt-formats/windows/ && zip -rl "$(CURDIR)"/dist/hosts_windows.zip ./
|
||||
cd dist/ && zip -rl hosts_windows.zip hosts
|
||||
cd ./resources/alt-formats/windows/ && zip -rl "$(CURDIR)"/dist/hosts_windows.zip ./
|
||||
cd ./dist/ && zip -rl ./hosts_windows.zip ./hosts
|
||||
|
||||
.PHONY: stats
|
||||
stats: stats-tlds stats-suffixes
|
||||
|
||||
.PHONY: stats-tlds
|
||||
stats-tlds: build-domains dist/most_abused_tlds.txt
|
||||
dist/most_abused_tlds.txt:
|
||||
"$(MKFILE_DIR)"/resources/stats/suffix.sh dist/hosts_domains.txt none > dist/most_abused_tlds.txt
|
||||
./resources/stats/suffix.sh ./dist/hosts_domains.txt none > ./dist/most_abused_tlds.txt
|
||||
|
||||
.PHONY: stats-suffixes
|
||||
stats-suffixes: build-domains dist/most_abused_suffixes.txt
|
||||
dist/most_abused_suffixes.txt:
|
||||
"$(MKFILE_DIR)"/resources/stats/suffix.sh dist/hosts_domains.txt > dist/most_abused_suffixes.txt
|
||||
./resources/stats/suffix.sh ./dist/hosts_domains.txt > ./dist/most_abused_suffixes.txt
|
||||
|
||||
.PHONY: index
|
||||
index: build-hosts dist/index.html
|
||||
dist/index.html:
|
||||
"$(MKFILE_DIR)"/resources/templates/index.sh dist/ > dist/index.html
|
||||
./resources/templates/index.sh ./dist/ > ./dist/index.html
|
||||
|
||||
.PHONY: logo
|
||||
logo:
|
||||
./resources/logo/rasterize.sh
|
||||
|
||||
.PHONY: install
|
||||
install: build-hosts
|
||||
mkdir -p -- "$(PREFIX)" "$(BINDIR)" "$(SYSCONFDIR)"
|
||||
install -m 0755 -- dist/hosts "$(SYSCONFDIR)"/hosts
|
||||
install -m 0755 -- "$(MKFILE_DIR)"/hblock "$(BINDIR)"/hblock
|
||||
install -m 0755 -- ./dist/hosts "$(SYSCONFDIR)"/hosts
|
||||
install -m 0755 -- ./hblock "$(BINDIR)"/hblock
|
||||
if test -x "$(SYSTEMCTL)" && test -d "$(SYSCONFDIR)"/systemd/system; then \
|
||||
install -m 0644 -- "$(MKFILE_DIR)"/resources/systemd/hblock.service "$(SYSCONFDIR)"/systemd/system/hblock.service \
|
||||
&& install -m 0644 -- "$(MKFILE_DIR)"/resources/systemd/hblock.timer "$(SYSCONFDIR)"/systemd/system/hblock.timer \
|
||||
install -m 0644 -- ./resources/systemd/hblock.service "$(SYSCONFDIR)"/systemd/system/hblock.service \
|
||||
&& install -m 0644 -- ./resources/systemd/hblock.timer "$(SYSCONFDIR)"/systemd/system/hblock.timer \
|
||||
&& "$(SYSTEMCTL)" daemon-reload \
|
||||
&& "$(SYSTEMCTL)" enable hblock.timer \
|
||||
&& "$(SYSTEMCTL)" start hblock.timer; \
|
||||
fi
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
rm -f -- "$(BINDIR)"/hblock
|
||||
printf -- '%s\n' "$$DEFAULT_HOSTS" > "$(SYSCONFDIR)"/hosts
|
||||
|
|
@ -125,17 +124,18 @@ uninstall:
|
|||
&& "$(SYSTEMCTL)" daemon-reload; \
|
||||
fi
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f \
|
||||
dist/hosts \
|
||||
dist/hosts_domains.txt \
|
||||
dist/hosts_adblock.txt \
|
||||
dist/hosts_rpz.txt \
|
||||
dist/hosts_dnsmasq.conf \
|
||||
dist/hosts_unbound.conf \
|
||||
dist/hosts_android.zip \
|
||||
dist/hosts_windows.zip \
|
||||
dist/most_abused_tlds.txt \
|
||||
dist/most_abused_suffixes.txt \
|
||||
dist/index.html
|
||||
-rmdir dist/
|
||||
./dist/hosts \
|
||||
./dist/hosts_domains.txt \
|
||||
./dist/hosts_adblock.txt \
|
||||
./dist/hosts_rpz.txt \
|
||||
./dist/hosts_dnsmasq.conf \
|
||||
./dist/hosts_unbound.conf \
|
||||
./dist/hosts_android.zip \
|
||||
./dist/hosts_windows.zip \
|
||||
./dist/most_abused_tlds.txt \
|
||||
./dist/most_abused_suffixes.txt \
|
||||
./dist/index.html
|
||||
-rmdir ./dist/
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ set -eu
|
|||
export LC_ALL=C
|
||||
|
||||
main() {
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
hblock="$scriptDir/../../hblock"
|
||||
hosts=$(readlink -f "${1:?}")
|
||||
hblock="./hblock"
|
||||
hosts="${1:?}"
|
||||
|
||||
$hblock -qO- \
|
||||
--sources "file://$hosts" \
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ set -eu
|
|||
export LC_ALL=C
|
||||
|
||||
main() {
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
hblock="$scriptDir/../../hblock"
|
||||
hosts=$(readlink -f "${1:?}")
|
||||
hblock="./hblock"
|
||||
hosts="${1:?}"
|
||||
|
||||
$hblock -qO- \
|
||||
--sources "file://$hosts" \
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ set -eu
|
|||
export LC_ALL=C
|
||||
|
||||
main() {
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
hblock="$scriptDir/../../hblock"
|
||||
hosts=$(readlink -f "${1:?}")
|
||||
hblock="./hblock"
|
||||
hosts="${1:?}"
|
||||
|
||||
$hblock -qO- \
|
||||
--sources "file://$hosts" \
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ set -eu
|
|||
export LC_ALL=C
|
||||
|
||||
main() {
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
hblock="$scriptDir/../../hblock"
|
||||
hosts=$(readlink -f "${1:?}")
|
||||
hblock="./hblock"
|
||||
hosts="${1:?}"
|
||||
|
||||
$hblock -qO- \
|
||||
--sources "file://$hosts" \
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@
|
|||
set -eu
|
||||
export LC_ALL=C
|
||||
|
||||
ENL="$(printf '\\\nx')"; ENL="${ENL%x}"
|
||||
|
||||
main() {
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
hblock="$scriptDir/../../hblock"
|
||||
hosts=$(readlink -f "${1:?}")
|
||||
hblock="./hblock"
|
||||
hosts="${1:?}"
|
||||
|
||||
$hblock -qO- \
|
||||
--sources "file://$hosts" \
|
||||
--header '' \
|
||||
--footer '' \
|
||||
--template 'local-zone: "\1" redirect\nlocal-data: "\1 A \2"' \
|
||||
--template 'local-zone: "\1" redirect'"$ENL"'local-data: "\1 A \2"' \
|
||||
--comment '#'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,50 +7,50 @@
|
|||
set -eu
|
||||
export LC_ALL=C
|
||||
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
targetDir="$scriptDir/bitmap"
|
||||
workDir=./resources/logo/
|
||||
targetDir=$workDir/bitmap/
|
||||
|
||||
_args='--without-gui'
|
||||
_inkscape="inkscape ${_args}";
|
||||
|
||||
rm -f "$targetDir"/favicon-*x*.png
|
||||
favicon="$scriptDir/favicon.svg"
|
||||
$_inkscape -w 16 -h 16 -e "$targetDir/favicon-16x16.png" "$favicon"
|
||||
$_inkscape -w 24 -h 24 -e "$targetDir/favicon-24x24.png" "$favicon"
|
||||
$_inkscape -w 32 -h 32 -e "$targetDir/favicon-32x32.png" "$favicon"
|
||||
$_inkscape -w 48 -h 48 -e "$targetDir/favicon-48x48.png" "$favicon"
|
||||
$_inkscape -w 72 -h 72 -e "$targetDir/favicon-72x72.png" "$favicon"
|
||||
$_inkscape -w 96 -h 96 -e "$targetDir/favicon-96x96.png" "$favicon"
|
||||
$_inkscape -w 128 -h 128 -e "$targetDir/favicon-128x128.png" "$favicon"
|
||||
$_inkscape -w 152 -h 152 -e "$targetDir/favicon-152x152.png" "$favicon"
|
||||
$_inkscape -w 256 -h 256 -e "$targetDir/favicon-256x256.png" "$favicon"
|
||||
$_inkscape -w 384 -h 384 -e "$targetDir/favicon-384x384.png" "$favicon"
|
||||
$_inkscape -w 512 -h 512 -e "$targetDir/favicon-512x512.png" "$favicon"
|
||||
favicon="$workDir"/favicon.svg
|
||||
$_inkscape -w 16 -h 16 -e "$targetDir"/favicon-16x16.png "$favicon"
|
||||
$_inkscape -w 24 -h 24 -e "$targetDir"/favicon-24x24.png "$favicon"
|
||||
$_inkscape -w 32 -h 32 -e "$targetDir"/favicon-32x32.png "$favicon"
|
||||
$_inkscape -w 48 -h 48 -e "$targetDir"/favicon-48x48.png "$favicon"
|
||||
$_inkscape -w 72 -h 72 -e "$targetDir"/favicon-72x72.png "$favicon"
|
||||
$_inkscape -w 96 -h 96 -e "$targetDir"/favicon-96x96.png "$favicon"
|
||||
$_inkscape -w 128 -h 128 -e "$targetDir"/favicon-128x128.png "$favicon"
|
||||
$_inkscape -w 152 -h 152 -e "$targetDir"/favicon-152x152.png "$favicon"
|
||||
$_inkscape -w 256 -h 256 -e "$targetDir"/favicon-256x256.png "$favicon"
|
||||
$_inkscape -w 384 -h 384 -e "$targetDir"/favicon-384x384.png "$favicon"
|
||||
$_inkscape -w 512 -h 512 -e "$targetDir"/favicon-512x512.png "$favicon"
|
||||
|
||||
rm -f "$targetDir"/logotype-*x*.png
|
||||
logotypeA="$scriptDir/logotype.svg"
|
||||
$_inkscape -w 80 -h 25 -e "$targetDir/logotype-80x25.png" "$logotypeA"
|
||||
$_inkscape -w 160 -h 50 -e "$targetDir/logotype-160x50.png" "$logotypeA"
|
||||
$_inkscape -w 240 -h 75 -e "$targetDir/logotype-240x75.png" "$logotypeA"
|
||||
$_inkscape -w 320 -h 100 -e "$targetDir/logotype-320x100.png" "$logotypeA"
|
||||
$_inkscape -w 400 -h 125 -e "$targetDir/logotype-400x125.png" "$logotypeA"
|
||||
$_inkscape -w 560 -h 175 -e "$targetDir/logotype-560x175.png" "$logotypeA"
|
||||
$_inkscape -w 720 -h 225 -e "$targetDir/logotype-720x225.png" "$logotypeA"
|
||||
$_inkscape -w 880 -h 275 -e "$targetDir/logotype-880x275.png" "$logotypeA"
|
||||
$_inkscape -w 1040 -h 325 -e "$targetDir/logotype-1040x325.png" "$logotypeA"
|
||||
$_inkscape -w 1200 -h 375 -e "$targetDir/logotype-1200x375.png" "$logotypeA"
|
||||
$_inkscape -w 1360 -h 425 -e "$targetDir/logotype-1360x425.png" "$logotypeA"
|
||||
logotypeA="$workDir"/logotype.svg
|
||||
$_inkscape -w 80 -h 25 -e "$targetDir"/logotype-80x25.png "$logotypeA"
|
||||
$_inkscape -w 160 -h 50 -e "$targetDir"/logotype-160x50.png "$logotypeA"
|
||||
$_inkscape -w 240 -h 75 -e "$targetDir"/logotype-240x75.png "$logotypeA"
|
||||
$_inkscape -w 320 -h 100 -e "$targetDir"/logotype-320x100.png "$logotypeA"
|
||||
$_inkscape -w 400 -h 125 -e "$targetDir"/logotype-400x125.png "$logotypeA"
|
||||
$_inkscape -w 560 -h 175 -e "$targetDir"/logotype-560x175.png "$logotypeA"
|
||||
$_inkscape -w 720 -h 225 -e "$targetDir"/logotype-720x225.png "$logotypeA"
|
||||
$_inkscape -w 880 -h 275 -e "$targetDir"/logotype-880x275.png "$logotypeA"
|
||||
$_inkscape -w 1040 -h 325 -e "$targetDir"/logotype-1040x325.png "$logotypeA"
|
||||
$_inkscape -w 1200 -h 375 -e "$targetDir"/logotype-1200x375.png "$logotypeA"
|
||||
$_inkscape -w 1360 -h 425 -e "$targetDir"/logotype-1360x425.png "$logotypeA"
|
||||
|
||||
rm -f "$targetDir"/logotype-alt-*x*.png
|
||||
logotypeB="$scriptDir/logotype-alt.svg"
|
||||
$_inkscape -w 48 -h 36 -e "$targetDir/logotype-alt-48x36.png" "$logotypeB"
|
||||
$_inkscape -w 72 -h 54 -e "$targetDir/logotype-alt-72x54.png" "$logotypeB"
|
||||
$_inkscape -w 96 -h 72 -e "$targetDir/logotype-alt-96x72.png" "$logotypeB"
|
||||
$_inkscape -w 128 -h 96 -e "$targetDir/logotype-alt-128x96.png" "$logotypeB"
|
||||
$_inkscape -w 152 -h 114 -e "$targetDir/logotype-alt-152x114.png" "$logotypeB"
|
||||
$_inkscape -w 256 -h 192 -e "$targetDir/logotype-alt-256x192.png" "$logotypeB"
|
||||
$_inkscape -w 384 -h 288 -e "$targetDir/logotype-alt-384x288.png" "$logotypeB"
|
||||
$_inkscape -w 512 -h 384 -e "$targetDir/logotype-alt-512x384.png" "$logotypeB"
|
||||
$_inkscape -w 640 -h 480 -e "$targetDir/logotype-alt-640x480.png" "$logotypeB"
|
||||
$_inkscape -w 768 -h 576 -e "$targetDir/logotype-alt-768x576.png" "$logotypeB"
|
||||
$_inkscape -w 896 -h 672 -e "$targetDir/logotype-alt-896x672.png" "$logotypeB"
|
||||
logotypeB="$workDir"/logotype-alt.svg
|
||||
$_inkscape -w 48 -h 36 -e "$targetDir"/logotype-alt-48x36.png "$logotypeB"
|
||||
$_inkscape -w 72 -h 54 -e "$targetDir"/logotype-alt-72x54.png "$logotypeB"
|
||||
$_inkscape -w 96 -h 72 -e "$targetDir"/logotype-alt-96x72.png "$logotypeB"
|
||||
$_inkscape -w 128 -h 96 -e "$targetDir"/logotype-alt-128x96.png "$logotypeB"
|
||||
$_inkscape -w 152 -h 114 -e "$targetDir"/logotype-alt-152x114.png "$logotypeB"
|
||||
$_inkscape -w 256 -h 192 -e "$targetDir"/logotype-alt-256x192.png "$logotypeB"
|
||||
$_inkscape -w 384 -h 288 -e "$targetDir"/logotype-alt-384x288.png "$logotypeB"
|
||||
$_inkscape -w 512 -h 384 -e "$targetDir"/logotype-alt-512x384.png "$logotypeB"
|
||||
$_inkscape -w 640 -h 480 -e "$targetDir"/logotype-alt-640x480.png "$logotypeB"
|
||||
$_inkscape -w 768 -h 576 -e "$targetDir"/logotype-alt-768x576.png "$logotypeB"
|
||||
$_inkscape -w 896 -h 672 -e "$targetDir"/logotype-alt-896x672.png "$logotypeB"
|
||||
|
|
|
|||
|
|
@ -15,14 +15,46 @@ exists() {
|
|||
else which -- "$1"; fi >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Get file size (or space if it is not a file)
|
||||
getFileSize() {
|
||||
if [ -f "$file" ]; then
|
||||
wc -c < "$file" | awk '{printf "%0.2f kB", $1 / 1000}'
|
||||
fi
|
||||
}
|
||||
|
||||
# Get file MIME type
|
||||
getFileType() {
|
||||
if exists file; then
|
||||
file -bL --mime-type -- "$1"
|
||||
else
|
||||
printf '%s' 'application/octet-stream'
|
||||
fi
|
||||
}
|
||||
|
||||
# Get file modification time
|
||||
getFileModificationTime() {
|
||||
if stat -c '%n' -- "$1" >/dev/null 2>&1; then
|
||||
TZ=UTC stat -c '%.19y UTC' -- "$1"
|
||||
elif stat -f '%Sm' -t '%Z' -- "$1" >/dev/null 2>&1; then
|
||||
TZ=UTC stat -f '%Sm' -t '%Y-%m-%d %H:%M:%S %Z' -- "$1"
|
||||
else
|
||||
printf '%s' '1970-01-01 00:00:00 UTC'
|
||||
fi
|
||||
}
|
||||
|
||||
# Check whether a string ends with the characters of a specified string
|
||||
endsWith() { str=$1 && substr=$2 && [ "${str%$substr}" != "$str" ]; }
|
||||
|
||||
# Escape string for use in HTML
|
||||
escapeHTML() {
|
||||
printf -- '%s' "$1" | \
|
||||
sed -e 's|&|\&|g;s|<|\<|g;s|>|\>|g;s|"|\"|g;s|'\''|\'|g' | \
|
||||
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\ /g'
|
||||
printf -- '%s' "$1" | awk -v RS="" '{
|
||||
gsub(/&/,"\\&");
|
||||
gsub(/</,"\\<");
|
||||
gsub(/>/,"\\>");
|
||||
gsub(/"/,"\\"");
|
||||
gsub(/'\''/,"\\'");
|
||||
gsub(/\n/,"\\ ");
|
||||
print}'
|
||||
}
|
||||
|
||||
# RFC 3986 compliant URL encoding method
|
||||
|
|
@ -45,7 +77,7 @@ encodeURI() {
|
|||
# Calculate digest for Content-Security-Policy
|
||||
cspDigest() {
|
||||
hex=$(printf -- '%s' "$1" | sha256sum | cut -f1 -d' ' | sed 's|\(.\{2\}\)|\1 |g')
|
||||
b64=$(for h in $hex; do printf '%b' "\\$(printf '%o' "0x$h")"; done | base64)
|
||||
b64=$(for h in $hex; do printf '%b' "\\$(printf '%o' "0x$h")"; done | base64 | tr -d '\r')
|
||||
printf 'sha256-%s' "$b64"
|
||||
}
|
||||
|
||||
|
|
@ -66,23 +98,13 @@ main() {
|
|||
escapedFileName=$(escapeHTML "$fileName")
|
||||
escapedFileNameURI=$(escapeHTML "$(encodeURI "$fileName")")
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
fileSize=$(wc -c < "$file" | awk '{printf "%0.2f kB", $1 / 1000}')
|
||||
escapedFileSize=$(escapeHTML "$fileSize")
|
||||
else
|
||||
fileSize=$(printf '\x20')
|
||||
escapedFileSize=$fileSize
|
||||
fi
|
||||
fileSize=$(getFileSize "$file")
|
||||
escapedFileSize=$(escapeHTML "$fileSize")
|
||||
|
||||
if exists file; then
|
||||
fileType=$(file -bL --mime-type "$file")
|
||||
escapedFileType=$(escapeHTML "$fileType")
|
||||
else
|
||||
fileType=$(printf 'application/octet-stream')
|
||||
escapedFileType=$fileType
|
||||
fi
|
||||
fileType=$(getFileType "$file")
|
||||
escapedFileType=$(escapeHTML "$fileType")
|
||||
|
||||
fileDate=$(date -ur "$file" '+%Y-%m-%d %H:%M:%S %Z')
|
||||
fileDate=$(getFileModificationTime "$file")
|
||||
escapedFileDate=$(escapeHTML "$fileDate")
|
||||
|
||||
# Entry template
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
set -eu
|
||||
|
||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||
baseDir="$scriptDir/.."
|
||||
action="${1:-nothing}"
|
||||
|
||||
# Escape strings in sed
|
||||
|
|
@ -13,34 +11,34 @@ quoteSubst() { printf -- '%s' "$1" | sed -e ':a' -e '$!{N;ba' -e '}' -e 's/[&/\]
|
|||
replaceLiteral() { sed -i -- "s/$(quoteRe "$1")/$(quoteSubst "$2")/g" "$3"; }
|
||||
|
||||
version() {
|
||||
jq -r '.version' "$baseDir/package.json"
|
||||
jq -r '.version' ./package.json
|
||||
}
|
||||
|
||||
checksum() {
|
||||
if [ "$action" = 'preversion' ]; then
|
||||
cd "$baseDir" && git show "v$(version):$1" | sha256sum | cut -c 1-64
|
||||
git show "v$(version):$1" | sha256sum | cut -c 1-64
|
||||
elif [ "$action" = 'version' ]; then
|
||||
sha256sum "$baseDir/$1" | cut -c 1-64
|
||||
sha256sum "$1" | cut -c 1-64
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$action" = 'preversion' ]; then
|
||||
replaceLiteral "# Version: $(version)" '# Version: __VERSION__' "$baseDir/hblock"
|
||||
replaceLiteral "'%s\\n' '$(version)'" "'%s\\n' '__VERSION__'" "$baseDir/hblock"
|
||||
replaceLiteral "# Version: $(version)" '# Version: __VERSION__' ./hblock
|
||||
replaceLiteral "'%s\\n' '$(version)'" "'%s\\n' '__VERSION__'" ./hblock
|
||||
|
||||
replaceLiteral "hblock/v$(version)/" 'hblock/v__VERSION__/' "$baseDir/README.md"
|
||||
replaceLiteral "$(checksum hblock)" '__CHECKSUM_HBLOCK__' "$baseDir/README.md"
|
||||
replaceLiteral "hblock/v$(version)/" 'hblock/v__VERSION__/' ./README.md
|
||||
replaceLiteral "$(checksum hblock)" '__CHECKSUM_HBLOCK__' ./README.md
|
||||
|
||||
replaceLiteral "hblock/v$(version)/" 'hblock/v__VERSION__/' "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral "$(checksum resources/systemd/hblock.service)" '__CHECKSUM_HBLOCK_SERVICE__' "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral "$(checksum resources/systemd/hblock.timer)" '__CHECKSUM_HBLOCK_TIMER__' "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral "hblock/v$(version)/" 'hblock/v__VERSION__/' ./resources/systemd/README.md
|
||||
replaceLiteral "$(checksum resources/systemd/hblock.service)" '__CHECKSUM_HBLOCK_SERVICE__' ./resources/systemd/README.md
|
||||
replaceLiteral "$(checksum resources/systemd/hblock.timer)" '__CHECKSUM_HBLOCK_TIMER__' ./resources/systemd/README.md
|
||||
elif [ "$action" = 'version' ]; then
|
||||
replaceLiteral '__VERSION__' "$(version)" "$baseDir/hblock"
|
||||
replaceLiteral '__VERSION__' "$(version)" ./hblock
|
||||
|
||||
replaceLiteral '__VERSION__' "$(version)" "$baseDir/README.md"
|
||||
replaceLiteral '__CHECKSUM_HBLOCK__' "$(checksum hblock)" "$baseDir/README.md"
|
||||
replaceLiteral '__VERSION__' "$(version)" ./README.md
|
||||
replaceLiteral '__CHECKSUM_HBLOCK__' "$(checksum hblock)" ./README.md
|
||||
|
||||
replaceLiteral '__VERSION__' "$(version)" "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral '__CHECKSUM_HBLOCK_SERVICE__' "$(checksum resources/systemd/hblock.service)" "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral '__CHECKSUM_HBLOCK_TIMER__' "$(checksum resources/systemd/hblock.timer)" "$baseDir/resources/systemd/README.md"
|
||||
replaceLiteral '__VERSION__' "$(version)" ./resources/systemd/README.md
|
||||
replaceLiteral '__CHECKSUM_HBLOCK_SERVICE__' "$(checksum resources/systemd/hblock.service)" ./resources/systemd/README.md
|
||||
replaceLiteral '__CHECKSUM_HBLOCK_TIMER__' "$(checksum resources/systemd/hblock.timer)" ./resources/systemd/README.md
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue