diff --git a/.bashrc b/.bashrc index b6be0b1f475e9f2c4a6f8bb2f972261e567af35d..eeda7c2861d7f95662846feb5aed28ece69cb433 100644 --- a/.bashrc +++ b/.bashrc @@ -65,10 +65,8 @@ alias deconcat="perl -pe 's/\\\\n/\\n/g'" alias ecr-login='eval $(aws ecr get-login --no-include-email)' alias hostlocal='docker run --rm --privileged --net=host gliderlabs/hostlocal' alias cadvisor='docker run --rm --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest' -alias __apt-daily="sudo /bin/sh -c 'apt-get update && apt-get dist-upgrade --download-only --yes && apt-get autoclean'" alias apt-daily="monitor __apt-daily" -alias __flatpak-daily='sudo flatpak update --assumeyes' -alias flatpak-daily="monitor __flatpak-daily" +alias flatpak-daily="sudo --preserve-env $(command -v monitor) flatpak update --assumeyes" 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='gunicorn httpbin:app' @@ -91,12 +89,14 @@ alias todo="vim \$HOME/Documents/TODO.yml" alias sudo="sudo " alias git="git " alias xargs="xargs " +alias monitor="monitor " +alias sudome="sudome " alias presentation='docker dev adarnimrod/presentation' alias prune_prerun='find "$HOME" -maxdepth 1 -name ".prerun\.[0-9]*" | grep -v "$(pgrep -u "$(id -u)" "$(basename "$SHELL" )" )" | xargs -r rm' alias netdata='docker run --detach --name netdata --cap-add SYS_PTRACE --volume /proc:/host/proc:ro --volume /sys:/host/sys:ro --volume /var/run/docker.sock:/var/run/docker.sock --publish 19999:19999 firehol/netdata:alpine' alias newman='docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/etc/newman" -t postman/newman_alpine33' alias http-server='python3 -m http.server 8080' -alias dd='monitor sudo dd status=progress' +alias dd='monitor dd status=progress' alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -delete' alias black='black --line-length 79' alias torrent_off='ssh xbmc.shore.co.il sudo systemctl stop transmission-{rss,daemon}.service' @@ -116,23 +116,6 @@ genpass () { head --bytes="$bytes" /dev/urandom | base64 --wrap=0 } -sudome () ( - eval "$(declare -F | sed 's/^declare/export/g')" - sudo -E "$SHELL" -c "$@" -) - -monitor () { - eval "$@" - code="$?" - if [ "$code" -eq 0 ] - then - notify-send "$(basename "${1#__}") has finished." - else - notify-send --urgency=critical "$(basename "${1#__}") has failed." - fi - return "$code" -} - jt () { if command -v pygmentize > /dev/null then diff --git a/Documents/bin/__apt-daily b/Documents/bin/__apt-daily new file mode 100755 index 0000000000000000000000000000000000000000..65258e080e0f4ceca66e840e4e98994b205ec0fb --- /dev/null +++ b/Documents/bin/__apt-daily @@ -0,0 +1,2 @@ +#!/bin/sh +exec sudo /bin/sh -c 'apt-get update && apt-get dist-upgrade --download-only --yes && apt-get autoclean' diff --git a/Documents/bin/monitor b/Documents/bin/monitor new file mode 100755 index 0000000000000000000000000000000000000000..5053f61d5520473839c1b842ee53c98762a41dc9 --- /dev/null +++ b/Documents/bin/monitor @@ -0,0 +1,24 @@ +#!/bin/sh +set -eu + +if ! command -v notify-send > /dev/null +then + notify="printf '\\a'" +elif [ "$(whoami)" = "root" ] && [ -n "${SUDO_USER:-}" ] +then + notify="sudo --preserve-env --set-home --user $SUDO_USER notify-send" +else + notify='notify-send' +fi + +eval "$@" || code="$?" +code="${code:-0}" + +if [ "$code" -eq 0 ] +then + $notify "$(basename "${1#__}") has finished." +else + $notify --urgency=critical "$(basename "${1#__}") has failed." +fi + +return "$code" diff --git a/Documents/bin/sudome b/Documents/bin/sudome new file mode 100755 index 0000000000000000000000000000000000000000..057826669ba45ee4a0b5f0620c1ee9b99654f0e5 --- /dev/null +++ b/Documents/bin/sudome @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu + +if command -v "$1" >/dev/null +then + executable="$(command -v "$1")" + shift + exec sudo --preserve-env --set-home "$executable" "$@" +else + exec sudo --preserve-env --set-home "$@" +fi