2022-08-19 14:52:07 +00:00
|
|
|
#!/bin/sh
|
2022-08-23 12:13:40 +00:00
|
|
|
case "$-" in
|
|
|
|
*i*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# Shell is not interactive.
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-08-19 14:52:07 +00:00
|
|
|
if [ -d /var/acp ]
|
|
|
|
then
|
|
|
|
export ACP=/var/acp
|
|
|
|
else
|
|
|
|
export ACP="$HOME/data"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up XDG variables. See:
|
|
|
|
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
2022-08-23 12:44:31 +00:00
|
|
|
if [ ! -d "$XDG_DATA_HOME" ] ; then install -d -m 0700 "$XDG_DATA_HOME" ; fi
|
|
|
|
if [ ! -d "$XDG_CACHE_HOME" ] ; then install -d -m 0700 "$XDG_CACHE_HOME" ; fi
|
|
|
|
if [ ! -d "$XDG_CONFIG_HOME" ] ; then install -d -m 0700 "$XDG_CONFIG_HOME" ; fi
|
|
|
|
if [ ! -d "$XDG_STATE_HOME" ] ; then install -d -m 0700 "$XDG_STATE_HOME" ; fi
|
2022-08-31 14:40:04 +00:00
|
|
|
if [ ! -d "$XDG_RUNTIME_DIR" ] ; then install -d -m 0700 "$XDG_RUNTIME_DIR" ; fi
|
2022-08-19 14:52:07 +00:00
|
|
|
if [ ! -d "$HOME/.local/bin" ] ; then install -d -m 0700 "$HOME/.local/bin" ; fi
|
|
|
|
|
|
|
|
_acp_add_path () {
|
|
|
|
if [ -n "$1" ] && [ -d "$1" ]
|
|
|
|
then
|
|
|
|
case ":$PATH:" in
|
|
|
|
*:"$1":*)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PATH="$1:$PATH"
|
|
|
|
export PATH
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Last in the list means first in the path.
|
|
|
|
for dir in "$HOME/.local/bin" \
|
|
|
|
"$HOME/.cargo/bin" \
|
|
|
|
"$XDG_DATA_HOME/gem/ruby/bin" \
|
|
|
|
"$XDG_DATA_HOME/flatpak/exports/bin" \
|
|
|
|
/opt/local/bin \
|
|
|
|
/opt/local/sbin \
|
|
|
|
/var/lib/flatpak/exports/bin \
|
|
|
|
/usr/local/bin \
|
|
|
|
/usr/local/sbin \
|
|
|
|
/usr/bin \
|
|
|
|
/usr/sbin
|
|
|
|
do
|
|
|
|
_acp_add_path "$dir"
|
|
|
|
done
|
|
|
|
|
|
|
|
umask 0022
|
|
|
|
|
|
|
|
# Other exports.
|
2022-08-31 14:11:04 +00:00
|
|
|
export PS1="${PS1:-\$ }"
|
2022-08-31 14:32:03 +00:00
|
|
|
export HISTFILE=""
|
2022-08-23 12:44:31 +00:00
|
|
|
export TIME_STYLE=long-iso # Used by GNU 'ls'.
|
2022-08-19 14:52:07 +00:00
|
|
|
|
|
|
|
if [ "$(uname -s)" = Darwin ]
|
|
|
|
then
|
|
|
|
export BASH_SILENCE_DEPRECATION_WARNING=1
|
|
|
|
fi
|
|
|
|
|
2022-08-23 12:44:31 +00:00
|
|
|
# Override this in "$XDG_CONFIG_HOME/shrc.local" or "$HOME/.ssh/config".
|
2022-08-19 14:52:07 +00:00
|
|
|
export LIBVIRT_DEFAULT_URI="qemu+ssh://vmhost/system"
|
|
|
|
|
|
|
|
if test -x /usr/bin/tty
|
|
|
|
then
|
|
|
|
GPG_TTY=$(tty)
|
|
|
|
export GPG_TTY
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up Vi/Vim.
|
|
|
|
if command -v vim > /dev/null
|
|
|
|
then
|
|
|
|
export EDITOR="vim -f"
|
|
|
|
alias vi=vim
|
|
|
|
else
|
|
|
|
export EDITOR=vi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(id -u)" -ne 0 ] && [ -x /usr/bin/dnf ]
|
|
|
|
then
|
|
|
|
alias dnf="dnf --cacheonly --nogpgcheck"
|
|
|
|
fi
|
|
|
|
|
|
|
|
alias 7zencrypt="7z a -t7z -p -mhe"
|
|
|
|
alias alu="apt list --upgradable"
|
|
|
|
alias asdo="apt source --download-only"
|
|
|
|
alias aurmake="makepkg -irs"
|
|
|
|
alias f=fossil
|
|
|
|
alias ip="ip -c"
|
|
|
|
alias isocal="cal --iso --reform=iso --monday --week"
|
|
|
|
alias la="ls -a"
|
|
|
|
alias ll="ls -l"
|
|
|
|
alias ls="command ls -F"
|
|
|
|
alias now="date +%Y%m%dT%H%M%S%z"
|
|
|
|
alias nowu="date -u +%Y%m%dT%H%M%SZ"
|
|
|
|
alias streamenc="openssl aes-256-cbc -pbkdf2 -in - -out - -e"
|
|
|
|
alias streamdec="openssl aes-256-cbc -pbkdf2 -in - -out - -d"
|
|
|
|
alias wgr=wordgrinder
|
|
|
|
alias ytmp3="youtube-dl -q -x --audio-format=mp3"
|
|
|
|
alias zlu="zypper list-updates"
|
|
|
|
|
|
|
|
# Language aliases.
|
|
|
|
alias en="LANG=en_GB.UTF-8"
|
|
|
|
alias fr="LANG=fr_FR.UTF-8"
|
|
|
|
|
|
|
|
# Alias dig to drill if dig is not installed.
|
|
|
|
if [ -x /usr/bin/drill ]
|
|
|
|
then
|
|
|
|
alias dig=drill
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up Go.
|
|
|
|
if [ -x "$ACP/opt/go/bin/go" ] || [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ]
|
|
|
|
then
|
|
|
|
export GOPROXY=https://proxy.golang.org
|
|
|
|
export GOPATH="$XDG_DATA_HOME/go"
|
|
|
|
if [ ! -d "$GOPATH" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$GOPATH/bin"
|
|
|
|
mkdir -p "$GOPATH/pkg"
|
|
|
|
mkdir -p "$GOPATH/src"
|
|
|
|
fi
|
|
|
|
if [ -x "$ACP/opt/go/bin/go" ]
|
|
|
|
then
|
|
|
|
export GOROOT="$ACP/opt/go"
|
|
|
|
_acp_add_path "$GOROOT/bin"
|
|
|
|
fi
|
|
|
|
_acp_add_path "$GOPATH/bin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
alias prun='podman run --rm --interactive --tty --security-opt label=disable --volume "$HOME":"$HOME" --volume "$XDG_RUNTIME_DIR":"$XDG_RUNTIME_DIR" --env XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" --env XDG_SESSION_TYPE=wayland --ipc host'
|
|
|
|
alias pruncerts='prun --volume /etc/pki/ca-trust:/etc/pki/ca-trust:ro --volume /etc/ssl/certs:/etc/ssl/certs:ro'
|
|
|
|
|
2022-08-25 10:31:58 +00:00
|
|
|
if command -v ssh-agent > /dev/null
|
2022-08-25 09:30:17 +00:00
|
|
|
then
|
2022-08-31 14:40:04 +00:00
|
|
|
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-$XDG_RUNTIME_DIR/ssh-agent.socket}"
|
|
|
|
export SSH_AGENT_PID="${SSH_AGENT_PID:-$XDG_RUNTIME_DIR/ssh-agent.pid}"
|
2022-08-25 10:31:58 +00:00
|
|
|
if [ ! -S "$SSH_AUTH_SOCK" ]
|
|
|
|
then
|
2022-08-29 20:24:49 +00:00
|
|
|
ssh-agent -a "$SSH_AUTH_SOCK" > /dev/null
|
2022-08-25 10:31:58 +00:00
|
|
|
fi
|
2022-08-25 09:30:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-19 14:52:07 +00:00
|
|
|
mkcd () {
|
|
|
|
if [ $# -ne 1 ]
|
|
|
|
then
|
|
|
|
echo "mkcd: incorrect arguments (one directory required)." >&2
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
mkdir -p "$1"
|
|
|
|
cd "$1" || return
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
linapm () {
|
|
|
|
cat /sys/class/power_supply/BAT0/status
|
|
|
|
cat /sys/class/power_supply/BAT0/capacity
|
|
|
|
}
|
|
|
|
|
|
|
|
xa () {
|
|
|
|
out=$(xrandr --listactivemonitors | awk 'NR!=1{print " "$NF" "}')
|
|
|
|
for monitor in $out
|
|
|
|
do
|
|
|
|
m=$(echo "$monitor" | sed 's/ //g')
|
|
|
|
xrandr --output "$m" --auto
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
emacsro () {
|
|
|
|
emacs "$1" -f view-mode
|
|
|
|
}
|
|
|
|
|
|
|
|
tm () {
|
|
|
|
if tmux list-sessions > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
tmux attach-session
|
|
|
|
else
|
|
|
|
tmux new-session
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -x /usr/bin/yum ] && [ ! -x /usr/bin/dnf ]
|
|
|
|
then
|
|
|
|
alias dnf=yum
|
|
|
|
fi
|
|
|
|
|
|
|
|
usermotd () {
|
|
|
|
# OS (kernel) name and version in reverse video.
|
2022-08-19 15:06:06 +00:00
|
|
|
printf "\033[7m$(uname -sr)\033[0m\n"
|
2022-08-19 14:52:07 +00:00
|
|
|
|
|
|
|
# Distro name and version on Linux and macOS.
|
|
|
|
if [ -r /etc/os-release ]
|
|
|
|
then
|
|
|
|
echo " $(. /etc/os-release; echo "$NAME" "$VERSION")"
|
|
|
|
fi
|
|
|
|
if [ "$(uname -s)" = "Darwin" ]
|
|
|
|
then
|
|
|
|
echo " $(sw_vers -productName) $(sw_vers -productVersion)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# System uptime and load averages.
|
|
|
|
uptime
|
|
|
|
|
2022-08-25 10:23:13 +00:00
|
|
|
# SSH keys.
|
|
|
|
if command -v ssh-add > /dev/null
|
|
|
|
then
|
|
|
|
ssh-add -l
|
|
|
|
fi
|
|
|
|
|
2022-08-19 14:52:07 +00:00
|
|
|
# Language for the shell.
|
|
|
|
echo "LANG=$LANG"
|
|
|
|
|
|
|
|
# Timezone.
|
|
|
|
if [ -n "$TZ" ]
|
|
|
|
then
|
|
|
|
echo "TZ=$TZ"
|
|
|
|
elif [ -x /usr/bin/timedatectl ] && [ "$(systemctl is-system-running)" != offline ]
|
|
|
|
then
|
|
|
|
timedatectl show --property=Timezone | sed 's/Timezone=/TZ=/'
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Shell name and version.
|
|
|
|
if [ -n "$BASH_VERSION" ]
|
|
|
|
then
|
|
|
|
echo "bash $BASH_VERSION"
|
|
|
|
elif [ -n "$ZSH_VERSION" ]
|
|
|
|
then
|
|
|
|
echo "zsh $ZSH_VERSION"
|
|
|
|
else
|
2022-08-19 15:08:06 +00:00
|
|
|
echo "SHELL=$SHELL"
|
2022-08-19 14:52:07 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
simpletls () {
|
|
|
|
# Create a self-signed certificate with:
|
|
|
|
# openssl req -new -x509 \
|
|
|
|
# -keyout $ACP/openssl/$(hostname)-key.pem \
|
|
|
|
# -out $ACP/openssl/$(hostname-cert.pem
|
|
|
|
if [ "$1" = "-l" ]
|
|
|
|
then
|
|
|
|
openssl s_server -cert "$ACP/openssl/$(hostname)-cert.pem" -key "$HOME/data/openssl/$(hostname)-key.pem" -tls1_3 -port "$2"
|
|
|
|
else
|
|
|
|
openssl s_client -CAfile "$ACP/openssl/$1-cert.pem" -tls1_3 -connect "$1":"$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
tlscheck () {
|
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
echo "Usage: tlscheck hostname:port" >&2
|
|
|
|
else
|
|
|
|
openssl s_client -connect "$1" </dev/null | openssl x509 -text
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-08-23 12:44:31 +00:00
|
|
|
if [ -r "$XDG_CONFIG_HOME/shrc.local" ]
|
|
|
|
then
|
|
|
|
. "$XDG_CONFIG_HOME/shrc.local"
|
|
|
|
fi
|
|
|
|
|
2022-08-23 12:13:40 +00:00
|
|
|
usermotd
|