summaryrefslogtreecommitdiff
path: root/home/xyz/.local/bin/upd
blob: 688817d5f34bb29814b1921f0929eff235feb979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/sh

all () {
	fast
	qb
	kg
	ncm
	refl
	#gall
	usb
	xmr
}

clean () {
	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 -- '{}' \;

	rm "$HOME/.mozilla/firefox/xxxxxxxx.fly/prefs.js.backup."*

	# 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/"

	sudo pacman -Sc --noconfirm
}

# basic daily stuff
fast () {
	pac
	misc
}

gall () {
	gallery-dl --download-archive "$XDG_DOCUMENTS_DIR/database/gallery-dl.sqlite3" -d "$XDG_PICTURES_DIR/anime/gallery-dl/" -i "$XDG_CONFIG_HOME/myconf/gallery_urls"
}

userjs () {
	kill $(pidof "$BROWSER")
	"$HOME/.mozilla/firefox/xxxxxxxx.fly/prefsCleaner.sh" -s
	"$HOME/.mozilla/firefox/xxxxxxxx.fly/updater.sh" -us
}

kg () {
	curlkg -u649b9e82272a348b -- "$XDG_MUSIC_DIR/lan_lan/kg/"
	#curlkg -u64949d822c25328c -- "$XDG_MUSIC_DIR/cheng_ruan/kg/"
}

misc () {
	"$EDITOR" +PlugUpgrade +PlugClean! +PlugUpdate +qa
	tldr --update
	sudo hardcode-fixer
	sudo units_cur
	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 --git-dir=/home/xyz/.mozilla/firefox/xxxxxxxx.fly/chrome/firefox-csshacks/.git/ --work-tree=/home/xyz/.mozilla/firefox/xxxxxxxx.fly/chrome/firefox-csshacks/ pull

	userjs
	clean
}

ncm () {
	curlncm -a48860966 -- "$XDG_MUSIC_DIR/lan_lan/ncm/artist/"
	#curlncm -a46703185 -- "$XDG_MUSIC_DIR/cheng_ruan/ncm/artist/"
	#curlncm -a30382647 -- "$XDG_MUSIC_DIR/qi_tian_sakura/ncm/artist/"

	curlncm -r793052426 -- "$XDG_MUSIC_DIR/lan_lan/ncm/djradio/"
	#curlncm -r792968433 -- "$XDG_MUSIC_DIR/cheng_ruan/ncm/djradio/"
	#curlncm -r792042397 -- "$XDG_MUSIC_DIR/qi_tian_sakura/ncm/djradio/"
}

pac () {
	pacpacs="$(sudo pacman --noconfirm -Syu | tee /dev/tty | grep '^Packages' | cut -d' ' -f3-)"
	aurpacs="$(paru --noconfirm -aSyu | 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
	sudo pacman -Fy
	# 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' ' ')
"
}

qb () {
	rm -r -- "$HOME/programs/qbittorrent_search_plugins/"
	curlqb "$HOME/programs/qbittorrent_search_plugins/"
}

refl () {
	sudo reflector --verbose --save /etc/pacman.d/mirrorlist --score 50 --fastest 45
}

usb () {
	cfg -l push usb
	cfg -s push
	git --git-dir="$XDG_DOCUMENTS_DIR/notes/.git/" --work-tree="$XDG_DOCUMENTS_DIR/notes/" push usb
	git --git-dir="$HOME/programs/reminders/.git/" --work-tree="$HOME/programs/reminders/" push usb

	#rsync -navPR --delete ~/archive ~/documents ~/downloads ~/music ~/pictures ~/programs ~/test ~/videos ~/.local/share/stardict/dic ~/.local/share/qBittorrent ~/.local/share/sdcv_history ~/.cache/nsxiv ~/.config/qBittorrent ~/.bitmonero/wallets ~/.password-store /run/media/xyz/BAKDRI
	# --files-from make -a not imply -r, so need to specify explicitly
	rsync -avPRr --delete --files-from="$XDG_CONFIG_HOME/myconf/upd_rsync_files" / /run/media/xyz/BAKDRI

	# not sure if useful or not
	sync
}

xmr () {
	monero-blockchain-export --output-file /run/media/xyz/BAKDRI/archive/monero/blockchain.raw
	# not sure if useful or not
	sync
}

if [ $# -eq 0 ]; then
	fast
else
	while getopts acfgjkmnpqrux opt; do
		case $opt in
			a)all;;
			c)clean;;
			f)fast;;
			g)gall;;
			j)userjs;;
			k)kg;;
			m)misc;;
			n)ncm;;
			p)pac;;
			q)qb;;
			r)refl;;
			u)usb;;
			x)xmr;;
			\?)exit 1;;
		esac
	done
fi
[ "$log" ] && printf '%s' "$log" | tee "$XDG_DOCUMENTS_DIR/log/upd.log"