Manager: Add support for apt/dpkg package management
This commit is contained in:
+103
-27
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Manages dotfiles and packages
|
# Manages dotfiles and packages
|
||||||
# Depends: GNU getopt, pacman-contrib
|
# Depends: GNU getopt, (pacman, pacman-contrib) / (dpkg, apt)
|
||||||
|
|
||||||
# User-config---------------------------
|
# User-config---------------------------
|
||||||
|
|
||||||
@@ -71,6 +71,9 @@ EOF
|
|||||||
# Exit if no option is provided
|
# Exit if no option is provided
|
||||||
[ "$#" -eq 0 ] && help >&2 && exit 1
|
[ "$#" -eq 0 ] && help >&2 && exit 1
|
||||||
|
|
||||||
|
# Files
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
setFiles()
|
setFiles()
|
||||||
{
|
{
|
||||||
files="$(find . -type f -o -type l \
|
files="$(find . -type f -o -type l \
|
||||||
@@ -153,40 +156,113 @@ push()
|
|||||||
pullPush "push"
|
pullPush "push"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! pacman -Qqs pacman-contrib > /dev/null; then \
|
# Packages
|
||||||
echo 'Please install the "pacman-contrib" dependency before running this option.' >&2
|
# --------------------------------------
|
||||||
|
|
||||||
|
osDetect()
|
||||||
|
{
|
||||||
|
id="$(sed -nE 's/^ID=(.*)/\1/p' /etc/os-release)"
|
||||||
|
idLike="$(sed -nE 's/^ID_LIKE=(.*)/\1/p' /etc/os-release)"
|
||||||
|
|
||||||
|
if [ "$id" = "arch" ]; then
|
||||||
|
os="arch"
|
||||||
|
elif echo "$idLike" | grep -q 'arch'; then
|
||||||
|
os="arch"
|
||||||
|
elif [ "$id" = "debian" ] || [ "$id" = "ubuntu" ]; then
|
||||||
|
os="debian"
|
||||||
|
elif echo "$idLike" | grep -q 'debian'; then
|
||||||
|
os="debian"
|
||||||
|
elif echo "$idLike" | grep -q 'ubuntu'; then
|
||||||
|
os="debian"
|
||||||
|
else
|
||||||
|
echo "Unsupported operating system." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
filterList="$( (pacman -Qqg base base-devel; pactree -u base | tail -n +2) | sort)"
|
osDependencies()
|
||||||
packageList="$(pacman -Qqe | grep -vx "$filterList" | sort)"
|
{
|
||||||
|
if [ "$os" = "arch" ]; then
|
||||||
|
binaryDependencyPair="
|
||||||
|
pacman:pacman
|
||||||
|
pactree:pacman-contrib
|
||||||
|
"
|
||||||
|
elif [ "$os" = "debian" ]; then
|
||||||
|
binaryDependencyPair="
|
||||||
|
apt-cache:apt
|
||||||
|
apt-mark:apt
|
||||||
|
dpkg-query:dpkg
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for pair in $binaryDependencyPair; do
|
||||||
|
binary="$(echo "$pair" | cut -d ':' -f 1)"
|
||||||
|
if ! command -v "$binary" > /dev/null; then
|
||||||
|
dependency="$(echo "$pair" | cut -d ':' -f 2)"
|
||||||
|
echo "Please install the '$dependency' dependency before running this option." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
packageList()
|
||||||
|
{
|
||||||
|
if [ "$os" = "arch" ]; then
|
||||||
|
filterList="$( (pacman -Qqg base base-devel; pactree -u base | tail -n +2) | sort)"
|
||||||
|
packageList="$(pacman -Qqe | grep -vx "$filterList" | sort)"
|
||||||
|
elif [ "$os" = "debian" ]; then
|
||||||
|
installedList="$(dpkg-query --show --showformat='${Package}\t${Priority}\n')"
|
||||||
|
filterList="$(echo "$installedList" | grep -E 'required|important|standard' | cut -f 1)"
|
||||||
|
installedList="$(echo "$installedList" | cut -f 1)"
|
||||||
|
installedManuallyList="$(awk '/Commandline:.* install / && !/APT::/ { print $NF }' /var/log/apt/history.log)"
|
||||||
|
installedManuallyList="$( (echo "$installedManuallyList"; apt-mark showmanual) | sort -u)"
|
||||||
|
packageList="$(echo "$installedManuallyList" | grep -x "$installedList" | grep -vx "$filterList")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
packageInstall()
|
||||||
|
{
|
||||||
|
if [ "$os" = "arch" ]; then
|
||||||
|
# Grab everything off enabled official repositories that is in the list
|
||||||
|
repoList="$(pacman -Ssq | grep -xf $packageFile)"
|
||||||
|
|
||||||
|
if [ "$1" = "install" ]; then
|
||||||
|
# Install packages
|
||||||
|
echo "$repoList" | xargs --open-tty sudo pacman -Sy --needed
|
||||||
|
fi
|
||||||
|
if [ "$1" = "install-aur" ]; then
|
||||||
|
# Determine which packages in the list are from the AUR
|
||||||
|
aurList="$(grep -vx "$repoList" < $packageFile)"
|
||||||
|
|
||||||
|
# Install AUR packages
|
||||||
|
echo "$aurList" | xargs --open-tty "$aurHelper" -Sy --needed --noconfirm
|
||||||
|
fi
|
||||||
|
elif [ "$os" = "debian" ]; then
|
||||||
|
# Grab everything off enabled official repositories that is in the list
|
||||||
|
repoList="$(apt-cache search .* | cut -d ' ' -f 1 | grep -xf $packageFile)"
|
||||||
|
|
||||||
|
# Install packages
|
||||||
|
echo "$repoList" | xargs --open-tty sudo apt install
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
packages()
|
||||||
|
{
|
||||||
|
# If unset
|
||||||
|
if [ -z "$os" ]; then
|
||||||
|
osDetect
|
||||||
|
osDependencies
|
||||||
|
packageList
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$1" = "list" ] || [ "$1" = "" ]; then
|
if [ "$1" = "list" ] || [ "$1" = "" ]; then
|
||||||
echo "$packageList"
|
echo "$packageList"
|
||||||
elif [ "$1" = "store" ]; then
|
elif [ "$1" = "store" ]; then
|
||||||
if [ ! -s $packageFile ]; then
|
|
||||||
touch "$packageFile"
|
|
||||||
else
|
|
||||||
truncate -s 0 "$packageFile"
|
|
||||||
fi
|
|
||||||
echo "$packageList" > "$packageFile"
|
echo "$packageList" > "$packageFile"
|
||||||
elif [ "$1" = "install" ] || [ "$1" = "install-aur" ]; then
|
elif [ "$1" = "install" ]; then
|
||||||
# Grab everything off enabled official repositories that is in the list
|
packageInstall "install"
|
||||||
coreList="$(pacman -Ssq | grep -xf $packageFile)"
|
elif [ "$1" = "install-aur" ]; then
|
||||||
|
packageInstall "install-aur"
|
||||||
if [ "$1" = "install" ]; then
|
|
||||||
# Install core packages, answer no to pacman questions (honor Ignore)
|
|
||||||
yes n | sudo pacman -Sy --needed $coreList
|
|
||||||
fi
|
|
||||||
if [ "$1" = "install-aur" ]; then
|
|
||||||
# Determine which packages in the list are from the AUR
|
|
||||||
aurList="$(grep -vx "$coreList" < $packageFile)"
|
|
||||||
|
|
||||||
# Install AUR packages
|
|
||||||
"$aurHelper" -Sy --needed --noconfirm $aurList
|
|
||||||
fi
|
|
||||||
packages()
|
|
||||||
{
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user