From: Andrew DeFaria Date: Wed, 5 Jan 2022 18:34:32 +0000 (-0800) Subject: Moved scripts from /System/bin to /opt/clearscm/bin X-Git-Url: https://defaria.com/gitweb/?a=commitdiff_plain;h=560c091996e7e2f3c2d1babb51c0e84f3afb95a6;p=clearscm.git Moved scripts from /System/bin to /opt/clearscm/bin Then symlinked them back to /System/bin. This puts these scripts under version control --- diff --git a/bin/backupEmail.sh b/bin/backupEmail.sh new file mode 100755 index 0000000..766a3ce --- /dev/null +++ b/bin/backupEmail.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# Simple script to backup email store +backupDir=/System/Backups/Email + +exclusions=--exclude=.* + +ssh defaria.com tar $exclusions -cjf - mail > $backupDir/mail.tar.bz2.$$ + +mv $backupDir/mail.tar.bz2.$$ $backupDir/mail.tar.bz2 diff --git a/bin/check4update b/bin/check4update new file mode 100755 index 0000000..387f034 --- /dev/null +++ b/bin/check4update @@ -0,0 +1,40 @@ +#!/bin/bash +expireTime=1200 +systems="\ + earth\ + mars\ + defaria.com\ +" + +function notify { + #zenity --notification --text "$1" 2> /dev/null + notify-send --expire-time=$expireTime "$1" +} + +function yesno { + question=$1 + + zenity --question --text "$question" --width=300 2> /dev/null +} + +update=$1; + +for system in $systems; do + notify "Checking $system for updates" + ssh $system sudo apt-get -qq update + ssh $system apt list --upgradeable 2> /dev/null | grep -v "^Listing" > /tmp/check4update.list + + if [ $(wc -l /tmp/check4update.list 2> /dev/null | cut -f1 -d' ') -ne 0 ]; then + cat /tmp/check4update.list + + if yesno "There are updates for $system\nApply them now?" ]; then + ssh $system sudo /opt/clearscm/bin/update-system + else + notify "$system not updated" + fi + else + notify "$system is up to date" + fi + + rm -f /tmp/check4update.list +done diff --git a/bin/fixdropbox b/bin/fixdropbox new file mode 100755 index 0000000..9b6395b --- /dev/null +++ b/bin/fixdropbox @@ -0,0 +1,3 @@ +#!/bin/bash +dropbox stop > /dev/null 2>&1 +dbus-launch dropbox start -i > /dev/null 2>&1 diff --git a/bin/fixscreen b/bin/fixscreen new file mode 100755 index 0000000..7195dc9 --- /dev/null +++ b/bin/fixscreen @@ -0,0 +1,3 @@ +#!/bin/bash +# Fixes screen when the gnome-panel gets stuck on the right side. +xrandr --output HDMI-0 --primary diff --git a/bin/gp b/bin/gp new file mode 100755 index 0000000..38e940e --- /dev/null +++ b/bin/gp @@ -0,0 +1,4 @@ +#!/bin/bash +# +# Simple script to restart gnome-panel since it keeps dying on me. +gnome-panel --replace > /dev/null 2>&1 & diff --git a/bin/impishgdm b/bin/impishgdm new file mode 100755 index 0000000..133a8d7 --- /dev/null +++ b/bin/impishgdm @@ -0,0 +1,234 @@ +#!/bin/bash + +codename=$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2) + +if [ "$codename" == "impish" ] +then +source="/usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource" +else +echo " +---------------------------------------- +Sorry, Script is only for Ubuntu 21.10 +Exiting... +----------------------------------------" +exit 1 +fi + +pkg=$(dpkg -l | grep libglib2.0-dev >/dev/null && echo "yes" || echo "no") +if [ "$pkg" == "no" ] +then +echo " +----------------------------------------------------------------------------------------------------- +Sorry, the package 'libglib2.0-dev' is not installed. Install the package and then run this Script. +For now, Exiting... +-----------------------------------------------------------------------------------------------------" +exit 1 +fi + +############################################################################################ +case "$1" in ############################################################################### +############################################################################################ +--set) +############################################################################################ + +if [ "$UID" != "0" ] +then +echo "This Script must be run with sudo" +exit 1 +fi + +echo " +------------------------------------------------------------------------------------------------------- +Please note that after setting login screen background, +>>>>>>>>> Reboot is highly recomonded to see the changes <<<<<<<<<<<< + +Do you want to proceed now? [Yes/no] Type n to exit, or press enter to proceed. +-------------------------------------------------------------------------------------------------------" +read answer + +if [ "$answer" == "n" ] || [ "$answer" == "N" ] +then +echo "Exiting..." +exit 1 +fi + +echo " +Please Choose any one number from below. +------------- +1. for Image +2. for Color +-------------" +read a + +if [ -z $a ] +then +echo "Option is not selected. +Exiting..." +exit 1 +fi + +if [ "$a" == "1" ] +then +echo "Enter Image Path for Login Screen +---------------------------------------------------- +Example1: /usr/share/backgrounds/2.jpg +Example2: /usr/local/share/backgrounds/spaceship.png +Example3: /home/impish/Downloads/myBG.jpeg +----------------------------------------------------" +read b + +elif [ "$a" == "2" ] +then +echo " +Enter Hex Color Code for Login Screen (you may note down colors of your choice from this link https://www.color-hex.com/) +------------------------------------------------------------------------------------------------------------------------- +Example1: #00ff00 +Example2: #fca +Example3: #456789 +Example4: #123 +Example5: #FF00FF +-------------------------------------------------------------------------------------------------------------------------" +read c +fi + +if [ -z $b ] && [ -z $c ] +then +echo "Input is not Provided. +Exiting..." +exit 1 +fi + +if [ -z $c ] +then +color="#042320" +else +color="$c" +fi + +if ! [ -z $c ] +then + if ! [[ $c =~ ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ ]]; then + echo " +------------------------------------------------------------------------------------------------------------ + Sorry it is not a valid Hex color, Please choose the valid HEX color first and then run this script. +------------------------------------------------------------------------------------------------------------" + exit 1 + fi +fi + +if ! [ -z $b ] +then + if ! [ -e $b ]; then + echo " +--------------------------------------------------------------------------------------------------- +Image path you entered does not exist, script defined background color is going to be used for now. +Please notedown the correct file path of the Image and then run this script. +---------------------------------------------------------------------------------------------------" + fi +fi + +prefix="/org/gnome/shell/theme" +dest="/usr/local/share/gnome-shell/theme/impishgdm" + +install -D /dev/null $dest/gdm.css +install -D /dev/null $dest/impishgdm.gresource.xml +install -d $dest/icons/scalable/actions + +gresource extract $source $prefix/gdm.css > $dest/original.css +gresource extract $source $prefix/checkbox.svg > $dest/checkbox.svg +gresource extract $source $prefix/checkbox-off.svg > $dest/checkbox-off.svg +gresource extract $source $prefix/checkbox-focused.svg > $dest/checkbox-focused.svg +gresource extract $source $prefix/checkbox-off-focused.svg > $dest/checkbox-off-focused.svg +gresource extract $source $prefix/toggle-on.svg > $dest/toggle-on.svg +gresource extract $source $prefix/toggle-off.svg > $dest/toggle-off.svg +gresource extract $source $prefix/icons/scalable/actions/pointer-drag-symbolic.svg > $dest/icons/scalable/actions/pointer-drag-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/keyboard-enter-symbolic.svg > $dest/icons/scalable/actions/keyboard-enter-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/keyboard-hide-symbolic.svg > $dest/icons/scalable/actions/keyboard-hide-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/pointer-secondary-click-symbolic.svg > $dest/icons/scalable/actions/pointer-secondary-click-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/keyboard-shift-filled-symbolic.svg > $dest/icons/scalable/actions/keyboard-shift-filled-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/keyboard-caps-lock-filled-symbolic.svg > $dest/icons/scalable/actions/keyboard-caps-lock-filled-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/pointer-primary-click-symbolic.svg > $dest/icons/scalable/actions/pointer-primary-click-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/keyboard-layout-filled-symbolic.svg > $dest/icons/scalable/actions/keyboard-layout-filled-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/eye-not-looking-symbolic.svg > $dest/icons/scalable/actions/eye-not-looking-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/pointer-double-click-symbolic.svg > $dest/icons/scalable/actions/pointer-double-click-symbolic.svg +gresource extract $source $prefix/icons/scalable/actions/eye-open-negative-filled-symbolic.svg > $dest/icons/scalable/actions/eye-open-negative-filled-symbolic.svg + +echo '@import url("resource:///org/gnome/shell/theme/original.css"); + #lockDialogGroup { + background: '$color' url(file://'$b'); + background-repeat: no-repeat; + background-size: cover; + background-position: center; }' > $dest/gdm.css + +echo ' + + + original.css + gdm.css + toggle-off.svg + checkbox-off.svg + toggle-on.svg + checkbox-off-focused.svg + checkbox-focused.svg + checkbox.svg + icons/scalable/actions/pointer-drag-symbolic.svg + icons/scalable/actions/keyboard-enter-symbolic.svg + icons/scalable/actions/keyboard-hide-symbolic.svg + icons/scalable/actions/pointer-secondary-click-symbolic.svg + icons/scalable/actions/keyboard-shift-filled-symbolic.svg + icons/scalable/actions/keyboard-caps-lock-filled-symbolic.svg + icons/scalable/actions/pointer-primary-click-symbolic.svg + icons/scalable/actions/keyboard-layout-filled-symbolic.svg + icons/scalable/actions/eye-not-looking-symbolic.svg + icons/scalable/actions/pointer-double-click-symbolic.svg + icons/scalable/actions/eye-open-negative-filled-symbolic.svg + +' > $dest/impishgdm.gresource.xml + +cd $dest +glib-compile-resources impishgdm.gresource.xml +mv impishgdm.gresource .. +rm -r $dest +update-alternatives --quiet --install /usr/share/gnome-shell/gdm-theme.gresource gdm-theme.gresource /usr/local/share/gnome-shell/theme/impishgdm.gresource 0 +update-alternatives --quiet --set gdm-theme.gresource /usr/local/share/gnome-shell/theme/impishgdm.gresource + +check=$(update-alternatives --query gdm-theme.gresource | grep Value | grep /usr/local/share/gnome-shell/theme/impishgdm.gresource >/dev/null && echo "pass" || echo "fail") +if [ "$check" == "pass" ] +then +echo " + --------- + |Success| + ---------" +else +echo Failure +exit 1 +fi +;; +############################################################################################ +--reset) ################################################################################### +############################################################################################ + +if [ -e /usr/local/share/gnome-shell/theme/impishgdm.gresource ] +then +rm /usr/local/share/gnome-shell/theme/impishgdm.gresource +update-alternatives --quiet --set gdm-theme.gresource "$source" +cd /usr/local/share +rmdir --ignore-fail-on-non-empty -p gnome-shell/theme +echo " + --------------- + |Reset Success| + ---------------" +else +echo " +----------------------------------------------------------------------------- +No need, Already Reset. (or unlikely background is not set using this Script.) +-----------------------------------------------------------------------------" +exit 1 +fi +;; +############################################################################################ +*) ######################################################################################### +############################################################################################ +echo "Use the parameter '--set' or '--reset'; example: './impishgdm --set' or './impishgdm --reset'" +exit 1 +esac diff --git a/bin/jpg b/bin/jpg new file mode 100755 index 0000000..69ac18e --- /dev/null +++ b/bin/jpg @@ -0,0 +1,6 @@ +#!/bin/bash +# +# Simple script to save an image in the clipboard to a file +save_file=/tmp/image.jpg + +xclip -selection clipboard -t image/jpeg -o > $save_file diff --git a/bin/lightsout.sh b/bin/lightsout.sh new file mode 100755 index 0000000..bd09301 --- /dev/null +++ b/bin/lightsout.sh @@ -0,0 +1,20 @@ +#!/bin/bash +host=$(hostname) + +if [ "$1" = "-a" ]; then + if [ $host = "mars" ]; then + setsid ssh earth lightsout.sh & + elif [ $host = "earth" ]; then + setsid ssh mars lightsout.sh & + fi +fi + +if [ $host = "earth" ]; then + export DISPLAY=:1 +else + export DISPLAY=:0 +fi + +sleep 2 +/usr/local/bin/setdpms.sh +xset dpms force off diff --git a/bin/micrecording.sh b/bin/micrecording.sh new file mode 100755 index 0000000..fe53d4b --- /dev/null +++ b/bin/micrecording.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# This will set the audio system to be able to record both the mic and what +# is going on in the speakers. This might cause feedback to turn down the +# speakers. Also, you'll probably here an echo, ugh. +# +# +module=$(pactl load-module module-loopback latency_msec=1) +echo "Note you must do pactl unload-module $module to turn this off" + diff --git a/bin/recordphone b/bin/recordphone new file mode 100755 index 0000000..2ebadae --- /dev/null +++ b/bin/recordphone @@ -0,0 +1,10 @@ +#!/bin/sh +if [ "$1" = "on" ]; then + pactl load-module module-loopback +elif [ "$1" = "off" ]; then + pactl unload-module module-loopback +else + echo "Usage $0 " + exit 1 +fi + diff --git a/bin/rmbg b/bin/rmbg new file mode 100755 index 0000000..17286b1 --- /dev/null +++ b/bin/rmbg @@ -0,0 +1,26 @@ +#!/bin/bash + +# We need our sj function... +source ~/.rc/functions + +# Get the PID of the running setbg process +setbgPID=$(sj setbg | awk '{print $2}') + +# Check to make sure it's not blank, meaning no setbg process running +if [ -s "$setbgPID" ]; then + echo "There is no setbg process running" + exit 1 +fi + +# Check to see if setbgPID has multiple processes. Multiple processes +# should never happen but if we get more than one PID back then they +# will be listed side by side with spaces, so check that. +echo $setbgPID | grep -q ' ' + +if [ $? = 0 ]; then + echo "There are multiple setbg processes???" + exit 1 +fi + +setbgPicture=$(cat ~/.setbg) +rm "$setbgPicture" && kill -USR1 $setbgPID diff --git a/bin/setsound.sh b/bin/setsound.sh new file mode 100755 index 0000000..605fbf9 --- /dev/null +++ b/bin/setsound.sh @@ -0,0 +1,4 @@ +#/bin/bash +# Need to set PULSE_RUNTIME_PATH under cron +export PULSE_RUNTIME_PATH=/run/user/$(id -u)/pulse +pactl -- set-sink-volume @DEFAULT_SINK@ $1% diff --git a/bin/shh b/bin/shh new file mode 100755 index 0000000..f70c361 --- /dev/null +++ b/bin/shh @@ -0,0 +1,15 @@ +#!/bin/bash +timeout=5000 # 5 seconds + +# This just toggles the creation of the /opt/clearscm/bin/shh file +if [ -f /opt/clearscm/bin/shh ]; then + rm /opt/clearscm/bin/shh + cp ~/.icons/ShhOff.png ~/.icons/Shh.png + notify-send -t $timeout "Announcements turned on" +else + touch /opt/clearscm/bin/shh + cp ~/.icons/ShhOn.png ~/.icons/Shh.png + # Note that a -t 0 will keep the notification up. This way we can + # be visually reminded that we are not receiving audio announcements + notify-send -t 0 "Announcements turned off" +fi diff --git a/bin/showpic b/bin/showpic new file mode 100755 index 0000000..1b223fb --- /dev/null +++ b/bin/showpic @@ -0,0 +1,2 @@ +#!/bin/bash +eog "$(cat ~/.setbg)" diff --git a/bin/speedtest b/bin/speedtest new file mode 100755 index 0000000..5a0214a --- /dev/null +++ b/bin/speedtest @@ -0,0 +1,8 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from speedtest import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/speedtest.sh b/bin/speedtest.sh new file mode 100755 index 0000000..aa73fef --- /dev/null +++ b/bin/speedtest.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec sudo -u andrew /System/bin/speedtest $@ diff --git a/bin/system76 b/bin/system76 new file mode 100755 index 0000000..7b51cd7 --- /dev/null +++ b/bin/system76 @@ -0,0 +1,16 @@ +#!/bin/bash +mkdir ~/system76 +journalctl > ~/system76/journal.log +dmesg > ~/system76/dmesg.log +cp /var/log/Xorg.1.log ~/system76/Xorg.1.log +sudo dmidecode > ~/system76/demidecode +sudo lspci -vv > ~/system76/lscpi.log +sudo lsusb -vv > ~/system76/lsusb.log +uname -a > ~/system76/uname.log +df -h / > ~/system76/df +lsblk -f > ~/system76/lsblk +cp /etc/fstab ~/system76/fstab +cp /etc/os-release ~/system76/os-release +tar czf system76-log.tgz ~/system76/* +rm ~/system76/* +rmdir ~/system76 diff --git a/bin/testspeed b/bin/testspeed new file mode 100755 index 0000000..2a4f25d --- /dev/null +++ b/bin/testspeed @@ -0,0 +1,13 @@ +#!/bin/bash +# Test internet speed + +speedtest=/System/bin/speedtest.sh +datafile=/System/Data/$(hostname).speedtest.csv + +# If creating file initially add csv headers +if [ ! -f $datafile ]; then + $speedtest --csv-header > $datafile +fi + +# Now test speed +$speedtest --csv >> $datafile diff --git a/bin/tunnel b/bin/tunnel new file mode 100755 index 0000000..06019c0 --- /dev/null +++ b/bin/tunnel @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Simple script to use ssh to tunnel ports for SMTP (1025 -> 25) to +# defaria.com so I can read and write email to my home server. +# +# Note -Nf puts ssh in the background after establishing the tunnel. +# +# This is for use on Synology only +tunnel_running=$(ps -ef | grep ssh | grep defaria.com:25) + +if [ -z "$tunnel_running" ]; then + ssh -Nf -L192.168.0.251:1025:defaria.com:25 andrew@defaria.com +fi diff --git a/bin/tunnel.sh b/bin/tunnel.sh new file mode 100755 index 0000000..586cf82 --- /dev/null +++ b/bin/tunnel.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# +# This is for use on Synology only +exec sudo -u andrew /System/bin/tunnel $@ diff --git a/bin/updateCalendar.sh b/bin/updateCalendar.sh new file mode 100755 index 0000000..50b50ef --- /dev/null +++ b/bin/updateCalendar.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Odd. Seems the following causes wget to use IPv6 instead of IPv4. Well +# recently we turned off IPv6 because we suspect this causes our WiFi +# dropout problem. But then this hangs. +#wget -O /tmp/calendar.$$.ics 'https://www.google.com/calendar/ical/adefaria%40gmail.com/public/basic.ics' >> /tmp/updateCalendar.$$.log 2>&1 +wget --no-check-certificate -O /tmp/calendar.$$.ics 'https://172.217.11.174/calendar/ical/adefaria%40gmail.com/public/basic.ics' >> /tmp/updateCalendar.$$.log 2>&1 +wget -O /tmp/meetups.$$.ics 'http://www.meetup.com/events/ical/10426135/8dfdd0ffaaedecf720c5faf0cf3871b7ee5f5c1e/going' >> /tmp/updateCalendar.$$.log 2>&1 + +wget -4 -O /tmp/tripit.$$.ics 'http://www.tripit.com/feed/ical/private/06C4F90D-EFEFB9C5FDB17EC5FCB327DE31A54D96/tripit.ics' >> /tmp/updateCalendar.$$.log 2>&1 + +# Now let's combine the files. First strip off the END:CALENDAR from the main +# file. +filesize=$(wc -l /tmp/calendar.$$.ics | cut -f1 -d' ') +let lines=filesize-1 +head -n $lines /tmp/calendar.$$.ics > /tmp/calendar2.$$.ics +mv /tmp/calendar2.$$.ics /tmp/calendar.$$.ics + +# Now extract the middle of the next calendar +# Note, if we have nothing RSVPed here for Meetup then the file should be skipped. +# We will get an .ics file but it'll be short - less than 27 lines +filesize=$(wc -l /tmp/meetups.$$.ics | cut -f1 -d' ') + +if [ $filesize -gt 27 ]; then + let lines=filesize-27 + + # Get the top portion... + tail -n $lines /tmp/meetups.$$.ics > /tmp/meetups2.$$.ics + + # Now strip off END:VCALENDAR + let lines=filesize-27-1 + + head -n $lines /tmp/meetups2.$$.ics >> /tmp/calendar.$$.ics + + # Clean up meetups2 + rm -f /tmp/meetups2.$$.ics +fi + +# Now extract the middle of the next calendar +filesize=$(wc -l /tmp/tripit.$$.ics | cut -f1 -d' ') + +if [ $filesize -gt 27 ]; then + let lines=filesize-27 + + # Get the top portion... + tail -n $lines /tmp/tripit.$$.ics > /tmp/tripit2.$$.ics + + # Now strip off END:VCALENDAR + let lines=filesize-27-1 + + head -n $lines /tmp/tripit2.$$.ics >> /tmp/calendar.$$.ics + + # Cleanup tripit2 + rm -f /tmp/tripit2.$$.ics +fi + +# Now add END:VCALENDAR to calendar.ics +echo "END:VCALENDAR" >> /tmp/calendar.$$.ics + +# Move into place +mv /tmp/calendar.$$.ics ~/Documents/calendar.ics + +# Get rid of stupid CRs +dos2unix -q ~/Documents/calendar.ics + +# Restart rainlendar2 +export DISPLAY=:1 +killall rainlendar2 +rainlendar2 > /tmp/rainlendar2.log 2>&1 & + +# Cleanup +rm -rf \ + /tmp/meetups.$$.ics \ + /tmp/tripit.$$.ics \ + /tmp/updateCalendar.$$.log diff --git a/bin/updateSongbook.sh b/bin/updateSongbook.sh new file mode 100755 index 0000000..23bf599 --- /dev/null +++ b/bin/updateSongbook.sh @@ -0,0 +1,2 @@ +#!/bin/bash +ssh home "cd /opt/songbook && git pull && cd /opt/media && git pull"