aboutsummaryrefslogtreecommitdiff
path: root/local/bin
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-06-30 16:03:25 +0200
committerKarel Kočí <cynerd@email.cz>2016-06-30 16:03:25 +0200
commite573b3020c032400eed60b649a2cbf55266e6bb0 (patch)
tree8f572394ac8433529c7a8e70d160a2fbe8268b4e /local/bin
parentb8c667bd64b3edd38d56c63c5bd1db53a23b4499 (diff)
downloadmyconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.gz
myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.tar.bz2
myconfigs-e573b3020c032400eed60b649a2cbf55266e6bb0.zip
Add current configurations from old repository
Diffstat (limited to 'local/bin')
-rwxr-xr-xlocal/bin/mxrandr119
-rwxr-xr-xlocal/bin/system-backup58
2 files changed, 177 insertions, 0 deletions
diff --git a/local/bin/mxrandr b/local/bin/mxrandr
new file mode 100755
index 0000000..7c51128
--- /dev/null
+++ b/local/bin/mxrandr
@@ -0,0 +1,119 @@
+#!/bin/bash
+
+# get info from xrandr
+connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
+activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
+disconnectedOutputs=$(xrandr | grep -E " disconnected (primary )?[1-9]+" | awk '{print $1}')
+
+cmd="xrandr "
+cmd_def=$cmd
+
+INTERNAL=eDP1
+HDMI=HDMI1
+VGA=VGA1
+
+for device in "$disconnectedOutputs"; do
+ if [ -n "$defice" ]; then
+ if [[ "$activeOutput" == *"$device"* ]]; then
+ cmd=$cmd" --output $device --off"
+ fi
+ fi
+done
+
+function only_internal {
+ cmd=$cmd" --output $INTERNAL --auto --primary"
+ cmd=$cmd" --output $HDMI --off"
+ cmd=$cmd" --output $VGA --off"
+}
+
+function internal_vga {
+ cmd=$cmd" --output $INTERNAL --auto --primary"
+ cmd=$cmd" --output $HDMI --off"
+ cmd=$cmd" --output $VGA --auto --right-of $INTERNAL"
+}
+
+function internal_hdmi {
+ cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI"
+ cmd=$cmd" --output $HDMI --auto --primary"
+ cmd=$cmd" --output $VGA --off"
+}
+
+function internal_hdmi_vga {
+ cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI"
+ cmd=$cmd" --output $HDMI --auto --primary"
+ cmd=$cmd" --output $VGA --auto --left-of $HDMI"
+}
+
+function cmd_exec {
+ if [ "$cmd" != "$cmd_def" ]; then
+ echo $cmd
+ `$cmd`
+ fi
+}
+
+
+if [ $# -le 1 ]; then
+ if [[ "$connectedOutputs" == *"$HDMI"* ]]; then
+ if [[ "$connectedOutputs" == *"$VGA"* ]]; then
+ internal_hdmi_vga
+ else
+ internal_hdmi
+ fi
+ else
+ if [[ "$connectedOutputs" == *"$VGA"* ]]; then
+ internal_vga
+ else
+ only_internal
+ fi
+ fi
+ cmd_exec
+ exit
+fi
+
+if [ "$2" != "mode" ]; then
+ if [[ "$connectedOutputs" != *"$2"* ]]; then
+ echo No $2 display known
+ exit
+ fi
+fi
+
+case "$1" in
+ toggle)
+ case "$2" in
+ $INTERNAL)
+ if [[ "$activeOutput" == *"$INTERNAL"* ]]; then
+ cmd=$cmd" --output $INTERNAL --off"
+ else
+ if [[ "$activeOutput" == *"$HDMI"* ]]; then
+ cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI"
+ else
+ cmd=$cmd" --output $INTERNAL --auto --primary"
+ fi
+ fi
+ ;;
+ $HDMI)
+ if [[ "$activeOutput" == *"$HDMI"* ]]; then
+ cmd=$cmd" --output $HDMI --off"
+ else
+ if [[ "$activeOutput" == *"$VGA"* ]]; then
+ cmd=$cmd" --output $HDMI --auto --primary"
+ else
+ cmd=$cmd" --output $HDMI --auto --right-of $INTERNAL"
+ fi
+ fi
+ ;;
+ $VGA)
+ if [[ "$activeOutput" == *"$VGA"* ]]; then
+ cmd=$cmd" --output $VGA --off"
+ else
+ if [[ "$activeOutput" == *"$HDMI"* ]]; then
+ cmd=$cmd" --output $VGA --auto --left-of $HDMI"
+ else
+ cmd=$cmd" --output $VGA --auto --right-of $INTERNAL"
+ fi
+ fi
+ ;;
+ esac
+ ;;
+esac
+cmd_exec
diff --git a/local/bin/system-backup b/local/bin/system-backup
new file mode 100755
index 0000000..18b85bc
--- /dev/null
+++ b/local/bin/system-backup
@@ -0,0 +1,58 @@
+#!/bin/bash
+# vim:ft=sh
+# New line separated list of all directories to backup
+read -d '' DIRS <<-"_EOF_"
+/etc
+/home
+/home_hdd
+_EOF_
+# Directory where backup will be stored
+BACKUP=backup
+# Directory where backup will be mounted
+MBACKUP=/media/backup-hdd
+# UUID of disk
+UUID=21e0c8dd-77cc-44f1-b2bd-bb238d142e7f
+####################################################################
+# Check if running as root
+if [ `id -u` -ne "0" ]; then
+ echo Please run this as root.
+ exit 1
+fi
+# Mount backup disk if available
+PART=$(lsblk -fpl | grep "$UUID" | awk '{print $1}')
+if [ -z "$PART" ]; then
+ echo Disk not detected. Exiting
+ exit -1
+fi
+MPATH=$(lsblk -lp | grep "$PART" | awk '{print$7}')
+if [ -n "$MPATH" ]; then
+ echo Disk already mounted to $MPATH. Continuing with that.
+else
+ MPATH=$MBACKUP
+ mkdir -p "$MPATH"
+ mount "$PART" "$MPATH"
+fi
+
+mkdir -p "$MPATH/$BACKUP"
+while read -r DIR; do
+ echo Backing up: $DIR
+ rdiff-backup -b --exclude-device-files --exclude-fifos --exclude-sockets \
+ --terminal-verbosity=5 --print-statistics \
+ "$DIR" "$MPATH/$BACKUP/$(basename $DIR)/"
+ rdiff-backup --remove-older-than 100D --force \
+ --terminal-verbosity=5 --print-statistics \
+ "$MPATH/$BACKUP/$(basename $DIR)/"
+done <<< "$DIRS"
+
+# If we were mounting it, we should unmount it
+if [ "$MBACKUP" = "$MPATH" ]; then
+ umount "$MPATH"
+fi
+
+date +"%Y%m%d" > /home/cynerd/.backup_date
+pkill -RTMIN+13 i3blocks
+
+sync
+
+echo
+echo Backup finished