-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpakt-sync
executable file
·90 lines (79 loc) · 1.93 KB
/
pakt-sync
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
#!/bin/sh
# Pakt (PAcman KaTegories) - Pacman wrapper for categorizing packages
# v0.1.0 GPL-2.0
# https://github.com/mrminede/pakt
# Help message part.
if [ "$#" -eq 0 ] || [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
echo "PAKT-SYNC: shamelessly redirecting you to the man page ..."
sleep 2
man pakt-sync
exit
fi
# Strict mode. The script will throw an error on an unbound variable encounter.
set -u
# Check whether the data path was defined with XDG.
if [ -z "${XDG_DATA_HOME:-}" ]; then
DATA_PATH="$HOME/.local/share/pakt"
else
DATA_PATH="$XDG_DATA_HOME/pakt"
fi
mkdir -p "$DATA_PATH"
# Control/set config path variable.
if [ -z "${PAKT_CONF_PATH:-}" ]; then
PAKT_CONF_PATH="/etc"
fi
# Check whether pakt.conf exists in the first place.
if [ ! -e "$PAKT_CONF_PATH/pakt.conf" ]; then
echo "PAKT: ERROR: /etc/pakt.conf not found. Exiting ..."
exit 1
fi
. "$PAKT_CONF_PATH/pakt.conf"
# Process variables
FLAG=""
FILES=""
CATS=""
PKGS=""
for arg in "$@"; do
case "$arg" in
"-"*)
FLAG="${FLAG}${arg}"
;;
"+"*)
CATS="${CATS} ${arg}"
;;
*)
FILES="${FILES} ${arg}"
;;
esac
done
for file in $(echo "$FILES" | tr ' ' '\n'); do
# The awk command cuts comments (hash characters and everything after them)
# and merges all lines into one.
file_pkgs=$(awk '!/^#/ { sub(/#.*/, ""); printf "%s ", $0 }' "$file")
PKGS="${PKGS} ${file_pkgs}"
done
for cat in $(echo "$CATS" | tr ' ' '\n'); do
# See comment above.
cat_pkgs=$(awk '!/^#/ { sub(/#.*/, ""); printf "%s ", $0 }' "$DATA_PATH/${cat#+}")
PKGS="${PKGS} ${cat_pkgs}"
done
case "$FLAG" in
"")
for pkg in $(echo "$PKGS" | tr ' ' '\n'); do
# Check whether pkg is an installed Arch package.
if ! pacman -Qs "$pkg" > /dev/null; then
echo "$pkg"
fi
done
;;
"-S"|"--sync")
eval "$PACKAGE_MANAGER -S $PKGS"
;;
"-R"|"--remove")
eval "$PACKAGE_MANAGER -Rcnsu $PKGS"
;;
*)
echo "PAKT-SYNC: ERROR: invalid flag(s): '$FLAG'. Exiting ..."
exit 1
;;
esac