#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/web dupl-links () { local page=${1:-~/public_html/index.html} grep --color=never -o -P "" $page | grep -v "#" | sort | uniq -D | uniq } broken-links () { local url=$1 local log_whole=bl-whole.log local log_errs=bl-errs.log wget --spider -r -nd -nv -o $log_whole $url grep --color=never -B1 "broken link!" $log_whole > $log_errs rm $log_whole } validate-ebc () { local hp_path=~/public_html echo "CSS check..." validate-html-and-css ${hp_path}/**/*.css echo "CSS check...done" echo -n "HTML check..." local h for h in ${hp_path}/**/*.html; do validate-html-and-css $h broken-links $h done echo "done" } alias ebc=validate-ebc alias validate=validate-ebc alias verify-ebc=validate-ebc validate-html-and-css () { local fs=($@) local ext for f in $fs; do ext=${f:e} case $ext in (htm|html) tidy -q -errors $f [[ $? == 1 ]] && echo "in file $f\n" ;; (css) echo "\n$f:" csstidy $f --compress_colors=false --silent ;; esac done } alias val-all=validate-html-and-css prefix-len () { local user_hosts=$1 local hosts=$(( $user_hosts + 2 )) # network and broadcast local len=$(( 32 - ceil(log($hosts)/log(2)) )) printf "%g\n" $len } test-speed () { local file=m100.data local user=$(whoami) local host=$(hostname) local system=dataswamp.org local dir=speed local url=https://${system}/~${user}/${dir}/${file} rm -f $file dd if=/dev/urandom \ of=$file \ count=$(( 1024 * 100 )) \ bs=1024 2> /dev/null | sha256sum | ( read rnd _; echo $rnd >> $file ) local bytes=$(stat --format "%s" $file) local ul_start=$(date -Is) local ul_time rsync -aLvq $file ${system}:public_html/${dir}/ ul_time=$(dateutils.ddiff $ul_start now) local ul_secs=${ul_time%s} local ul_speed=$(( $bytes / 1024 / $ul_secs )) echo "$bytes bytes -> $user@$system: $ul_time (${ul_speed} KiB/s)" local dl_start=$(date -Is) local dl_time wget -q -O /dev/null $url dl_time=$(dateutils.ddiff $dl_start now) local dl_secs=${dl_time%s} local dl_speed=$(( $bytes / 1024 / $dl_secs )) echo "$bytes bytes -> $user@$host: $dl_time (${dl_speed} KiB/s)" } sleep-until-internet () { while ( $ping-test ); do sleep 1 done } time-up () { sudo ntpdate pool.ntp.org } when-internet-set-time () { sleep-until-internet time-up } cls () { nmcli con show } print-internet-down () { print-label 1 0 " down " } print-internet-up () { print-label 2 0 " up " } ping-test () { local quiet=$1 local google=8.8.8.8 # Google's high-availability DNS ping -w 2 -c 1 $google &> /dev/null local up=$? (( ! ${+quiet} )) && if (( $up == 0 )); then print-internet-up else print-internet-down fi return $up } alias {pingtest,pt}=ping-test