diff options
| author | Xiao Pan <gky44px1999@gmail.com> | 2024-02-23 03:08:52 -0800 | 
|---|---|---|
| committer | Xiao Pan <gky44px1999@gmail.com> | 2024-02-23 03:08:52 -0800 | 
| commit | dd78faaf40862bd1552ec36c41374b527f747284 (patch) | |
| tree | b914f890c545db7168984f7bcc15cfc7c976c1d3 /upd | |
| parent | c808bb6ee7f77f077308a1f06f63dbee6a928f6d (diff) | |
Reorganize shell scripts into sh dir, consider in the future fsh will have different kinds of files
Diffstat (limited to 'upd')
| -rwxr-xr-x | upd | 219 | 
1 files changed, 0 insertions, 219 deletions
@@ -1,219 +0,0 @@ -#!/bin/sh - -all () { -	fast -	clean -	[ "$hostname" != xyzpp ] && refl -	[ "$hostname" = xyzka ] && qb -	[ "$hostname" = xyzinsp ] && music -	if [ "$hostname" = xyzinsp ] || [ "$hostname" = xyzpp ]; then -		userjs -	fi -} - -backup () { -	case "$hostname" in -		xyzinsp) backup_branch=master;; -		*) backup_branch=${hostname#xyz};; -	esac - -	if [ "$hostname" = xyzinsp ]; then -		# Pull repos and branches from studio, so one more backup on insp or duplicity will backup to ka,for one more backup for 321 backup rule -		# cfgl master and pp branches already satisfy 321 rule. Here are three copies: 1. master/pp, 2. studio, 3. gitlab or alternative -		# But I still copy those on insp because one more copy will not hurt. And all my other data stil satisfy 3 copies without backup to gitlab, so why left out cfgl? Also it may be nice if I what to use that local dir for searching things. -		cd "$HOME/programs/config_local_arch" || exit 1 -		git branch | awk '{print ($1=="*")?$2:$1}' | while read -r branch; do -			git checkout "$branch" -			git pull -			# Push ka branch to codeberg or any future alternative website for mirroring. Needed for public codes/data, considering my death may result in all copies on my computers being lost. -			[ "$branch" = ka ] && git push -		done -		# git checkout will change mtime, need to change back so rsync won't think it needs to backup these files -		# https://stackoverflow.com/q/1964470/9008720 -		# https://stackoverflow.com/q/21735435/9008720 -		# https://github.com/MestreLion/git-tools -		# aur/git-tools-git -		git restore-mtime - -		( -			umask 077 -			# backup ka cfgl -			sudo -E git -C /root/programs/config_local_arch_secrets_ka pull -			# backup studio cfgl -			sudo -E git -C /root/programs/config_local_arch_secrets pull -		) - -		# rsync backup from studio to insp -		rsync -avPR --delete studio:/home/xyz/.config/qBittorrent :/home/xyz/.local/share/qBittorrent/BT_backup "$HOME/backup/studio" - -	fi -	 -	if [ "$hostname" = xyzinsp ] || [ "$hostname" = xyzstudio ]; then -		# rsync backup from ka -		rsync -avPR --delete ka:/home/xyz/.config/qBittorrent :/home/xyz/.local/share/qBittorrent/BT_backup "$HOME/backup/ka" -	fi - -	if [ "$hostname" != xyzstudio ] && [ "$hostname" != xyzka ]; then -		# rsync backup to studio -		# --files-from make -a not imply -r, so need to specify explicitly -		rsync -avPRr --delete --files-from="$XDG_CONFIG_HOME/myconf/upd_rsync_files" / "studio:/home/xyz/backup/$backup_branch" -	fi - -	if [ "$hostname" != xyzka ]; then -		# duplicity backup to ka -		# https://wiki.archlinux.org/title/Duplicity -		# Need // for absolute path, see manpage URL FORMAT section. If not use //, will store to /home/xyz/home/xyz/... -		# --files-from has a bug, this bug makes source url that is / not working while /home works, more see vq notes -		# --use-agent not working when ssh to pp and insp, works on insp, not sure why -		use_agent= -		[ "$hostname" = xyzinsp ] && use_agent='--use-agent' -		sudo duplicity --ssh-askpass $use_agent --encrypt-key 9790577D2BE328D46838117ED3F54FE03F3C68D6 --sign-key 05899270DF25BB1EEDF57BE824F769E5D08C9E9A --full-if-older-than 2Y --include /etc/.cfgs --include-filelist "/home/xyz/.config/myconf/upd_rsync_files" --exclude / / "sftp://xyz@xyzka.kyun.li//home/xyz/backup/$backup_branch" -	fi -} - -clean () { -	if [ "$hostname" = xyzinsp ]; then -		nsxiv -c -		# my ways -		# -exec can't replace -execdir here -		find "$XDG_CACHE_HOME/nsxiv/" -depth -type d -empty -execdir rmdir -- '{}' \+ -		# -exec can replace -execdir here -		#find "$XDG_CACHE_HOME/nsxiv/" -depth -type d -execdir rmdir --ignore-fail-on-non-empty -- '{}' \+ -		# nsxiv man page way -		#find "$XDG_CACHE_HOME/nsxiv/" -depth -type d -empty ! -name '.' -exec rmdir -- '{}' \; - -	fi - -	if [ "$hostname" = xyzinsp ] || [ "$hostname" = xyzpp ]; then -		cd "$HOME/.mozilla/firefox/xxxxxxxx.fly/prefsjs_backups" || exit -		# https://stackoverflow.com/a/34862475/9008720 -		ls -t | tail -n +11 | tr '\n' '\0' | xargs -0 rm -- -		# https://unix.stackexchange.com/questions/92095/reset-atq-list-to-zero -		sudo systemctl stop atd -		echo 0 | sudo tee /var/spool/atd/.SEQ > /dev/null -		sudo systemctl start atd -		rm -rf "$XDG_VIDEOS_DIR/recordings/tmp/" -	fi - -	paru -aSc --noconfirm -} - -# basic daily stuff -fast () { -	pac -	misc -	[ "$hostname" != xyzka ] && backup -} - -userjs () { -	kill $(pidof "$BROWSER") -	# change working dir for cleaner -	cd "$HOME/.mozilla/firefox/xxxxxxxx.fly" || exit -	arkenfox-cleaner -s -	arkenfox-updater -s -} - -misc () { -	"$EDITOR" +PlugClean! +PlugUpdate +qa - -	if [ "$hostname" = xyzinsp ] || [ "$hostname" = xyzpp ]; then -		tldr --update -	fi - -	if [ "$hostname" = xyzinsp ]; then -		sudo hardcode-fixer -		ssh pp '[ -s "$HOME/.local/share/sdcv_history" ] && cat "$HOME/.local/share/sdcv_history" && rm "$HOME/.local/share/sdcv_history"' >> "$XDG_DATA_HOME/sdcv_history" -		awk '!a[$0]++' "$XDG_DATA_HOME/sdcv_history" | sponge "$XDG_DATA_HOME/sdcv_history" -		# temperory solution before find a way of using git submodule or subtree with `cfg -l` -		git -C "$HOME/.mozilla/firefox/xxxxxxxx.fly/chrome/firefox-csshacks" pull -		git -C "$XDG_DOCUMENTS_DIR/notes" commit --all -m 'update' -		git -C "$XDG_DOCUMENTS_DIR/notes" push -		git -C "$HOME/programs/reminders" commit --all -m 'update' -		git -C "$HOME/programs/reminders" push -		pass git push -	fi - -	if [ "$hostname" = xyzpp ]; then -		git -C "$XDG_DOCUMENTS_DIR/notes" pull -		git -C "$HOME/programs/reminders" pull -		pass git pull -	fi -} - -pac () { -	pacpacs="$(sudo pacman --noconfirm -Syu | tee /dev/tty | grep -m1 '^Packages' | cut -d' ' -f3-)" -	# Update rust toolchains before paru so paru can compile things in newest rust if needed. -	rustup update -	aurpacs="$(paru --color never --noconfirm -aSu --ignore libredwg-git | tee /dev/tty | grep '^Aur' | cut -d' ' -f3-)" -	# part steal from aur comment -	# sometimes "ERROR: Failure while downloading": https://github.com/neovim/neovim/issues/15709 -	# echo 1, printf 1 and yes 1 all works? not sure why -	# aur neovim-nightly-bin has some issue on 12/26/2021? switch to community repo neovim temporary -	#rm -rf ~/.cache/paru/clone/neovim-nightly-bin/ && echo 1 | PARU_PAGER=cat paru --rebuild --redownload neovim-nightly-bin -	pacman -Qqme > "$XDG_CONFIG_HOME/myconf/pacman_Qqme" -	pacman -Qqne > "$XDG_CONFIG_HOME/myconf/pacman_Qqne" -	systemctl list-unit-files --state=enabled > "$XDG_CONFIG_HOME/myconf/sye" -	systemctl --user list-unit-files --state=enabled > "$XDG_CONFIG_HOME/myconf/syue" -	# pacdiff default use pacman database, so no need `sudo -E` for find, but will be a little bit slower -	log="$log -updated pacman packages: $pacpacs -updated aur packages: $aurpacs -pacdiff: $(pacdiff -o | tr '\n' ' ') -checkrebuild: $(checkrebuild | awk '$2!~"zoom|miniconda3"{printf("%s ",$2)}') -$(if echo "$pacpacs" | grep -q 'linux-\(megi-\)\?[0-9]'; then echo 'kernel upgraded, need reboot'; fi) -" -} - -qb () { -	sudo systemctl stop qbittorrent-nox@xyz.service -	find "$XDG_DATA_HOME/qBittorrent/nova3/engines" -maxdepth 1 -type f ! -name 'jackett*' -a ! -name '__init__.py' -delete -	curlqb "$XDG_DATA_HOME/qBittorrent/nova3/engines" -	sudo systemctl start qbittorrent-nox@xyz.service -} - -refl () { -	# why not use http: -	# https://www.reddit.com/r/archlinux/comments/kx149z/should_i_use_http_mirrors/ -	# https://www.reddit.com/r/archlinux/comments/ej4k4d/is_it_safe_to_use_not_secured_http_pacman_mirrors/ -	# rsync may need to change XferCommand in /etc/pacman.conf -	# https://www.reddit.com/r/archlinux/comments/mynw6e/rsync_mirrors_with_pacman/ -	# need --delay so no super out of sync mirrors -	if [ "$hostname" != xyzka ]; then -		sudo reflector --verbose --save /etc/pacman.d/mirrorlist --country us --protocol https --delay 1 --latest 25 --score 25 --fastest 10 -	else -		sudo reflector --verbose --save /etc/pacman.d/mirrorlist --country ro --protocol https --delay 1 --fastest 3 -	fi -} - -music () { -	yt-dlp -f 'bestaudio[ext=opus]/bestaudio' --match-filter 'license=cc-by' --match-filter 'title~=(?i)cc-by' -P "$XDG_MUSIC_DIR/cc-by/scott_buckley" https://soundcloud.com/scottbuckley/tracks -	rsync -avP --delete "$XDG_MUSIC_DIR/cc-by/scott_buckley" pp:/home/xyz/music/cc-by -	rsync -avP --delete "$XDG_MUSIC_DIR/favorite" pp:/home/xyz/music -} - -hostname="$(hostname)"  -[ "$hostname" = xyzpp ] && gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type nothing -if [ $# -eq 0 ]; then -	fast -else -	while getopts abcfjmMpqr opt; do -		case $opt in -			a)all;; -			b)backup;; -			c)clean;; -			f)fast;; -			j)userjs;; -			m)misc;; -			M)music;; -			p)pac;; -			q)qb;; -			r)refl;; -			\?)exit 1;; -		esac -	done -fi -[ "$log" ] && printf '%s' "$log" | tee "$XDG_DOCUMENTS_DIR/logs/upd.log" -[ "$hostname" = xyzpp ] && gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type suspend -# `[ "$hostname" = xyzpp ] && ...` if check failed will have exit status of 1, unlike check with `if` -# I decided to always `exit 0` if reached end, so commands like `upd -p && ...` can keep running -exit 0  | 
