diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/backup.sh | 9 | ||||
| -rwxr-xr-x | scripts/change_fan.sh | 79 | ||||
| -rwxr-xr-x | scripts/format_displays.sh | 83 |
3 files changed, 171 insertions, 0 deletions
diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100755 index 0000000..caf5b7b --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +## +# Create full tree backups to specified media + +GLOBAL_MEDIA_BLOCK=$1 + +echo "Beginning rsync full system backup / -> $GLOBAL_MEDIA_BLOCK" +rsync -SHaAX --delete --info=progress2 --exclude={"/dev/*", "/proc/*", "/sys/*", "/tmp/*", "/run/*", "/mnt/*", "/lost+found"} / $1 diff --git a/scripts/change_fan.sh b/scripts/change_fan.sh new file mode 100755 index 0000000..b290700 --- /dev/null +++ b/scripts/change_fan.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +## It would be nice to check the system and dynamically figure out which fan controller +## is being used...but I don't need that right now. + +# echo "1" > /sys/devices/platform/applesmc.768/fan1_manual +# echo "9000" > /sys/devices/platform/applesmc.768/fan1_output +# cat /sys/devices/platform/applesmc.768/fan1_output + +FAN_DIR=/sys/devices/platform/applesmc.768 +FAN_OUT=$FAN_DIR/fan1_output +FAN_MANUAL=$FAN_DIR/fan1_manual +MAX_FAN=$(cat $FAN_DIR/fan1_max) +MIN_FAN=$(cat $FAN_DIR/fan1_min) + +function toggle_mbpfan() { + SHOULD_DEACTIVE=$1 + IS_ACTIVE=$(systemctl is-active mbpfan) + if [[ "$SHOULD_DEACTIVE" == "false" ]]; then + echo "force deactive!" + echo "0" > "$FAN_MANUAL" + sudo systemctl start mbpfan + return + elif [[ "$IS_ACTIVE" == "active" || "$SHOULD_DEACTIVE" == "true" ]]; then + sudo systemctl stop mbpfan + echo "force active!" + echo "1" > "$FAN_MANUAL" + return + else + echo "force deactive and start mbpfan" + echo "there!" + echo "0" > "$FAN_MANUAL" + sudo systemctl start mbpfan + return + fi +} + +function increase_fan() { + CURR_SPEED=$(cat $FAN_DIR/fan1_output) + NEXT_SPEED=$(echo - | awk -v curr="$CURR_SPEED" '{printf "%1.0f", (curr + 500)}') + + # deactivate mbpfan + toggle_mbpfan "true" + + if [[ $NEXT_SPEED -lt $MAX_FAN ]]; then + echo $NEXT_SPEED > "$FAN_OUT" + else + echo $MAX_FAN > "$FAN_OUT" + fi +} + +function decrease_fan() { + CURR_SPEED=$(cat $FAN_DIR/fan1_output) + NEXT_SPEED=$(echo - | awk -v curr="$CURR_SPEED" '{printf "%1.0f", (curr - 500)}') + + # deactivate mbpfan + toggle_mbpfan "true" + + if [[ $NEXT_SPEED -gt $MIN_FAN ]]; then + echo $NEXT_SPEED > "$FAN_OUT" + else + # no reason to ever this low. + # let the system take back over, since the user probably forgot + toggle_mbpfan "false" + fi +} + +while getopts ":idt" opt; do + case ${opt} in + t) toggle_mbpfan + ;; + i) increase_fan + ;; + d) decrease_fan + ;; + \? ) + ;; + esac +done diff --git a/scripts/format_displays.sh b/scripts/format_displays.sh new file mode 100755 index 0000000..acb2638 --- /dev/null +++ b/scripts/format_displays.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# get the displays which are connected and setup an associative array +DISPLAYS=( $(xrandr | grep " connected" | awk '{print $1}') ) +declare -A DISP_RES + +BG_IMG="~/.setup/des/i3/assets/wallpaper/yosemite_color_block.png" + +VERBOSE="" +if_echo () { + if [ -n "$VERBOSE" ]; then + echo $1 + fi +} + +while getopts ":h" opt; do + case ${opt} in + h ) VERBOSE="on" + ;; + \? ) echo "read the script for help; -v for verbose logging" + ;; + esac +done + +for (( i=0; i <${#DISPLAYS[@]}; i++ )); do + # store the assocated resolutions + DISPLAY_NAME=${DISPLAYS[i]} + DISP_RES["$DISPLAY_NAME"]=$(xrandr | grep "^$DISPLAY_NAME" -A 1 | tail -n 1 | awk '{print $1}') +done + +# We setup a consistent monitor ordering as follows... +# ----- ----- ------ ------ +# | DP-1 | | DP-2 | | HDMI-1 | | HDMI-2 | +# ----- ----- ------ ------ +# \ \ / / +# \ | | / +# \ ----- / +# \ | eDP-1 |----/ +# _____ + +EDP_1=${DISP_RES["eDP-1"]} +DP_1=${DISP_RES["DP-1"]} +DP_2=${DISP_RES["DP-2"]} +HDMI_1=${DISP_RES["HDMI-1"]} + +if [ -n "$EDP_1" ]; then + # if no other displays are set, then we bring all windows into eDP-1 + if [[ -z "$DP_1" && -z "$DP_2" && -z "$HDMI_1" ]]; then + if_echo "No displays detected. Resetting primary display (eDP-1)" + xrandr --auto + else + if_echo "Found other displays, and explicitly setting primary display (eDP-1)" + xrandr --output eDP-1 --mode "$EDP_1" + fi +fi + +if [ -n "$DP_1" ]; then + if_echo "Found DP-1. Setting DP-1 above primary display (eDP-1)" + xrandr --output DP-1 --mode "$DP_1" --above eDP-1 +fi + +if [[ -n "$DP_2" && -n "$DP_1" ]]; then + if_echo "Found DP-2. Setting DP-2 right of DP-1" + xrandr --output DP-2 --mode "$DP_2" --right-of DP-1 +elif [[ -n "$DP_2" ]]; then + if_echo "Found DP-2 but not DP-1. Setting DP-2 above primary display (eDP-1)" + xrandr --output DP-2 --mode "$DP_2" --above eDP-1 +fi + +if [[ -n "$HDMI_1" && -n "$DP_2" && "$DP_1" ]]; then + if_echo "Found HDMI-1. Setting it right of DP-2" + xrandr --output HDMI-1 --mode "$HDMI_1" --right-of DP-2 +elif [[ -n "$HDMI_1" && ( "$DP_2" || "$DP_1" ) ]]; then + if [ -n "$DP_2" ]; then + if_echo "Found HDMI-1 and DP-2 but not DP-1. Setting HDMI-1 right of DP-2" + xrandr --output HDMI-1 --mode "$HDMI_1" --right-of DP-2 + else + if_echo "Found HDMI-1 and DP-1 but not DP-2. Setting HDMI-1 right of DP-1" + xrandr --output HDMI-1 --mode "$HDMI_1" --right-of DP-1 + fi +fi + +feh bg-fill "$IMG" |
