From 22d0f239f849efca80d22a2469a65127b8334a49 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 21 Jun 2020 13:26:14 +0200 Subject: [PATCH] extended update function to cleanup and autoremove --- zsh-david.plugin.zsh | 61 +++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/zsh-david.plugin.zsh b/zsh-david.plugin.zsh index 05b0af4..68e0fd7 100644 --- a/zsh-david.plugin.zsh +++ b/zsh-david.plugin.zsh @@ -6,7 +6,7 @@ set -o shwordsplit -# **** aliases definitions **** +# **** aliases **** alias zz='source $HOME/.zshrc' alias {update_zsh,zu}='echo "LAST_EPOCH=0" > $ZSH_CACHE_DIR/.zsh-custom-update > $ZSH_CACHE_DIR/.zsh-update; source $HOME/.zshrc' alias vz='vim $HOME/.zshrc && source $HOME/.zshrc' @@ -26,6 +26,8 @@ alias aec="sshuttle -vvr 90.146.8.233 192.168.6.0/24 90.146.8.0/26 10.9.0.0/26 1 alias home="sshuttle -vvr stargazer.socialnerds.org:2222 10.1.0.0/16" alias dmz="sshuttle -vvr 90.146.8.9 90.146.8.0/26" alias c="clear" +#alias cleardnscache="sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache; say DNS cache has been cleared" +alias cleardnscache="sudo killall -HUP mDNSResponder; sudo dscacheutil -flushcache; say DNS cache has been cleared" #alias ls='ls --color=auto' #does not work on macos alias pacrepo='sudo reflector -l 20 -f 10 --save /etc/pacman.d/mirrorlist' @@ -72,10 +74,18 @@ log() { sleep 0.5; echo -e "[$level] ${@:2}" } -## setup user accounts on linux systems +# setup user accounts on linux systems +# update them if existing +# ? delete them +# add authorized_keys setup_user() { if [ $1 ]; then log info "setting up account for $1" + #TODO: do the groups exist beforehand? + useradd -m -d /home/$1 -G "sudo sshusers docker" $1 + if [ $? -ne 0 ]; then + log error "error while creating user ($1)" + fi else log error "no username given" return 1 @@ -83,9 +93,7 @@ setup_user() { } ## RDP client -rdp() -{ - +rdp() { if [ -z $1 ]; then echo -e "server: \c" read server @@ -121,22 +129,22 @@ rdp() fi } -## OS Upgrade for various systems. -update() -{ + +## OS upgrade for various systems +update() { systems="ubuntu arch solus raspbian antergos" issue="$(cat /etc/issue)" for item in $systems; do echo $issue | grep -i $item >> /dev/null if [ $? -eq 0 ]; then - system=$item + system=$item fi done case $system in ubuntu|debian|raspbian) echo "Updating Ubuntu/Debian.." - sudo apt-get update && sudo apt-get dist-upgrade + sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y ;; arch|antergos) echo "Updating Arch Linux.." @@ -151,45 +159,16 @@ update() return 1 ;; esac + if [ $? -ne 0 ]; then echo "error: something went wrong." return 1 fi - } -# **** old content which i keep here for reference **** - -## Cross-platform install routine -#install() -#{ -# systems="ubuntu arch" -# issue="$(cat /etc/issue)" -# packages=$* -# for item in $systems; do -# echo $issue | grep -i $item >> /dev/null -# if [ $? -eq 0 ]; then -# system=$item -# fi -# done -# -# case $system in -# ubuntu) -# sudo apt-get install -y $packages -# ;; -# arch) -# sudo pacman -Sy --noconfirm $packages -# ;; -# ?) -# echo "unknown system. could not run install." -# ;; -# esac -#} - ## Thinkpad Trackpoint input fix (for for thinkpad x131e/chromebook) -#fixtrackpoint() -#{ +#fixtrackpoint() { # xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation" 1 # xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Button" 2 # xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Timeout" 200