Skip to content

Commit 76c1ac3

Browse files
committed
feat: clean up
1 parent 2eb1190 commit 76c1ac3

File tree

1 file changed

+77
-121
lines changed

1 file changed

+77
-121
lines changed
Lines changed: 77 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,58 @@
11
# ~/.bash_functions
22

33
{
4-
function __docker() {
5-
if [ -n "$(docker network ls | grep wireguard)" ]; then
6-
docker run \
7-
--interactive \
8-
--network "container:wireguard" \
9-
--rm \
10-
--tty \
11-
--user "${UID}:${UID}" \
12-
--volume "$(readlink -f ${PWD}):/sandbox" \
13-
--workdir /sandbox \
14-
"$@"
15-
else
16-
docker run \
17-
--interactive \
18-
--rm \
19-
--tty \
20-
--user "${UID}:${UID}" \
21-
--volume "$(readlink -f ${PWD}):/sandbox" \
22-
--workdir /sandbox \
23-
"$@"
24-
fi
4+
function aptu() {
5+
sudo apt update
6+
sudo apt upgrade
7+
sudo apt autoremove
8+
sudo apt clean
259
}
2610

27-
function __docker_vpn() {
11+
function thumbnail() {
12+
local filepath="$(basename "$1")" # $filename + $extension
13+
local filename="${filepath%.*}"
14+
local extension="${filepath##*.}"
15+
16+
{
17+
# Generate thumbnail seed.
18+
local seed=$(openssl rand $RANDOM | md5sum | awk '{print $1}')
19+
20+
# Get total video duration in seconds.
21+
local duration=$(ffprobe -i "$filepath" -show_entries format=duration -v quiet -of csv="p=0")
22+
23+
# Generate 20 snapshots.
24+
ffmpeg -i "$filepath" -vf fps="20/${duration}" -vcodec png ${seed}-%002d.png &> /dev/null
25+
26+
# Collage snapshots.
27+
montage -geometry +4+4 ${seed}-*.png "$filename.png" &> /dev/null
28+
29+
# Compress collage.
30+
mogrify -quality '60%' "$filename.png"
31+
} && rm ${seed}-*.png
32+
}
33+
}
34+
35+
{
36+
function __vpn_check() {
2837
[ -n "$(docker network ls | grep wireguard)" ] || {
2938
docker network create wireguard
3039
}
3140

41+
[ -n "$(docker ps | grep vpn)" ] || {
42+
# __vpn_openvpn
43+
__vpn_wireguard
44+
}
45+
}
46+
47+
function __vpn_wireguard() {
3248
docker run \
3349
--cap-add=NET_ADMIN \
3450
--cap-add=SYS_MODULE \
3551
--detach \
3652
--device /dev/net/tun \
3753
--env PGID="$(id -g)" \
3854
--env PUID="$(id -u)" \
39-
--name wireguard \
55+
--name vpn \
4056
--publish="127.0.0.1:${RANDOM}:46882/udp" \
4157
--publish="127.0.0.1:${RANDOM}:50052/udp" \
4258
--publish="127.0.0.1:${RANDOM}:51413/tcp" \
@@ -48,6 +64,20 @@
4864
linuxserver/wireguard
4965
}
5066

67+
function __docker() {
68+
__vpn_check && {
69+
docker run \
70+
--interactive \
71+
--network "container:vpn" \
72+
--rm \
73+
--tty \
74+
--user "$(id -u):$(id -u)" \
75+
--volume "$(readlink -f ${PWD}):/sandbox" \
76+
--workdir /sandbox \
77+
"$@"
78+
}
79+
}
80+
5181
function dsh() {
5282
__docker initbar/lib:latest "$@"
5383
}
@@ -57,13 +87,6 @@
5787
7z "$@"
5888
}
5989

60-
function aptu() {
61-
sudo apt update
62-
sudo apt upgrade
63-
sudo apt autoremove
64-
sudo apt clean
65-
}
66-
6790
function binwalk() {
6891
dsh \
6992
binwalk
@@ -86,33 +109,6 @@
86109
exiftool "$@"
87110
}
88111

89-
function gip() {
90-
curl https://ipinfo.io
91-
}
92-
93-
function thumbnail() {
94-
local filepath="$(basename "$1")" # $filename + $extension
95-
local filename="${filepath%.*}"
96-
local extension="${filepath##*.}"
97-
98-
{
99-
# Generate thumbnail seed.
100-
local seed=$(openssl rand $RANDOM | md5sum | awk '{print $1}')
101-
102-
# Get total video duration in seconds.
103-
local duration=$(ffprobe -i "$filepath" -show_entries format=duration -v quiet -of csv="p=0")
104-
105-
# Generate 20 snapshots.
106-
ffmpeg -i "$filepath" -vf fps="20/${duration}" -vcodec png ${seed}-%002d.png &> /dev/null
107-
108-
# Collage snapshots.
109-
montage -geometry +4+4 ${seed}-*.png "$filename.png" &> /dev/null
110-
111-
# Compress collage.
112-
mogrify -quality '60%' "$filename.png"
113-
} && rm ${seed}-*.png
114-
}
115-
116112
function lrzip() {
117113
dsh \
118114
lrzip "$@"
@@ -125,18 +121,6 @@
125121
"$@"
126122
}
127123

128-
function mp3-dl() {
129-
dsh \
130-
yt-dlp \
131-
--audio-format mp3 \
132-
--audio-quality 320k \
133-
--extract-audio \
134-
--no-cache-dir \
135-
--no-sponsorblock \
136-
--verbose \
137-
"$@"
138-
}
139-
140124
function pdfmerge() {
141125
dsh \
142126
gs \
@@ -149,71 +133,31 @@
149133
"$@"
150134
}
151135

152-
function rchk() {
153-
dsh \
154-
md5sum \
155-
--binary \
156-
--tag \
157-
"$@"
158-
}
159-
160-
function rsgn() {
161-
local signature="$(md5sum $1 | head -c 8)"
162-
local extension="$(echo $1 | tr . \\n | tail -n 1)"
163-
mv -v "$1" "${signature}.${extension}"
164-
}
165-
166136
function strings() {
167137
dsh \
168138
strings \
169139
--all \
170140
"$@"
171141
}
172142

173-
function skaffold() {
174-
docker run \
175-
gcr.io/k8s-skaffold/skaffold:latest \
176-
skaffold \
177-
"$@"
178-
}
179-
180143
function tcli() {
181-
if [ -n "$(docker network ls | grep wireguard)" ]; then
182-
__docker \
183-
--detach \
184-
--volume="${HOME}/.torrents:/home/ubuntu/Downloads" \
185-
initbar/lib:latest \
186-
transmission-cli \
187-
--blocklist \
188-
--encryption-preferred \
189-
--no-downlimit \
190-
--uplimit 1 \
191-
--verify \
192-
"$1"
193-
else
194-
__docker \
195-
--detach \
196-
--publish="127.0.0.1:${RANDOM}:46882/udp" \
197-
--publish="127.0.0.1:${RANDOM}:50052/udp" \
198-
--publish="127.0.0.1:${RANDOM}:51413/tcp" \
199-
--publish="127.0.0.1:${RANDOM}:51413/udp" \
200-
--publish="127.0.0.1:${RANDOM}:9091" \
201-
--volume="${HOME}/.torrents:/home/ubuntu/Downloads" \
202-
initbar/lib:latest \
203-
transmission-cli \
204-
--blocklist \
205-
--encryption-preferred \
206-
--no-downlimit \
207-
--uplimit 1 \
208-
--verify \
209-
"$1"
210-
fi
144+
__docker \
145+
--detach \
146+
--volume="${HOME}/.torrents:/home/ubuntu/Downloads" \
147+
initbar/lib:latest \
148+
transmission-cli \
149+
--blocklist \
150+
--encryption-preferred \
151+
--no-downlimit \
152+
--uplimit 1 \
153+
--verify \
154+
"$1"
211155
}
212156

213157
function tclis() {
214158
while :; do
215159
docker ps |\
216-
egrep -v 'wireguard|CONTAINER' |\
160+
egrep -v 'vpn|CONTAINER' |\
217161
awk '{print $1}' |\
218162
sort |\
219163
xargs -I{} sh -c 'PROGRESS=$(docker logs --tail 1 {} | egrep -o "(Progress: [0-9.]+%)|Seeding" | sort -u | tail -1 | sed "s/^/\[/; s/$/\]/"); echo "> Container: {} ${PROGRESS}"' &&\
@@ -252,4 +196,16 @@
252196
--yes-playlist \
253197
"$@"
254198
}
199+
200+
function mp3-dl() {
201+
dsh \
202+
yt-dlp \
203+
--audio-format mp3 \
204+
--audio-quality 320k \
205+
--extract-audio \
206+
--no-cache-dir \
207+
--no-sponsorblock \
208+
--verbose \
209+
"$@"
210+
}
255211
}

0 commit comments

Comments
 (0)