Merge branch 'shadowarch.sh-refactor'

This commit is contained in:
DarkFeather 2024-02-28 14:47:45 -06:00
commit e3be67286d
Signed by: DarkFeather
GPG Key ID: 1CC1E3F4ED06F296
9 changed files with 135 additions and 193 deletions

View File

@ -1,5 +1,3 @@
httpRoot = ${pkgdir}/srv/http/aninix.net
httpUser = http
syncList = profile.d tmux.conf syncList = profile.d tmux.conf
userServiceList = tmux.service userServiceList = tmux.service
@ -8,17 +6,17 @@ compile: ./shadowarch ${syncList} ${userServiceList} ./shadowarch.vim ./skel
install: compile install: compile
mkdir -p ${pkgdir}/etc/ mkdir -p ${pkgdir}/etc/
mkdir -p ${pkgdir}/usr/lib/systemd/user
mkdir -p ${pkgdir}/usr/share/vim/vimfiles/plugin/
for i in ${syncList}; do cp -r "$$i" ${pkgdir}/etc/; chmod -R a+r "${pkgdir}/etc/$$i"; done
for i in ${userServiceList}; do cp "$$i" ${pkgdir}/usr/lib/systemd/user/"$$i"; done
cp ./shadowarch.vim ${pkgdir}/usr/share/vim/vimfiles/plugin/shadowarch.vim
cp -pr ./skel ${pkgdir}/etc cp -pr ./skel ${pkgdir}/etc
mkdir -p ${pkgdir}/usr/lib/systemd/user
for i in ${userServiceList}; do cp "$$i" ${pkgdir}/usr/lib/systemd/user/"$$i"; done
mkdir -p ${pkgdir}/etc/pacman.d/hooks
mkdir -p ${pkgdir}/usr/share/vim/vimfiles/plugin/
cp ./shadowarch.vim ${pkgdir}/usr/share/vim/vimfiles/plugin/shadowarch.vim
for i in ${syncList}; do cp -r "$$i" ${pkgdir}/etc/; chmod -R a+r "${pkgdir}/etc/$$i"; done
if [ `uname -r | grep -c arch` -eq 1 ]; then mkdir -p ${pkgdir}/usr/share/pacman/keyrings; cp aninix.gpg ${pkgdir}/usr/share/pacman/keyrings; fi if [ `uname -r | grep -c arch` -eq 1 ]; then mkdir -p ${pkgdir}/usr/share/pacman/keyrings; cp aninix.gpg ${pkgdir}/usr/share/pacman/keyrings; fi
checkperm: ${syncList} checkperm: ${syncList}
printf "What is your deprivileged user? "; read user; chown -R ${user}:${user} . printf "What is your deprivileged user? "; read user; chown -R ${user}:${user} .
if [ -f ${httpRoot}/shadowarch ]; then chmod 0755 ${httpRoot}/shadowarch; chown ${httpUser} ${httpRoot}/shadowarch; fi
chown -R root:root ${syncList} chown -R root:root ${syncList}
for i in ${syncList}; do if [ -f "${i}" ]; then chmod 0644 "${i}"; elif [ -d "${i}" ]; then chmod 0755 "${i}"; fi; done for i in ${syncList}; do if [ -f "${i}" ]; then chmod 0644 "${i}"; elif [ -d "${i}" ]; then chmod 0755 "${i}"; fi; done
@ -27,20 +25,15 @@ test:
bash ./shadowarch -h bash ./shadowarch -h
echo Success. echo Success.
reverse: ${httpRoot}/shadowarch ${syncList} reverse: ${syncList}
cat ${httpRoot}/shadowarch > ./shadowarch
for i in ${syncList}; do rsync -avz ${syncList} .; done for i in ${syncList}; do rsync -avz ${syncList} .; done
for i in ${userServiceList}; do rsync -avz /usr/lib/systemd/user/${userServiceList} .; done for i in ${userServiceList}; do rsync -avz /usr/lib/systemd/user/${userServiceList} .; done
rsync --delete-before -avz ${pkgdir}/etc/skel ./skel rsync --delete-before -avz ${pkgdir}/etc/skel ./skel
clean: clean:
@echo Nothing to do. git clean -fdX
diff: ${syncList} diff: ${syncList}
if [ -f ${httpRoot}/shadowarch ]; then diff ./shadowarch ${httpRoot}/shadowarch; echo; fi if [ -f ${httpRoot}/shadowarch ]; then diff ./shadowarch ${httpRoot}/shadowarch; echo; fi
for i in ${syncList}; do diff -rc "$$i" ./`echo $$i | rev | cut -f 1 -d '/' | rev`; echo; done for i in ${syncList}; do diff -rc "$$i" ./`echo $$i | rev | cut -f 1 -d '/' | rev`; echo; done
diff -rc ${pkgdir}/etc/skel ./skel; printf "" diff -rc ${pkgdir}/etc/skel ./skel; printf ""
find-missing-hooks-in-src:
@for i in `wget -q -O - https://aninix.net/foundation/ | grep toplevel-repo | cut -f 4 -d \'`; do if [ -z $$i ]; then continue; fi; for file in `find ../.. -type f -name Makefile | grep $$i`; do if [ -z "$$file" ]; then echo NO MAKEFILE FOR $$i; elif [ `grep -c -i 'hook for systemd' $$file` -eq 0 ]; then echo HOOK MISSING IN: $$file; else echo HOOK FOUND IN: $$file; fi; done; done
@for i in `wget -q -O - https://aninix.net/foundation/ | grep toplevel-repo | cut -f 4 -d \'`; do if [ -z $$i ]; then continue; fi; for file in `find ../.. -type f -name Makefile | grep $$i`; do if [ -z "$$file" ]; then echo NO MAKEFILE FOR $$i; elif [ `grep -c useradd $$file` -eq 0 ]; then echo DEPRIV MISSING IN: $$file; else echo DEPRIV FOUND IN: $$file; fi; done; done

View File

@ -1,59 +0,0 @@
# /etc/profile
#Set our umask
umask 022
# Append "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
append_path () {
case ":$PATH:" in
*:"$1":*)
;;
*)
PATH="${PATH:+$PATH:}$1"
esac
}
# Append our default paths
append_path '/usr/local/sbin'
append_path '/usr/local/bin'
append_path '/usr/sbin'
append_path '/usr/bin'
append_path '/sbin'
append_path '/bin'
append_path '~/bin'
# Force PATH to be environment
export PATH
# Set IFS to be newline delimited
IFS="
"
export IFS
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -r "$profile" && . "$profile"
done
unset profile
fi
# Unload our profile API functions
unset -f append_path
# Source global bash config, when interactive but not posix or sh mode
if test "$BASH" &&\
test "$PS1" &&\
test -z "$POSIXLY_CORRECT" &&\
test "${0#-}" != sh &&\
test -r /etc/bashrc
then
. /etc/bashrc
fi
# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP
# Man is much better than us at figuring this out
unset MANPATH

View File

@ -0,0 +1,28 @@
### AniNIX Customizations ###
alias get-commands='for i in $( echo $PATH | sed "s/:/\n/g"); do ls $i; done | sort | less'
alias whoison='who | grep -v tmux'
function vncdesktop() {
set -x
if [ -z "$@" ]; then
vncserver :2 -rfbport 5901
else
vncserver $@
fi
export DISPLAY=`vncserver -list | tail -n 1 | awk '{print $1; }' `
sleep 3
xfce4-session
vncserver -kill "$DISPLAY"
set +x
}
alias vi=vim
alias view="vim -R"
alias top="top -o %CPU"
alias make-entrypoints="egrep '^[a-zA-Z0-9\-]*:' Makefile"
alias rdns="dig +short -x "
alias dns="dig +short "
export WEECHAT_HOME=$HOME/.weechat
if [ -x `which torsocks 2>/dev/null` ] && [ `systemctl status tor 2>/dev/null| grep -c running` -eq 1 ]; then
alias tor-lynx="torsocks lynx https://check.torproject.org/";
fi
IFS="
"

View File

@ -0,0 +1,6 @@
### Ansible ###
export ANSIBLE_VAULT_PASSWORD_FILE=$HOME/password-store/${organization}.vault.password
export ANSIBLE_VAULT_FILE=$HOME/password-store/${organization}.vault
alias ansible="/usr/bin/ansible -e @${ANSIBLE_VAULT_FILE}"
alias ansible-playbook="/usr/bin/ansible-playbook -e @${ANSIBLE_VAULT_FILE}"
alias vault="/usr/bin/ansible-vault edit ${ANSIBLE_VAULT_FILE}"

View File

@ -0,0 +1,10 @@
### GPG ###
export GPG_TTY=$(tty)
# GPG Key Agent
# Credit: https://wiki.archlinux.org/index.php/GnuPG
if [ `pgrep -afc -u $USER gpg-agent` -lt 1 ] && [ -x `which gpg-agent` ]; then
gpg-agent --daemon 2>&1 | grep -v another
fi

View File

@ -0,0 +1,18 @@
# Set up screen/tmux safety nest by default for remote sessions
if [ -n "$SSH_CLIENT" ]; then
# Prefer tmux
if [ -x "$(which tmux 2>/dev/null)" ] && [ -z "$TMUX" ]; then
if [ `tmux list-sessions | grep created | wc -l` -eq 0 ]; then
exec tmux
elif [ `tmux list-sessions | grep created | wc -l` -eq 1 ] && [ `tmux list-sessions | grep attached | wc -l` -eq 0 ]; then
exec tmux a -d -t `tmux list-sessions | grep created | cut -f 1 -d ':'`
else
tmux list-sessions
fi
alias tat="exec tmux a -d -t"
fi;
### XFCE4 ###
elif [ `who -m | egrep "^$(whoami)" | awk '{ print $2; }' | egrep -c "^tty"` -eq 1 ] && [ -x /usr/sbin/startxfce4 ] && [ `pgrep -ac xinit` -eq 0 ] && [ `whoami` != 'root' ]; then
exec startxfce4
fi

View File

@ -0,0 +1,24 @@
### Prompt ###
organization="$(echo $HOSTNAME | rev | cut -f 2 -d '.' | rev)"
PS1='\[\033[00;31m\][ \[\033[01;32m\]\u\[\033[00;31m\]@\H:${SHELL} {\[\033[m\]$? \[\033[00;36m\]\D{%F-%R} \[\033[00;35m\]\w\[\033[00;31m\]\[\033[00;31m\]\[\033[00;33m\]$(git_prompt_var)\[\033[00;31m\]} ]\n|\[\033[m\]> '
PS2='> '
PS3='> '
PS4='+ '
case ${TERM} in
screen|xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
PROMPT_COMMAND='echo -en "\033]0;'${organization^^}'/'${HOSTNAME%%.*}'\a"'
;;
esac
# Terminal settings
export TERM=xterm-256color
alias weechat="TERM=screen weechat"
# Disable bracketed paste mode
printf "\e[?2004l"
# systemctl --user
export XDG_RUNTIME_DIR=/run/user/$UID
### MOTD ###
[ -f /etc/bash.motd ] && cat /etc/bash.motd

View File

@ -0,0 +1,41 @@
### SSH ###
# Tell shell about ssh-agent -- enable with 'systemctl --user enable --now ssh-agent.service'
export SSH_AGENT_PID="$(pgrep -fu "$USER" ssh-agent)"
if [ -n "$SSH_AGENT_PID" ]; then
export SSH_AUTH_SOCK="/run/user/$EUID/ssh-agent.socket"
echo ssh-agent PID is $SSH_AGENT_PID
fi
if [ -n "$SSH_AUTH_SOCK" ] && [ `ssh-add -L | grep -c no\ identities` -eq 1 ]; then
ssh-add
ssh-add -L
fi
# Tmux help
function tssh () {
tmux new-window -n "$1" "/bin/bash -ilc 'ssh $1'"
}
### GIT ###
source /usr/share/git/completion/git-prompt.sh
function git_prompt_var() {
### If $PWD is a Git repo, add URL and branch to PS1
url=`git config remote.origin.url 2>/dev/null`
if [ -n "$url" ]; then
branch=`__git_ps1 '%s'`
url=`basename "$url"`
echo " $url($branch)"
fi
}
### User-directory .gitbare Support (Git) ###
if [ -d ~/.git ]; then
cd
printf "~/.git: "
if [ $SHLVL -eq 1 ] && [ -z "$TMUX" ]; then
git pull
else
git rev-parse --short HEAD
fi
git status
fi

View File

@ -1,119 +0,0 @@
### Prompt ###
organization="$(echo $HOSTNAME | rev | cut -f 2 -d '.' | rev)"
PS1='\[\033[00;31m\][ \[\033[01;32m\]\u\[\033[00;31m\]@\H:${SHELL} {\[\033[m\]$? \[\033[00;36m\]\D{%F-%R} \[\033[00;35m\]\w\[\033[00;31m\]\[\033[00;31m\]\[\033[00;33m\]$(git_prompt_var)\[\033[00;31m\]} ]\n|\[\033[m\]> '
PS2='> '
PS3='> '
PS4='+ '
case ${TERM} in
screen|xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
PROMPT_COMMAND='echo -en "\033]0;'${organization^^}'/'${HOSTNAME%%.*}'\a"'
;;
esac
# Terminal settings
export TERM=xterm-256color
alias weechat="TERM=screen weechat"
# Disable bracketed paste mode
printf "\e[?2004l"
# systemctl --user
export XDG_RUNTIME_DIR=/run/user/$UID
### MOTD ###
[ -f /etc/bash.motd ] && cat /etc/bash.motd
### SSH ###
# Tell shell about ssh-agent -- enable with 'systemctl enable ssh-agent@$USER.service'
export SSH_AGENT_PID="$(pgrep -fu "$USER" ssh-agent)"
if [ -n "$SSH_AGENT_PID" ]; then
export SSH_AUTH_SOCK="$(ls -ld /tmp/ssh-*/agent.* | grep -m 1 "$USER" | awk '{ print $9; }')"
echo ssh-agent PID is $SSH_AGENT_PID
fi
if [ -n "$SSH_AUTH_SOCK" ] && [ `ssh-add -L | grep -c no\ identities` -eq 1 ]; then
ssh-add
ssh-add -L
fi
### GIT ###
source /usr/share/git/completion/git-prompt.sh
function git_prompt_var() {
### If $PWD is a Git repo, add URL and branch to PS1
url=`git config remote.origin.url 2>/dev/null`
if [ -n "$url" ]; then
branch=`__git_ps1 '%s'`
url=`basename "$url"`
echo " $url($branch)"
fi
}
### User-directory .gitbare Support (Git) ###
if [ -d ~/.git ]; then
cd
printf "~/.git: "
if [ $SHLVL -eq 1 ] && [ -z "$TMUX" ]; then
git pull
else
git rev-parse --short HEAD
fi
git status
fi
### GPG ###
export GPG_TTY=$(tty)
# GPG Key Agent
# Credit: https://wiki.archlinux.org/index.php/GnuPG
if [ `pgrep -afc -u $USER gpg-agent` -lt 1 ] && [ -x `which gpg-agent` ]; then
gpg-agent --daemon 2>&1 | grep -v another
fi
### Ansible ###
export ANSIBLE_VAULT_PASSWORD_FILE=$HOME/password-store/${organization}.vault.password
export ANSIBLE_VAULT_FILE=$HOME/password-store/${organization}.vault
### AniNIX Customizations ###
alias get-commands='for i in $( echo $PATH | sed "s/:/\n/g"); do ls $i; done | sort | less'
alias whoison='who | grep -v tmux'
function vncdesktop() {
set -x
if [ -z "$@" ]; then
vncserver :2 -rfbport 5901
else
vncserver $@
fi
export DISPLAY=`vncserver -list | tail -n 1 | awk '{print $1; }' `
sleep 3
xfce4-session
vncserver -kill "$DISPLAY"
set +x
}
alias vi=vim
alias view="vim -R"
alias top="top -o %CPU"
alias make-entrypoints="grep -E '^[a-zA-Z0-9\-]*:' Makefile"
alias rdns="dig +short -x "
alias dns="dig +short "
export WEECHAT_HOME=$HOME/.weechat
if [ -x `which torsocks 2>/dev/null` ] && [ `systemctl status tor 2>/dev/null| grep -c running` -eq 1 ]; then
alias tor-lynx="torsocks lynx https://check.torproject.org/";
fi
IFS="
"
# Set up screen/tmux safety nest by default for remote sessions
if [ -n "$SSH_CLIENT" ]; then
# Prefer tmux
if [ -x "$(which tmux 2>/dev/null)" ] && [ -z "$TMUX" ]; then
if [ `tmux list-sessions | grep created | wc -l` -eq 0 ]; then
exec tmux
elif [ `tmux list-sessions | grep created | wc -l` -eq 1 ] && [ `tmux list-sessions | grep attached | wc -l` -eq 0 ]; then
exec tmux a -d -t `tmux list-sessions | grep created | cut -f 1 -d ':'`
else
tmux list-sessions
fi
alias tat="exec tmux a -d -t"
fi;
### XFCE4 ###
elif [ `who -m | grep -E "^$(whoami)" | awk '{ print $2; }' | grep -E -c "^tty"` -eq 1 ] && [ -x /usr/sbin/startxfce4 ] && [ `pgrep -ac xinit` -eq 0 ] && [ `whoami` != 'root' ]; then
exec startxfce4
fi