-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_functions.sh
494 lines (440 loc) · 14.3 KB
/
bash_functions.sh
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
#!/bin/bash
# General
mkcd() {
mkdir -p -- "$1" && cd -P -- "$1"
}
nvmeHealth() {
local option=""
read -p "Disk: " option
sudo nvme smart-log -H /dev/nvme$option
}
resetDevice() {
local option=""
local module=""
echo "Device Reset 1.0"
echo "1. Bluetooth - btusb"
echo "2. Intel WiFi - iwlmvm"
echo "3. Mediatek WiFi - mt7921e"
echo "4. PlayStation 4/5 Controllers - hid_playstation"
echo "5. PlayStation 3 Controllers - hid_sony"
read -p "Option: " option
case $option in
1)
module=btusb ;;
2)
module=iwlmvm ;;
3)
module=mt7921e ;;
4)
module=hid_playstation ;;
5)
module=hid_sony ;;
*)
echo "Incorrect or no option chosen"
return
esac
echo "Option $module reset"
sudo rmmod $module && sudo modprobe $module
}
findFiles() {
find -type f -name "*.$1"
}
findFiles2() {
find ./ -type f \( -iname \*."$1" -o -iname \*."$2" \)
}
findFolders() {
find -maxdepth 1 -type d -name "$1*"
}
to7z() {
7z a -mx9 "${1%.$2}.7z" "$1"
}
toZst() {
tar -I "zstd --ultra -22 -T$(nproc)" -cf $1.tar.zst $1
}
delete() {
if [[ -d "$1" ]]
then
sudo rm -r "$1"
echo "Deleting folder $1"
elif [[ -f "$1" ]]
then
sudo rm "$1"
echo "Deleting file $1"
else
echo "$1 not found"
fi
}
tscCheck() {
if [[ $(cat /sys/devices/system/clocksource/clocksource0/current_clocksource) == "tsc" ]]
then
echo "TSC is active" | systemd-cat -p info
echo "TSC is active"
else
echo "TSC is not active" | systemd-cat -p emerg
echo "TSC is not active"
fi
return
}
clearCacheFiles() {
find $XDG_CACHE_HOME -type d -name "$1" | while read folder
do
find $folder -name "*" -type f -mtime +1 -delete
done
}
storageCleanup() {
yay -Scc
sudo rm -r /var/log/journal/*
echo "Cleared /var/log/journal"
sudo rm -rf /var/lib/systemd/coredump/*
echo "Cleared /var/lib/systemd/coredump"
find "$XDG_CACHE_HOME" -name "ksycoca6*" -type f -mtime +1 -delete
find "$XDG_CACHE_HOME/qtshadercache-x86_64-little_endian-lp64/" -name "*" -type f -mtime +1 -delete
find "$XDG_CACHE_HOME" -name "*.qmlc" -type f -mtime +1 -delete
find "$XDG_CACHE_HOME" -name "*.jsc" -type f -mtime +1 -delete
find "$XDG_CACHE_HOME" -name "qqpc_opengl" -type f -mtime +1 -delete
echo "Cleared various cache files"
}
debugLogs() {
mkdir debugLogs
cd debugLogs
dmesg > dmesg.log
journalctl -b > journalctl.log
glxinfo > glxinfo.log
vulkaninfo > vulkaninfo.log
lsusb > lsusb.log
lspci > lspci.log
sudo fdisk -l > fdisk.log
cd ../
zip -9 debugLogs.zip debugLogs/*
rm -R debugLogs
}
# Media
toFlac() {
findFiles $1 | parallel ffmpeg -i "{}" -c:a flac -sample_fmt s32 "{.}.flac"
}
flacToOpus() {
findFiles flac | parallel opusenc --bitrate $1 "{}" "{.}.opus"
}
tagMusic() {
if [[ "$1" == "title" ]]
then
kid3-cli -c "select *.opus" -c "totag '%{title}' 2"
elif [[ "$1" == "album" ]]
then
kid3-cli -c "select *.opus" -c "set Album '$2'"
else
echo "Fail"
fi
}
downloadMusic() {
yt-dlp --format 251 --extract-audio --audio-format "opus" $1 -o "%(title)s.%(ext)s"
}
mkvDefaultTrack() {
echo "MKV Default Track Changer 1.0"
echo "This script lets you change the default track properties in an MKV"
echo ""
local trackType=""
local trackNum=""
local trackDef=""
local trackForced=""
mkvInfo "$file"
echo "MKV Default Track Selector"
read -p "Default track type: audio or subtitle (a/s): " trackType
read -p "Choose a track number: " trackNum
read -p "Set the track number as default? (0,1): " trackDef
read -p "Set the track number as forced (0,1) " trackForced
findFiles mkv | parallel mkvpropedit "{}" --edit track:$trackType$trackNum --set flag-default=$trackDef --set flag-forced=$trackForced
}
toMKV() {
findFiles $1 | parallel mkvmerge -o "{.}.mkv" "{}"
}
removeTracks() {
# Audio and Subtitle tracks not chosen by $1 and $2 will be removed
findFiles mkv | parallel mkvmerge -o "Muxed/{}" -a $1 -s $2 "{}"
}
addSubs() {
findFiles $1 | parallel mkvmerge -o "Muxed/{}" "{}" "{.}".srt
}
toJxl() {
local type=""
read -p "Image Type: " type
echo ".$type images chosen"
findFiles $type | parallel cjxl "{}" "{.}.jxl"
}
videoState() {
# $1 The file containing the list of videos
cat $1 | while read video
do
# echo $video
if [[ -f "$video" ]]
then
mv $video $video.bak
echo "Disabled $video"
elif [[ -f "$video.bak" ]]
then
mv $video.bak $video
echo "Restored $video"
else
echo "Video/s not found"
fi
done
}
# Gaming
# Gaming-Wine
wineKill() {
kill -9 $(ps -ef | grep -E -i "(wine|processid|\.exe)" | awk "{print $2}")
killall -9 pressure-vessel-adverb
}
downloadDirectX() {
curl -s https://api.github.com/repos/HansKristian-Work/vkd3d-proton/releases/latest | grep -o "https.*zst" | wget -i -
curl -s https://api.github.com/repos/doitsujin/dxvk/releases/latest | grep -om 1 "https.*tar.gz" | wget -i -
}
dx11() {
echo "Installing DXVK (DirectX 8,9,10,11)"
$HOME/Sync/Gaming/DXVK/setup_dxvk.sh install --symlink
}
dx12() {
echo "Installing VKD3D-Proton (DirectX 12)"
$HOME/Sync/Gaming/VKD3D-Proton/setup_vkd3d_proton.sh install --symlink
}
dxSetup() {
dx11
dx12
}
# Gaming-Emulation
crom() {
case $1 in
"chdDVD")
findFiles2 iso bin | parallel chdman createdvd -f -i "{}" -o "{.}.chd" ;;
"chdCD")
findFiles cue | parallel chdman createcd -f -i "{}" -o "{.}.chd" ;;
*)
echo "Incorrect or no option chosen"
esac
}
crom7z() {
findFiles $1 | parallel --bar 7z a -mx9 "{.}.7z" "{}"
}
reCrom() {
ark --batch --autodestination *.7z
mvrom $1
}
mvrom() {
local type="$1"
local dest=""
case $1 in
"nes")
crom7z $type
type="7z"
dest="$HOME/Games/Emulation/ROMs/Nintendo/NES" ;;
"n64")
crom7z $type
type="7z"
dest="$HOME/Games/Emulation/ROMs/Nintendo/N64" ;;
"gba")
crom7z $type
type="7z"
dest="$HOME/Games/Emulation/ROMs/Nintendo/GBA" ;;
"nds")
crom7z $type
type="7z"
dest="$HOME/Games/Emulation/ROMs/Nintendo/DS" ;;
"3ds")
dest="$HOME/Games/Emulation/ROMs/Nintendo/3DS" ;;
"switch")
type="nsp"
dest="$HOME/Games/Emulation/ROMs/Nintendo/Switch" ;;
"ps1")
dest="$HOME/Games/Emulation/ROMs/Sony/PS1"
type="chdCD"
crom $type
type="chd" ;;
"ps2")
dest="$HOME/Games/Emulation/ROMs/Sony/PS2"
type="chdDVD"
crom $type
type="chd" ;;
"psp")
dest="$HOME/Games/Emulation/ROMs/Sony/PSP"
type="chdDVD"
crom $type
type="chd" ;;
*)
echo "Choose a file type!"
echo "n64 - Nintendo 64"
echo "gba - GameBoy Advance"
echo "nds - Nintendo DS"
echo "3ds - Nintendo 3DS"
echo "switch - Nintendo Switch"
echo "ps1 - PlayStation 1"
echo "ps2 - PlayStation 2"
echo "psp - PlayStation Portable"
return
esac
echo "Moving $1 files to $dest"
mv *.$type "$dest"
}
# Gaming-Misc
changeGPUState() {
local gpuLevel=/sys/class/drm/card1/device/power_dpm_force_performance_level
echo "Current GPU Level: $(cat $gpuLevel)"
echo "Setting GPU Level to $1"
sudo sh -c "echo $1 > $gpuLevel"
echo "Current GPU Level: $(cat $gpuLevel)"
}
# Pi
piBackupSettings() {
local backupFile="/srv/nfs/Backup/Linux/Raspberry Pi/Raspberry Pi Settings - $(date +"%Y-%m-%d").tar.zst"
local targets="/home/pi/.profile /home/pi/.bashrc /home/pi/.ssh/authorized_keys /etc/samba /etc/fstab /home/pi/.local/state/syncthing"
sudo tar -P -I "zstd --ultra -22 -T$(nproc)" -cf "$backupFile" $targets
}
jellyfinBackup() {
local backupFile="/srv/nfs/Backup/Linux/Raspberry Pi/Jellyfin Backup - $(date +"%Y-%m-%d").tar"
local targets="/var/lib/jellyfin /etc/jellyfin"
sudo tar -P -cf "$backupFile" $targets
}
restoreTar() {
local backupFile=""
ls -l *.{tar,tar.zst}
read -p "Which tar file would you like to restore: " backupFile
sudo tar -P -xf "$backupFile"
}
# Git
buildMesa() {
local oldLocation=$PWD
cd "$HOME/Git/mesa"
git pull
git status
time ninja -C build64/ install
time ninja -C build32/ install
cd $oldLocation
rm -rf $HOME/.cache/mesa_shader_cache_sf
}
configureMesa() {
local oldLocation=$PWD
local option=""
local mesaSync="$HOME/Sync/Gaming/Mesa"
echo "Mesa Configurator 1.0"
echo "1: RADV"
echo "2: RADV+Zink"
echo "3: RADV+Zink+ACO"
read -p "Choose an option: " option
cd "$HOME/Git/mesa"
case $option in
1)
meson setup --reconfigure build64 --libdir lib64 --prefix $mesaSync -Dbuildtype=release -Dgallium-drivers= -Dvulkan-drivers=amd -Dllvm=disabled
meson setup --reconfigure build32 --cross-file gcc-i686 --libdir lib --prefix $mesaSync -Dgallium-drivers= -Dvulkan-drivers=amd -Dllvm=disabled -Dbuildtype=release
echo "Configured for RADV" ;;
2)
meson setup --reconfigure build64 --libdir lib64 --prefix $mesaSync -Dbuildtype=release -Dgallium-drivers=zink -Dvulkan-drivers=amd -Dllvm=disabled
meson setup --reconfigure build32 --cross-file gcc-i686 --libdir lib --prefix $mesaSync -Dgallium-drivers=zink -Dvulkan-drivers=amd -Dllvm=disabled -Dbuildtype=release
rm -rf $mesaSync/*
echo "Configured for RADV+Zink" ;;
3)
meson setup --reconfigure build64 --libdir lib64 --prefix $mesaSync -Dbuildtype=release -Dgallium-drivers=radeonsi,zink -Dvulkan-drivers=amd -Dllvm=disabled
meson setup --reconfigure build32 --cross-file gcc-i686 --libdir lib --prefix $mesaSync -Dgallium-drivers=radeonsi,zink -Dvulkan-drivers=amd -Dllvm=disabled -Dbuildtype=release
rm -rf $mesaSync/* ;;
*)
echo "Incorrect or no option chosen"
esac
cd $oldLocation
}
# Misc
buildLinuxTSC() {
local patches="$HOME/Sync/Config/Kernel/"
local kernel=""
echo "1: linux"
echo "2: linux-lts"
read -p "Which kernel would you like to build? " kernel
case $kernel in
1)
kernel="linux" ;;
2)
kernel="linux-lts" ;;
*)
echo "Incorrect or no option chosen"
return
esac
pkgctl repo clone --protocol=https $kernel
cd $kernel
cp $patches/tsc.patch tsc.patch
patch -i $patches/$kernel.patch PKGBUILD
time makepkg --syncdeps --skipinteg
}
printAfter() {
string=$1
searchstring="$2"
result=${string#*$searchstring}
echo $result
}
isInstalled() {
if [[ -f $1 ]]
then
echo "Installed"
else
echo "Not installed";
fi
}
sysCheck() {
local kernelVersion=$(uname -r)
local glibcVersion=$(ldd --version | grep ldd | awk '{print $4}')
local maxMapCount=$(cat /proc/sys/vm/max_map_count)
local limitNOFILE=$(ulimit -Hn)
local steamUdevRules=$(isInstalled /usr/lib/udev/rules.d/70-steam-input.rules)
local cpufreq=/sys/devices/system/cpu/cpu0/cpufreq/
local scaleGov=$(cat $cpufreq/scaling_governor)
local scaleDriver=$(cat $cpufreq/scaling_driver)
local turboBoost="$(if [[ $(cat $cpufreq/boost) == 1 ]]; then echo "On"; else echo "Off"; fi)"
local amdPstateMode=$(cat /sys/devices/system/cpu/amd_pstate/status)
local eppPref="$(if [ -f $cpufreq/energy_performance_preference ]; then cat $cpufreq/energy_performance_preference; else echo "N/A"; fi)"
local clocksource="$(cat /sys/devices/system/clocksource/clocksource0/current_clocksource)"
local gpuLevel=$(cat /sys/class/drm/card1/device/power_dpm_force_performance_level)
local gpuName=$(printAfter "$(DRI_PRIME=1! vulkaninfo --summary | grep -m 1 "deviceName")" "= ")
local gpuVram=$(DRI_PRIME=1! glxinfo -B | grep "Dedicated video memory:" | awk 'NR==1 { print $4 }')
local mesaVersion=$(vulkaninfo | grep driverVersion | awk 'NR==1 { print $3 }')
local llvmVersion=$(llvm-config --version)
local openglVersion=$(glxinfo | grep "OpenGL core profile version string" | awk '{ print $6 }')
local vulkanVersion=$(vulkaninfo | grep apiVersion | awk 'NR==1 { print $3 }')
local mangohudCheck=$(if [[ -f /usr/bin/mangohud ]]; then mangohud --version | cut -c 2-; else echo "Not installed"; fi)
local gamemodeCheck=$(if [[ -f /usr/bin/gamemoded ]]; then gamemoded -v | awk '{ print $3 }' | cut -c 2-; else echo "Not installed"; fi )
local gamescopeCheck=$(isInstalled /usr/bin/gamescope)
echo "System Check V2.11"
echo
echo "System"
echo "......................"
echo "Kernel : $kernelVersion"
echo "glibc : $glibcVersion"
echo "vm.max_map_count : $maxMapCount"
echo "DefaultLimitNOFILE : $limitNOFILE"
echo "Steam udev rules : $steamUdevRules"
echo
echo "CPU"
echo "......................"
echo "Scaling Governor : $scaleGov"
echo "Scaling Driver : $scaleDriver"
echo "Turbo Boost : $turboBoost"
echo "AMD P-State Mode : $amdPstateMode"
echo "EPP Preference : $eppPref"
echo "Clocksource : $clocksource"
echo
echo "GPU"
echo "......................"
echo "Name : $gpuName"
echo "VRAM : $gpuVram MB"
echo "Mesa : $mesaVersion"
echo "LLVM : $llvmVersion"
echo "OpenGL : $openglVersion"
echo "Vulkan : $vulkanVersion"
echo "AMDGPU Perf Level : $gpuLevel"
echo
echo "Utilities"
echo "......................"
echo "MangoHud : $mangohudCheck"
echo "Feral GameMode : $gamemodeCheck"
echo "Gamescope : $gamescopeCheck"
}
test_amd_s2idle() {
mkcd amd_s2idle
wget https://gitlab.freedesktop.org/drm/amd/-/raw/master/scripts/amd_s2idle.py
sudo python amd_s2idle.py
}