-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveinstalled
executable file
·78 lines (56 loc) · 2.37 KB
/
saveinstalled
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
#!/usr/bin/env sh
# Save lists of explicitly installed packages.
ScriptName=${0##*/}
Version=1.0.0
Deps=pacman
DefaultListsDir=${XDG_DATA_HOME:-$HOME/.local/share}/installed_packages
EnvListsDirVar=$(printf '%s_DIR' "$ScriptName" | tr '[a-z]' '[A-Z]')
EnvListsDirValue=$(eval printf '%s' \"\$$EnvListsDirVar\")
ListsDir=${EnvListsDirValue:-$DefaultListsDir}
[ "$EnvListsDirValue" ] && ListsDirStatus="Currently \033[1;34m$EnvListsDirVar\033[0m=$ListsDir" || \
ListsDirStatus="Currently \033[1;34m$EnvListsDirVar\033[0m is not set."
HelpMessage="\033[32m$ScriptName\033[0m $Version
Alexander Chaplin Braz <contact@alexchaplinbraz.com>
Save lists of explicitly installed official and AUR pacman packages. Can also
save a custom list based on directories inside the specified directory. Useful
for packages that have been installed from source. To activate it, pass a valid
directory like: ~/.local/src
Can set where to save the lists with \033[1;34m$EnvListsDirVar\033[0m, but if not set
it defaults to: $DefaultListsDir
$ListsDirStatus
\033[33mUSAGE:\033[0m
$ScriptName [PATH]
$ScriptName [FLAG]
\033[33mFLAGS:\033[0m
\033[32m-h\033[0m, \033[32m--help\033[0m Print help and exit.
\033[32m-v\033[0m, \033[32m--version\033[0m Print version and exit.
\033[33mARGS:\033[0m
\033[32m[PATH]\033[0m Path to extra directory.
\033[33mDEPENDENCIES:\033[0m
$Deps
"
error() {
printf "\033[1;31m${2:-ERROR}\033[0m: %s.\nTry '%s --help' for more information.\n" \
"$1" "$ScriptName" 1>&2
exit 1
}
case $1 in
-h|--help) printf '%b' "$HelpMessage"; exit 0 ;;
-v|--version) printf '%s\n' "$Version"; exit 0 ;;
'') ;;
*) ExtraDir=$1 ;;
esac
for dep in $Deps; do ! command -v $dep 1>/dev/null && MissingDeps="$MissingDeps $dep"; done
[ "$MissingDeps" ] && error "missing dependencies:$MissingDeps"
mkdir -p "$ListsDir"
[ ! -d "$ListsDir" ] && error "'$ListsDir' is not a valid directory"
pacman -Qqen > "$ListsDir/official" && \
printf 'Saved list of explicitly installed official packages.\n'
pacman -Qqem > "$ListsDir/aur" && \
printf 'Saved list of AUR installed packages.\n'
[ -z "$ExtraDir" ] && exit 0
[ ! -d "$ExtraDir" ] && error "'$ExtraDir' is not a valid directory"
find "$ExtraDir" -maxdepth 1 -type d -exec basename {} \; | \
sed '1d' > \
"$ListsDir/${ExtraDir##*/}" && \
printf "Saved list of '${ExtraDir##*/}'.\n"