-
Notifications
You must be signed in to change notification settings - Fork 20
/
pkgadd
executable file
·48 lines (41 loc) · 1.03 KB
/
pkgadd
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
#!/usr/bin/env bash
if test -z "$PACKLIST" ;then
if [[ -r $XDG_CONFIG_HOME/pkgsync/pkgsync.conf ]] ; then
# shellcheck disable=1091
source "$XDG_CONFIG_HOME"/pkgsync/pkgsync.conf
fi
fi
if test -z "$PACKLIST" ;then
echo 'PACKLIST not defined'
exit 1
fi
cd "$( dirname "$PACKLIST" )" || exit
pkgs=("$@")
while [[ -z "${pkgs[*]}" ]] ; do
read -rp "Enter packages name: " pkgs
done
need2install=0
for pkg in "${pkgs[@]}" ; do
if grep -xq "$pkg" "$PACKLIST" ; then
echo "Package $pkg is already in $PACKLIST"
else
tmp=$(mktemp /tmp/pkgadd.XXXXXX)
trap 'rm -f "$tmp"' EXIT
cp "$PACKLIST" "$tmp"
echo "$pkg" >> "$tmp"
sort -u "$tmp" -o "$tmp" && mv "$tmp" "$PACKLIST" && \
echo "Package $pkg added to $PACKLIST"
fi
if pacman -Q "$pkg" &>/dev/null ; then
echo "Package $pkg is already installed"
else
need2install=1
fi
done
if [[ $need2install -eq 1 ]] ; then
read -rp 'Run pkgsync? [Y/n]: ' ans
case "$ans" in
[Nn]*) ;;
*) PACKLIST="$PACKLIST" pkgsync ;;
esac
fi