]> zdv2.bktei.com Git - BK-2020-03.git/blob - user/bkotsgu
chore(user/gthumb/prune.org):Minor fixes
[BK-2020-03.git] / user / bkotsgu
1 #!/bin/bash
2 # Desc: Updates all ots files in $HOME and /mnt/ directories recursively.
3 # Depends: bash 5.1.16, GNU Findutils 4.8.0, GNU Coreutils 8.32
4 # Version: 0.1.3
5 # Depends: GNU Coreutils (nproc)
6
7 main() {
8 # Specify find targets
9 declare -a find_targets;
10
11 ## User home directory
12 find_targets+=("$HOME");
13
14 ## Subdirectories of /mnt/
15 mapfile -t -O "${#find_targets[@]}" find_targets < <(find /mnt/ -mindepth 1 -maxdepth 1 -type d; );
16
17 # Specify options
18 find_depth=12; # find directory depth
19 cpu_count="$(nproc)"; # get logical CPU count
20 batch_size_xargs=100; # xargs batch size
21 cpu_duty="$((cpu_count / 4 + 1))"; # logical CPU cores to use
22
23 # Remove OTS backup files
24 find "${find_targets[@]}" -maxdepth "$find_depth" -type f -name "*.ots.bak" -exec rm '{}' \; 2>/dev/random;
25
26 # Upgrade OTS files
27 find "${find_targets[@]}" -maxdepth "$find_depth" -type f -name "*.ots" -print0 2>/dev/random | \
28 sort -uz | \
29 shuf -z | \
30 xargs -0 -n "$batch_size_xargs" -P "$cpu_duty" ots u;
31 }; # main program
32
33 time { main "$@"; };