From b5d2d59c02a7d1771e4813ef82115c15a9d45295 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sun, 5 May 2019 22:05:30 +1000 Subject: [PATCH 1/1] add various old scripts --- cifs-refresh.sh | 79 +++++++++++++++++++++++++++++++++++++++++++ modemstatus.sh | 6 ++++ rgbtobgr565.c | 39 +++++++++++++++++++++ update-blocklist-2.sh | 43 +++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100755 cifs-refresh.sh create mode 100755 modemstatus.sh create mode 100644 rgbtobgr565.c create mode 100644 update-blocklist-2.sh diff --git a/cifs-refresh.sh b/cifs-refresh.sh new file mode 100755 index 0000000..38dcc18 --- /dev/null +++ b/cifs-refresh.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# smbbind.sh share mountpoint +# smbbind.sh "//SERVER/SHARE" "/mnt/somewhere" + +check_every=30 #Seconds +timeout_after=5 #Seconds +restart_after=30 #Seconds + +hide_path=~/.smbbind/ +cifs_opts="rw,cache=strict,username=nt_username,password=nt_password,domain=nt_domain,uid=0,noforceuid,gid=0,noforcegid,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=61440,wsize=57344,actimeo=60,_netdev" + +share="$1" +bind_mountpoint="$2" + +function clean { + #Umount bindfs, next umount cifs, then exit. + echo [..] Cleaning... + #The only open handle opened on the cifs share should be the bindfs one. + echo [..] forcing umounting bindfs on "$bind_mountpoint" + kill -9 $bindfs_pid + umount -f "$bind_mountpoint" + echo [OK] Done. + # Umounted bindfs, cifs should umount without problems + echo [..] Forcing umounting cifs on "$cifs_mountpoint" + umount -f "$cifs_mountpoint" + umount -l "$cifs_mountpoint" + echo [OK] Done cleaning. +} + +function finish { + echo exiting... + clean + trap exit INT TERM EXIT + exit +} + +trap finish INT TERM EXIT + +#Prepare environment + mkdir $hide_path &>/dev/null + cifs_mountpoint=$hide_path/$(echo $bind_mountpoint|tr '/' '_') + mkdir -p $cifs_mountpoint &>/dev/null + mkdir -p $bind_mountpoint &>/dev/null + +while true ; do + + #Mount things: + echo [..] mounting cifs "$share" on "$cifs_mountpoint" + if timeout 10 mount.cifs "$share" "$cifs_mountpoint" -o $cifs_opts ; then + echo [OK] mounted cifs "$share" on "$cifs_mountpoint" + + echo [..] mounting bind "$cifs_mountpoint" on "$bind_mountpoint" + bindfs "$cifs_mountpoint" "$bind_mountpoint" + #Getting the pid of bindfs is tricky. + bindfs_pid=$(ps -eo pid,args|grep bindfs |grep "$cifs_mountpoint" |grep "$bind_mountpoint" |cut -d " " -f 1) + echo [OK] mounted bind "$cifs_mountpoint" on "$bind_mountpoint" + + #Check them + echo [OK] Start Main check cycle, whill check every $check_every seconds... + while true ; do + if ! timeout -k 1 $timeout_after ls "$bind_mountpoint" &>/dev/null ; then + echo no answer from bindfs for "$bind_mountpoint" + clean + break + #else + #echo Share is alive + fi + sleep $check_every + done + + else + echo [!!] Cannot mount "$share" on "$cifs_mountpoint" + fi + + echo [..] Waiting $restart_after seconds: $(date) + sleep $restart_after + +done diff --git a/modemstatus.sh b/modemstatus.sh new file mode 100755 index 0000000..0ea179b --- /dev/null +++ b/modemstatus.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +AUTHUSER=admin +AUTHPASS=$1 +curl -s gateway/DashBoard.asp -u $AUTHUSER:$AUTHPASS | sed -n 's/.*Internet-status2" class="Condition-\(\w*\)".*/\1/gp' + diff --git a/rgbtobgr565.c b/rgbtobgr565.c new file mode 100644 index 0000000..dd6fe9f --- /dev/null +++ b/rgbtobgr565.c @@ -0,0 +1,39 @@ +/* rgbtobgr565 - convert 24-bit RGB pixels to 16-bit BGR565 pixels + + Written in 2016 by Glenn Randers-Pehrson + + To the extent possible under law, the author has dedicated all copyright + and related and neighboring rights to this software to the public domain + worldwide. This software is distributed without any warranty. + See . + + Use with ImageMagick or GraphicsMagick to convert 24-bit RGB pixels + to 16-bit BGR565 pixels, e.g., + + magick file.png -depth 8 rgb:- | rgbtobgr565 > file.bgr565 + + Note that the 16-bit pixels are written in network byte order (most + significant byte first), with blue in the most significant bits and + red in the least significant bits. + + ChangLog: + Jan 2017: changed bgr565 from int to unsigned short (suggested by + Steven Valsesia) +*/ + +#include +int main() +{ + int red,green,blue; + unsigned short bgr565; + while (1) { + red=getchar(); if (red == EOF) return (0); + green=getchar(); if (green == EOF) return (1); + blue=getchar(); if (blue == EOF) return (1); + bgr565 = (unsigned short)(red * 31.0 / 255.0) | + (unsigned short)(green * 63.0 / 255.0) << 5 | + (unsigned short)(blue * 31.0 / 255.0) << 11; + putchar((bgr565 >> 8) & 0xFF); + putchar(bgr565 & 0xFF); + } + } diff --git a/update-blocklist-2.sh b/update-blocklist-2.sh new file mode 100644 index 0000000..bdf3ab8 --- /dev/null +++ b/update-blocklist-2.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# +# update-blocklist-2.sh +# Download a list of blocked domains and pass to dnsmasq +# + +target='blank' # IP to resolve blocked domains to +configfile=/etc/dnsmasq.conf + + +# List server specification +listurl="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml&showintro=0" +extrasfile='/etc/blacklist' # Add additional entries here +reloadcmd='/etc/init.d/dnsmasq restart' +tmpfile="/tmp/.adlist.$$" +tmpconf="/tmp/.dnsmasq.conf.$$" +fetchcmd="/usr/bin/curl "$listurl" -o "$tmpfile"" + +$fetchcmd + +# Add additional entries +[ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile + +# Check temp file +if [ ! -s $tmpfile ]; then + echo "temp file '$tmpfile' either doesn't exist or is empty; quitting" + exit +fi + +# save old config (excluding address entries) +if [ -f "$configfile" ]; then + cat $configfile | grep -v "address=" > $tmpconf +fi + +while read line; do + echo "address=/${line}/${target}" >> $tmpconf +done < $tmpfile + +mv $tmpconf $configfile +$reloadcmd +rm $tmpfile +exit -- 2.47.0