commit 0f9c3d2b6a9521dbe62ca0af0e35a6ef550b07d1
parent 6c1333993e21c92ed8426bc60daa1dd9d19de7d8
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 18 Dec 2025 07:27:40 +0530
parent 6c1333993e21c92ed8426bc60daa1dd9d19de7d8
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 18 Dec 2025 07:27:40 +0530
Categorize scripts
19 files changed, 317 insertions(+), 89 deletions(-)
A
|
81
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/debug/dump-colors.sh b/debug/dump-colors.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +for i in $(seq 0 255); do + printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n" +done +
diff --git a/dump-colors.sh b/dump-colors.sh @@ -1,4 +0,0 @@ -for i in {0..255}; do - printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n" -done -
diff --git a/getperms.vbs b/getperms.vbs @@ -1,41 +0,0 @@ -' GrantFullControlToUsers.vbs -Option Explicit - -' File to modify permissions for -Const TARGET_FILE = "C:/Program Files/SKGA Automation/PendingAutomation.ods" - -' Constants for security permissions -Const ADS_RIGHT_GENERIC_ALL = &H10000000 ' Full Control -Const ADS_ACETYPE_ACCESS_ALLOWED = 0 -Const ADS_ACEFLAG_INHERIT_ACE = &H2 -Const ADS_FLAG_OBJECT_TYPE_PRESENT = &H1 - -' Get the file's security descriptor -Dim objSD, objDACL, objACE, objSecurity, objUser -Set objSecurity = CreateObject("ADsSecurityUtility") -Set objSD = objSecurity.GetSecurityDescriptor("file:///" & TARGET_FILE) - -If objSD Is Nothing Then - WScript.Echo "Error: Could not access file security descriptor." - WScript.Quit 1 -End If - -' Get the Discretionary ACL (DACL) -Set objDACL = objSD.DiscretionaryAcl - -' Create an Access Control Entry (ACE) for "Users" -Set objUser = GetObject("WinNT://./Users,group") -Set objACE = CreateObject("AccessControlEntry") -objACE.Trustee = objUser.ADsPath -objACE.AccessMask = ADS_RIGHT_GENERIC_ALL -objACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED -objACE.AceFlags = ADS_ACEFLAG_INHERIT_ACE - -' Add the ACE to the DACL -objDACL.AddAce objACE - -' Apply the modified DACL back to the file -objSD.DiscretionaryAcl = objDACL -objSecurity.SetSecurityDescriptor objSD - -WScript.Echo "Successfully granted Full Control to 'Users' for: " & TARGET_FILE
diff --git a/gradle.sh b/gradle.sh @@ -1,3 +0,0 @@ -#!/bin/sh - -
diff --git a/os/wifi-connect.sh b/os/wifi-connect.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +WIFI_SSID=Home +WIFI_PASS=Home + +case "$(uname -s)" in + Linux) iwctl wlan0 connect "${WIFI_SSID}" "${WIFI_PASS}" ;; + Darwin) networksetup -setairportnetwork en0 "${WIFI_SSID}" "${WIFI_PASS}" ;; + Windows_NT) netsh wlan connect "${WIFI_SSID}" "${WIFI_PASS}" ;; +esac
diff --git a/photos/when.sh b/photos/when.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # Prints out when a file was created using exiftool when () {
diff --git a/qrgen.sh b/qrgen.sh @@ -1,23 +0,0 @@ -#!/bin/bash - -dir='./qr_out' -if [ -e $dir ]; then - #FIXME grammatical errors - echo -e "The directory $dir already exist, do you want to overwrite?[y/N]\c" - read desc - if [ $desc = 'y' ]; then - #FIXME alternative descision checking is recommended - rm -rf $dir - mkdir $dir - fi -else mkdir $dir -fi - - -#TODO query items in block to reduce load -#query items from db -items=`sqlite3 prod.db "select id from prod"` -for i in $items; do - #FIXME change accordingly, use 'qrencode --help' for more info - qrencode -o $dir/$i\.png $i -done
diff --git a/routine/qrgen.sh b/routine/qrgen.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +dir='./qr_out' +if [ -e $dir ]; then + #FIXME grammatical errors + echo -e "The directory $dir already exist, do you want to overwrite?[y/N]\c" + read desc + if [ $desc = 'y' ]; then + #FIXME alternative descision checking is recommended + rm -rf $dir + mkdir $dir + fi +else mkdir $dir +fi + + +#TODO query items in block to reduce load +#query items from db +items=`sqlite3 prod.db "select id from prod"` +for i in $items; do + #FIXME change accordingly, use 'qrencode --help' for more info + qrencode -o $dir/$i\.png $i +done
diff --git a/server/apit b/server/apit @@ -0,0 +1,110 @@ +#!/bin/sh + +# apit - acme.sh post install tool +# +# You issued certs, now where do they go? +# apit solves this problem by giving you a "configuration file", +# +# Two problems are solved here, +# * You don't have type exorbitantly long commands and make common mistakes +# * Properly specify user/group for the certs +# +# =EXAMPLE= +# $ cat apit.conf +# --dir /etc/lighttpd/ssl --domain saikrupagas.com +# --dir /etc/prosody/ssl --domain im.saikrupagas.com +# --dir /etc/openldap/ssl -u ldap -g ldap --domain ldap.saikrupagas.com +# --dir /etc/prosody/ssl -u prosody -g prosody --domain im.saikrupagas.com +# --domain mail.saikrupagas.com +# +# You can consume this with, +# $ apit $(cat apit.conf) +# +# There are two actions: install and remove (install being the default) +# To remove files mentioned in the "configuration file" +# $ apit --action remove $(cat apit.conf) +# +# The script is very simple, and whipped into existence on a +# frustrating server maintainence routine. +# +# =BUGS= +# Does not support -d'option' flags, use as -d 'option' +# +# =LICENSE= +# apit is in the public domain. +# +# To the extent possible under law, Bharatvaj Hemanth <bharatvaj@nply.org> +# has waived all copyright and related or neighboring rights to this work. +# +# http://creativecommons.org/publicdomain/zero/1.0/ + +set -e + +APIT_VERSION=0.1 + +# initial values +default_cert_dir=/etc/ssl/live +op_action=install + +panic() { echo "apit $@"; exit 1; } +usage() { + echo "apit - acme.sh post install tool +$1 +Usage: apit [options] + + --action install / remove (default: ${op_action}) + --dir The path to install the certificates + (default: ${cert_dir}) + -u user (default: current user) + -g group (default: current group) + -h print this message + --domain Name of the domain to install / remove + (caution: This should be given at last) +" + exit 0 +} + +_apit_remove() { + for key in cert.pem fullchain.pem privkey.pem; do + [ -f "${domain_cert_dir}/${key}" ] && rm -v "${domain_cert_dir}/${key}"; + done + [ -d "${domain_cert_dir}" ] && rmdir "${domain_cert_dir}" +} + +_apit_install() { + if [ ! -d "$domain_cert_dir" ]; then + (set -x; mkdir -p "$domain_cert_dir") + fi + + acme.sh --install-cert -d "$1" \ + --key-file "${domain_cert_dir}/privkey.pem" \ + --cert-file "${domain_cert_dir}/cert.pem" \ + --fullchain-file "${domain_cert_dir}/fullchain.pem" + + [ -z "$op_group" ] && op_group="$op_user" + if [ -n "$op_user" ]; then + (set -x; chown "$op_user:$op_group" -R "${domain_cert_dir}") + fi +} + +while [ $# -ne 0 ]; do + case $1 in + --action) op_action="$2" ;; + --dir) cert_dir="$2" ;; + -u) op_user="$2" ;; + -g) op_group="$2" ;; + --domain) + [ -z "$1" ] && usage "Error: no domain given" + domain_cert_dir="$cert_dir/$2" + echo "==> ${op_action}: $2" + _apit_${op_action} "$2" + echo + cert_dir="${default_cert_dir}" + op_user= + op_group= + ;; + -h) usage ;; + -v) echo "${APIT_VERSION}" ;; + esac + shift +done
diff --git a/server/certbot2acmesh.sh b/server/certbot2acmesh.sh @@ -0,0 +1,81 @@ +#/bin/bash + +# Adapted from https://gist.github.com/kobuki/a8b29f3e989f1fa3fc36a9d96873e726 +# to alpine +ACME_SH_ROOT=/root/.acme.sh +WEBCONF_ROOT=/etc/lighttpd/ +WEBROOT=/srv/www/saikrupagas.com +RELOADCMD='service reload lighttpd' + +dom=() +altdoms=() +expiry=() +certpath=() +keypath=() + +fixexpiry() { + local ts randoffset expshift + ts=$1 + [ -n $2 ] && randoffset=$2 || offset=5 + [ -n $3 ] && expshift=$3 || expshift=-30 + echo $(( ts + RANDOM * randoffset * 86400 / 32767 + expshift * 86400)) +} + +certbot certificates > certs.txt +eval "$(cat certs.txt | awk ' +/Domains:/ {print "\ndom+=(" $2 ")"; $1=$2=""; printf "altdoms+=(\""; for (i=3;i<=NF;i++) printf $i (i==NF ? "" : ","); print "\")"} +/Expiry Date:/ {print "expiry+=(\"" $3 " " $4 "\")"} +/Certificate Path:/ {print "certpath+=(" $3 ")"} +/Private Key Path:/ {print "keypath+=(" $4 ")"} +')" + +i=0 +for d in ${dom[@]}; do + echo "Converting: $d" + echo "Alternative names: ${altdoms[$i]}" + echo "Expiration: ${expiry[$i]}" + echo "Cert path: ${certpath[$i]}" + echo "Key path: ${keypath[$i]}" + + siteroot=$ACME_SH_ROOT/$d + mkdir -p $siteroot + [[ -n ${altdoms[$i]} ]] && ad=$'\n'"Le_Alt='${altdoms[$i]}'" || ad="" + renewal=$(date -u -D '%Y-%m-%d %H:%M:%S+00:00' -d "${expiry[$i]}" '+%s') + reloadcmd_b64=$(echo -n "$RELOADCMD" | base64) + renewal=$(fixexpiry $renewal 5 -30) + #renewalstr=$(date -u -D '%Y-%m-%d %H:%M:%S+00:00' -d $renewal +%FT%TZ) #-u '+%FT%TZ' + renewalstr=$(date -u -d @$renewal +%FT%TZ) #-u '+%FT%TZ' + creation=$(date +%s) + creation=$((creation - 86400 * 30)) + creationstr=$(date -d @$creation -u '+%FT%TZ') + echo "New renewal date: $renewalstr" + + cat >$siteroot/$d.conf <<EOF +Le_Domain='$d'$ad +Le_Webroot='$WEBROOT' +Le_PreHook='' +Le_PostHook='' +Le_RenewHook='' +Le_Keylength='2048' +Le_NextRenewTimeStr='$renewalstr' +Le_NextRenewTime='$renewal' +Le_CertCreateTimeStr='$creationstr' +Le_CertCreateTime='$creation' +Le_RealCertPath='' +Le_RealCACertPath='' +Le_RealKeyPath='' +Le_ReloadCmd='__ACME_BASE64__START_${reloadcmd_b64}__ACME_BASE64__END_' +Le_RealFullChainPath='' +Le_API='https://acme-v02.api.letsencrypt.org/directory' +EOF + + cp -aH $(dirname ${certpath[$i]})/fullchain.pem $siteroot/fullchain.cer + cp -aH ${certpath[$i]} $siteroot/$d.cer + cp -aH ${keypath[$i]} $siteroot/$d.key + + #sed -i -e "s@$(dirname ${certpath[$i]})/fullchain.pem@$siteroot/fullchain.cer@" -e "s@${keypath[$i]}@$siteroot/$d.key@" $WEBCONF_ROOT/* + + echo "=====" + i=$((i + 1)) +done +
diff --git a/server/setup-stagit-pages.sh b/server/setup-stagit-pages.sh @@ -0,0 +1,44 @@ +#!/bin/sh -e + +# setup-stagit-pages.sh <bare_repo_dir> +# Generates stagit pages for reposities present in $bare_repo_dir +# The output folders will be generated in the current folder + +bare_repos_dir=${1:-/home/git/repositories} +gitolite_dir="/root/gitolite-admin" + +[ -d "${bare_repos_dir}" ] || { echo "Directory ${bare_repos_dir} not found, skipping stagit run"; exit 0; } + +[ -d "${gitolite_dir}" ] || { echo "Directory ${gitolite_dir} not found"; exit 1; } +git --git-dir "${gitolite_dir}"/.git pull + +for i in $(grep @projects "${gitolite_dir}/conf/gitolite.conf" -m1 | cut -d= -f 2); do + projects="${projects} $i.git" +done + +echo "# Generating web pages for: $projects" + +project_dirs="" +for project in ${projects}; do + project_dirs="${project_dirs} ${bare_repos_dir}/${project}" +done + +echo "# Generating index.html" +( set -x; stagit-index ${project_dirs} > index.html ) + +echo "# Generating web page for $i" +for i in ${projects}; do + repo_name=${i} + dir_name=${repo_name%%.git} + [ -d ${dir_name} ] || mkdir ${dir_name} + cd ${dir_name} + ( set -x; stagit ${bare_repos_dir}/$i ) + cd .. +done + + +echo "# Copying assets" +for i in */; do + cp style.css $i/ + [ -f $i/logo.png ] || cp logo.png $i/ +done
diff --git a/vbs/getperms.vbs b/vbs/getperms.vbs @@ -0,0 +1,41 @@ +' GrantFullControlToUsers.vbs +Option Explicit + +' File to modify permissions for +Const TARGET_FILE = "C:/Program Files/Some Program" + +' Constants for security permissions +Const ADS_RIGHT_GENERIC_ALL = &H10000000 ' Full Control +Const ADS_ACETYPE_ACCESS_ALLOWED = 0 +Const ADS_ACEFLAG_INHERIT_ACE = &H2 +Const ADS_FLAG_OBJECT_TYPE_PRESENT = &H1 + +' Get the file's security descriptor +Dim objSD, objDACL, objACE, objSecurity, objUser +Set objSecurity = CreateObject("ADsSecurityUtility") +Set objSD = objSecurity.GetSecurityDescriptor("file:///" & TARGET_FILE) + +If objSD Is Nothing Then + WScript.Echo "Error: Could not access file security descriptor." + WScript.Quit 1 +End If + +' Get the Discretionary ACL (DACL) +Set objDACL = objSD.DiscretionaryAcl + +' Create an Access Control Entry (ACE) for "Users" +Set objUser = GetObject("WinNT://./Users,group") +Set objACE = CreateObject("AccessControlEntry") +objACE.Trustee = objUser.ADsPath +objACE.AccessMask = ADS_RIGHT_GENERIC_ALL +objACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED +objACE.AceFlags = ADS_ACEFLAG_INHERIT_ACE + +' Add the ACE to the DACL +objDACL.AddAce objACE + +' Apply the modified DACL back to the file +objSD.DiscretionaryAcl = objDACL +objSecurity.SetSecurityDescriptor objSD + +WScript.Echo "Successfully granted Full Control to 'Users' for: " & TARGET_FILE
diff --git a/wifi-connect.sh b/wifi-connect.sh @@ -1,18 +0,0 @@ -#!/bin/sh - -WIFI_SSID=Home -WIFI_PASS=Home - -# linux -if iwctl wlan0 connect "${WIFI_SSID}" "${WIFI_PASS}"; then - exit 0 -fi - -# mac -if networksetup -setairportnetwork en0 "${WIFI_SSID}" "${WIFI_PASS}"; then - exit 0 -fi -# win -if netsh wlan connect "${WIFI_SSID}" "${WIFI_PASS}"; then - exit 0 -fi
: bharatvaj/scripts