diff --git a/.bashrc b/.bashrc index b95093d1efb661b76c1a49e3fea6c9c1b8ff1183..f98e6cd23bd292bcf2dbb313f26fef5c4e808a51 100644 --- a/.bashrc +++ b/.bashrc @@ -88,6 +88,7 @@ alias cdtemp='cd $(mktemp -d)' alias 0-day-cleanup='ssh xbmc.shore.co.il "sudo -u debian-transmission find /srv/library/Comics -name *.part -path *0-Day\ Week\ of* -delete"' alias httpbin='tox -c $HOME/.tox.ini.httpbin --' alias update-requirements='find -name "*requirements*.txt" -exec pur --requirement {} \;' +alias restart-kodi='ssh xbmc.shore.co.il "sudo systemctl kill --kill-who all xorg.service"' deduce_aws_region () { AWS_DEFAULT_REGION="$(curl --silent \ diff --git a/.cargo/bin/.gitkeep b/.config/dconf.ini similarity index 100% rename from .cargo/bin/.gitkeep rename to .config/dconf.ini diff --git a/.githooks/post-merge b/.githooks/post-merge index be076ab03a78a600c2ef59517d7b3d05158421ca..0c269552a3c624ff4fdfa22f22e428d578cbe942 100755 --- a/.githooks/post-merge +++ b/.githooks/post-merge @@ -3,3 +3,5 @@ set -eu cd "$(git rev-parse --show-toplevel)" echo Generating SSH config Documents/bin/gen-ssh-config +echo Loading dconf config +Documents/bin/dconf-load diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 358618cceb2f64acdf8949c33ff930ceb045f457..f0c301277e3fdfdab306baaed582b650fd2fb9d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ - repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.7.1 + sha: v0.8.0 hooks: - id: check-added-large-files - id: check-merge-conflict @@ -9,6 +9,6 @@ sha: v0.5.4 hooks: - id: shell-lint - files: &shellscripts 'bashrc|post-merge|profile|docker-|train-wifi|renew-certs|dma-clean|gen-ssh-config' + files: &shellscripts 'bashrc|post-merge|profile|docker-|train-wifi|renew-certs|dma-clean|gen-ssh-config|dconf-load|kavim-wifi' - id: shellcheck files: *shellscripts diff --git a/Documents/.gitkeep b/Documents/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Documents/bin/dconf-load b/Documents/bin/dconf-load new file mode 100755 index 0000000000000000000000000000000000000000..84b1cd11dc627dc713885853c426566ede706480 --- /dev/null +++ b/Documents/bin/dconf-load @@ -0,0 +1,10 @@ +#!/bin/sh +set -eu + +if ! which dconf > /dev/null +then + echo "Can't find dconf, exiting." + exit 0 +fi + +dconf-load < "$HOME/.config/dconf.ini" diff --git a/Documents/bin/kavim-wifi b/Documents/bin/kavim-wifi new file mode 100755 index 0000000000000000000000000000000000000000..bc091d46aeda76c11760a0109b0a75bc3d176063 --- /dev/null +++ b/Documents/bin/kavim-wifi @@ -0,0 +1,77 @@ +#!/bin/sh +# The MIT License (MIT) +# +# Copyright (c) 2017 Adar Nimrod <nimrod@shore.co.il> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Logs in to the Israeli train's wifi. +# Requires: cURL, sh, awk, logger, nmcli. +# To install, clone the repo, cd to this directory and run: +# +# sudo cp --preserve=mode kavim-wifi /etc/NetworkManager/dispatcher.d/90kavimwifi +# +# If you don't want to clone the repo but you just want this script, run: +# +# curl https://www.shore.co.il/cgit/rcfiles/plain/Documents/bin/train-wifi | sudo tee /etc/NetworkManager/dispatcher.d/90trainwifi +# sudo chmod +x /etc/NetworkManager/dispatcher.d/90trainwifi + +set -eu + +die () { + logger -p user.err "$@" + exit 1 +} + +iswifi () { + # TODO: Check if a network interface is passed. + [ "$(nmcli --terse --fields GENERAL.TYPE device show "$1" | awk -F: '{print $2}')" = 'wifi' ] +} + +wifi_connection () { + nmcli --terse --fields GENERAL.CONNECTION device show "$1" | awk -F: '{print $2}' +} + +if [ $# -ne 2 ] +then + echo "Usage: $0 interface action" + exit 1 +else + interface="$1" + action="$2" +fi + +which curl > /dev/null || die "Can't login to the kavim wifi, cURL is not installed." +which awk > /dev/null || die "Can't login to the kavim wifi, awk is not installed." +which logger > /dev/null || die "Can't login to the kavim wifi, logger is not installed." +which nmcli > /dev/null || die "Can't login to the kavim wifi, nmcli is not installed." + +[ "$action" = 'up' ] || die "Can't login to the kavim wifi, action $action isn't up." +iswifi "$interface" || die "Can't login to the kavim wifi, interface $interface isn't wifi." +connection="$(wifi_connection "$interface")" +[ "$connection" = "Kavim-wifi" ] || die "Can't login to the kavim wifi, wifi network $connection isn't ISRAEL-RAILWAYS." + +redirect_url="$(curl --output /dev/null --silent --write-out '%{redirect_url}' http://detectportal.firefox.com/success.txt)" +logger -p user.debug "Train wifi redirect url: $redirect_url" +login_ip="$(echo "$redirect_url" | grep --only-matching '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')" || die "Can't login to the kavim wifi, redirect URL doesn't contain an IP." +logger -p user.debug "Train wifi login IP: $login_ip" +login_url="http://$login_ip/loginHandler.php?allowAccess=true" +logger -p user.debug "Train wifi login URL: $login_url" +http_code="$(curl --output /dev/null --silent --write-out '%{http_code}' "$login_url")" +logger -p user.debug "Train wifi login HTTP code: $http_code" diff --git a/Documents/bin/pocketchip-battery b/Documents/bin/pocketchip-battery new file mode 100755 index 0000000000000000000000000000000000000000..6a66cfc743a007b736c6f5b8f33ec3c240e4a852 --- /dev/null +++ b/Documents/bin/pocketchip-battery @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +current="$(cat /usr/lib/pocketchip-batt/voltage)" + +. "$HOME/.local/voltage" + +echo $(( 100 * (current - min) / (max - min) )) diff --git a/Documents/bin/update-voltage b/Documents/bin/update-voltage new file mode 100755 index 0000000000000000000000000000000000000000..83e3f49a644164299f676c91c5de3dfe6980d397 --- /dev/null +++ b/Documents/bin/update-voltage @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu +# To install, add the folowing lines to your crontab: +# PATH="~/Documents/bin:/usr/local/bin:/usr/bin:/bin" +# */5 * * * * update-voltage + +filepath="$HOME/.local/voltage" + +update_voltage () { + echo "min=$1" > "$filepath" + echo "max=$2" >> "$filepath" +} + +current="$(cat /usr/lib/pocketchip-batt/voltage)" + +mkdir -p "$(dirname "$filepath" )" + +if [ ! -f "$filepath" ] +then + update_voltage "$current" "$current" + exit 0 +fi + +. "$filepath" + +if [ "$current" -gt "$max" ] +then + max="$current" + update_voltage "$min" "$max" +elif [ "$current" -lt "$min" ] +then + min="$current" + update_voltage "$min" "$max" +fi