Skip to content
Snippets Groups Projects
Commit dcf0cc3b authored by nimrod's avatar nimrod
Browse files

Working monitor with sudo.

- Moved `monitor` from a shell function to a script, now it's callable
without mocking with the shell. Also, added an alias for `monitor` to
expand aliases after it.
- `sudome` is now a shell script instead of a function, now it works
around the `secure_path` option by trying to find the executable in the
path before calling `sudo`. Also, added an alias for `sudome` to expand
aliases after it.
- `__apt-daily` is now a shell script, it probably could have stayed a
shell alias but the quotes failed to pass the entire command to
`/bin/sh` as it was and I couldn't be arsed to solve it.
- Simplified `flatpak-daily`.
- `dd` shell alias is simpler and now the invocation `sudome dd` works
as expected (which was the whole point to begin with).
parent 23a145b4
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#!/bin/sh
exec sudo /bin/sh -c 'apt-get update && apt-get dist-upgrade --download-only --yes && apt-get autoclean'
#!/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"
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment