1
0
Fork 0

Merge branch 'master' of github.com:sbrl/bin

This commit is contained in:
Starbeamrainbowlabs 2017-01-30 22:13:41 +01:00
commit b7722c5a59
10 changed files with 265 additions and 1 deletions

View File

@ -1,3 +1,5 @@
dd if=/dev/zero status=progress bs=1M count=1024 | gzip -9 >bomb.gz
rsync -av --delete JBS\ SCH/ JBS\ Backup/
duplicity --encrypt-key 001E1725 --exclude /proc --exclude /sys --exclude /tmp --exclude /dev --exclude /mnt --exclude /var/cache --exclude /var/tmp --exclude /var/backups --exclude /srv/www-mail/rainloop/v / file:///mnt/hubic/default/ServerBackups/
inotifywait --event CLOSE_WRITE --monitor Wikitle.css | xargs -I {} csstidy Wikitle.css Wikitle.min.css --template=highest
letsencrypt certonly --webroot -w /srv/letsencrypt -d im.starbeamrainbowlabs.com -d starbeamrainbowlabs.com

View File

@ -39,6 +39,11 @@ Here's a list of the most interesting ones, along with what they do and where th
- [tldr](https://github.com/raylee/tldr) - A bash client for
[tldr-pages](https://github.com/tldr-pages/tldr).
- [git ignore](https://gitignore.io/) - A really useful subcommand for git that allows you to generate ignore files automagically.
- organise-photos - A small bash script I wrote that organises the photos in a directory by year & month.
- [ogg-cover-art](https://github.com/acabal/scripts/blob/master/ogg-cover-art) - A script that adds cover art to ogg files.
- senddir - A small script I wrote to send whole directories over the network as a temporary thing. Uses netcat + gzip + tar.
- recvdir - The counterpart to the above that receives the directory sent.
- brightness.sh - Another small script I've written that controls the brightness of my screen. It works for me, but it may not work for you.
## Disclaimer
I don't own many of the tools in this repository. If you are an owner of one of these tools and I haven't linked to you, please let me know as I probably forgot.

2
backup
View File

@ -5,6 +5,8 @@ then
echo Error: Not settings file specified!
echo Settings files are located in ~/.config/backups.
echo To use one, simply specify it\'s name. e.g. \'backup riftgate\' would use the \'~/.config/riftgate.config\' backup configuration file.
echo Backup configuration files detected:
ls ~/.config/backups
exit
fi

45
brightness.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
increment=10
backlight_prefix=/sys/class/backlight/intel_backlight/
echo $1
if [[ "$1" = "decrease" ]]; then
echo decreasing
increment=$(expr -${increment})
fi
cur_brightness=$(cat ${backlight_prefix}brightness)
max_brightness=$(cat ${backlight_prefix}max_brightness)
new_brightness=$(expr ${cur_brightness} + ${increment})
# Permissions changes on brightness:
## change group to sbrl
## add g+w
# Old command:
#gksudo -- bash -c "echo ${new_brightness} >${backlight_prefix}brightness"
echo ${new_brightness} >${backlight_prefix}brightness
####################
### Notification ###
####################
### uncomment the following line to disable the notification
#exit
# Calculate the percentage
new_percent=$(echo "(${new_brightness} / ${max_brightness}) * 100" | bc -l)
new_percent=$(printf "%.1f" "${new_percent}")
echo new_percent: $new_percent
max_bar_length=100
bar_length=$(echo "(${new_percent} / 100) * ${max_bar_length}" | bc -l)
bar_length=$(printf "%.0f" "${bar_length}")
n_bar=$(head -c $bar_length < /dev/zero | tr '\0' '=')
# Kill the previous notification
killall notify-osd
notify-send "Brightness: ${new_percent}%" "${n_bar} (${new_brightness})"
#notify-send "Brightness" "${new_percent}%"

BIN
cscz

Binary file not shown.

View File

@ -8,10 +8,13 @@ mv ~/.hh_favourites ~/.hh_favourites.bak
# Link to the new ones
ln -s ${BIN_DIR}/.bashrc ~/.bashrc
ln -s ${BIN_DIR}/.bash_aliases ~/.bash_aliases
ln -s ${BIN_DIR}/.hh_favourites ~/.hh_favourites
ln -s ${BIN_DIR}/.hh_favorites ~/.hh_favorites
# Copy the bash host file into place
cp ${BIN_DIR}/.bash_host ~
# Set up git
## Set the username & email address
git config --global user.name "Starbeamrainbowlabs"
git config --global user.email "sbrl@starbeamrainbowlabs.com"
## Add gitignore.io .gitignore file generator
git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'

128
ogg-cover-art Executable file
View File

@ -0,0 +1,128 @@
#!/bin/sh
usage(){
fmt <<EOF
DESCRIPTION
Add cover art to an OGG file.
Adapted from mussync-tools by biapy: https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
USAGE
ogg-cover-art [COVER-FILENAME] OGG-FILENAME
Add cover art to OGG-FILENAME. If COVER-FILENAME is not specified,
use cover.jpg, cover.jpeg, or cover.png located in the same folder
as OGG-FILENAME.
EOF
exit
}
die(){ printf "Error: ${1}\n" 1>&2; exit 1; }
require(){ command -v $1 > /dev/null 2>&1 || { suggestion=""; if [ ! -z "$2" ]; then suggestion=" $2"; fi; die "$1 is not installed.${suggestion}"; } }
if [ $# -eq 1 ]; then if [ "$1" = "--help" -o "$1" = "-h" ]; then usage; fi fi
#End boilerplate
require "vorbiscomment" "Try: apt-get install vorbis-tools"
if [ $# -eq 0 ]; then
usage
fi
outputFile=""
imagePath=""
if [ $# -eq 1 ]; then
outputFile="$1"
dirName=$(dirname "$1")
imagePath="${dirName}/cover.jpg"
if [ ! -f "${imagePath}" ]; then
imagePath="${dirName}/cover.jpeg"
if [ ! -f "${imagePath}" ]; then
imagePath="${dirName}/cover.png"
if [ ! -f "${imagePath}" ]; then
die "Couldn't find a cover image in ${dirName}."
fi
fi
fi
fi
if [ $# -eq 2 ]; then
outputFile="$2"
imagePath="$1"
fi
if [ ! -f "${outputFile}" ]; then
die "Couldn't find ogg file."
fi
if [ ! -f "${imagePath}" ]; then
die "Couldn't find cover image."
fi
imageMimeType=$(file -b --mime-type "${imagePath}")
if [ "${imageMimeType}" != "image/jpeg" -a "${imageMimeType}" != "image/png" ]; then
die "Cover image isn't a jpg or png image."
fi
oggMimeType=$(file -b --mime-type "${outputFile}")
if [ "${oggMimeType}" != "audio/x-vorbis+ogg" -a "${oggMimeType}" != "audio/ogg" ]; then
die "Input file isn't an ogg file."
fi
#Export existing comments to file
commentsPath="$(mktemp -t "tmp.XXXXXXXXXX")"
vorbiscomment --list --raw "${outputFile}" > "${commentsPath}"
#Remove existing images
sed -i -e '/^metadata_block_picture/d' "${commentsPath}"
#Insert cover image from file
#metadata_block_picture format
#See: https://xiph.org/flac/format.html#metadata_block_picture
imageWithHeader="$(mktemp -t "tmp.XXXXXXXXXX")"
description=""
#Reset cache file
echo -n "" > "${imageWithHeader}"
#Picture type <32>
printf "0: %.8x" 3 | xxd -r -g0 >> "${imageWithHeader}"
#Mime type length <32>
printf "0: %.8x" $(echo -n "${imageMimeType}" | wc -c) | xxd -r -g0 >> "${imageWithHeader}"
#Mime type (n * 8)
echo -n "${imageMimeType}" >> "${imageWithHeader}"
#Description length <32>
printf "0: %.8x" $(echo -n "${description}" | wc -c) | xxd -r -g0 >> "${imageWithHeader}"
#Description (n * 8)
echo -n "${description}" >> "${imageWithHeader}"
#Picture with <32>
printf "0: %.8x" 0 | xxd -r -g0 >> "${imageWithHeader}"
#Picture height <32>
printf "0: %.8x" 0 | xxd -r -g0 >> "${imageWithHeader}"
#Picture color depth <32>
printf "0: %.8x" 0 | xxd -r -g0 >> "${imageWithHeader}"
#Picture color count <32>
printf "0: %.8x" 0 | xxd -r -g0 >> "${imageWithHeader}"
#Image file size <32>
printf "0: %.8x" $(wc -c "${imagePath}" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "${imageWithHeader}"
#Image file
cat "${imagePath}" >> "${imageWithHeader}"
echo "metadata_block_picture=$(base64 --wrap=0 < "${imageWithHeader}")" >> "${commentsPath}"
#Update vorbis file comments
vorbiscomment --write --raw --commentfile "${commentsPath}" "${outputFile}"
#Delete temp files
rm "${imageWithHeader}"
rm "${commentsPath}"

56
organise-photos Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# This script takes all the jpg and mp4 files in a directory and
# organises them into a folder structure based on the month and year
# they were last modified (taken).
DRY_RUN=false
while test $# -gt 0
do
case "$1" in
--help)
echo organise-photos
echo " by Starbeamrainbowlabs <feedback@starbeamrainbowlabs.com>"
echo "This script takes all the jpg and mp4 files in a directory and organises them into a folder structure based on the month and year they were last modified (taken)."
echo
echo "Options:"
echo " --help"
echo " Show this help message"
echo " --dry-run"
echo " Do a dry run - don't actually move any files."
exit
;;
--dry-run)
echo Activating dry run mode.
DRY_RUN=true
esac
shift
done
find . -maxdepth 1 \( -iname "*.jpg" -o -iname "*.mp4" \) -print0 | while read -r -d '' filename
do
echo -ne "Processing ${filename} - ";
takenYear=$(date -r "${filename}" +%Y);
takenMonth=$(date -r "${filename}" +%-m);
takenMonthText=$(date -r "${filename}" +%B);
newFolder="${takenYear}/${takenMonth}-${takenMonthText}/";
newFilename="${newFolder}${filename}";
echo -ne "filing in ${newFolder} - ";
if [ "$DRY_RUN" = true ] ; then
echo dry run
continue
fi
mkdir -p "${newFolder}";
mv "${filename}" "${newFilename}";
echo Done\!;
done
echo "*** Complete! ***"
exit 0

12
recvdir Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
if [ "$#" -ne 2 ]; then
echo Recieve an entire directory from the network and save it to the current directory.
echo Shows recieving progress via pv. Note that the progress indicator is before compression has been removed.
echo Usage:
echo " recvdir ip_address port"
exit
fi
nc $1 $2 | pv | tar xzf -

11
senddir Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
if [ "$#" -ne 2 ]; then
echo Send an entire directory over the network.
echo Shows progress via pv - note that progress is measured before compress is added.
echo Usage:
echo " senddir directoryname listen_port_number"
exit
fi
tar cf - "${1}" | pv | gzip | nc -l $2