Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference count sources list files so packages that share repositories work together nicely #643

Merged
merged 7 commits into from Dec 2, 2022
1 change: 1 addition & 0 deletions 01-main/packages/chronograf
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64 armhf"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="Chronograf"
WEBSITE="https://www.influxdata.com/time-series-platform/chronograf/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/influxdb
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64 armhf"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="InfluxDB"
WEBSITE="https://www.influxdata.com/products/influxdb-overview/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/influxdb2
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="InfluxDB2"
WEBSITE="https://www.influxdata.com/products/influxdb-overview/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/influxdb2-cli
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="InfluxDB2 CLI"
WEBSITE="https://www.influxdata.com/products/influxdb-overview/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/kapacitor
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="Kapacitor"
WEBSITE="https://github.com/influxdata/kapacitor"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/nomad
@@ -1,5 +1,6 @@
DEFVER=1
ASC_KEY_URL="https://apt.releases.hashicorp.com/gpg"
APT_LIST_NAME="hashicorp"
APT_REPO_URL="https://apt.releases.hashicorp.com ${UPSTREAM_CODENAME} main"
APT_REPO_OPTIONS="arch=${HOST_ARCH}"
PRETTY_NAME="Nomad"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/sublime-merge
@@ -1,5 +1,6 @@
DEFVER=1
ASC_KEY_URL="https://download.sublimetext.com/sublimehq-pub.gpg"
APT_LIST_NAME="sublime-text"
APT_REPO_URL="https://download.sublimetext.com/ apt/stable/"
PRETTY_NAME="Sublime Merge"
WEBSITE="https://www.sublimemerge.com/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/sublime-text
@@ -1,5 +1,6 @@
DEFVER=1
ASC_KEY_URL="https://download.sublimetext.com/sublimehq-pub.gpg"
APT_LIST_NAME="sublime-text"
APT_REPO_URL="https://download.sublimetext.com/ apt/stable/"
PRETTY_NAME="Sublime Text"
WEBSITE="https://www.sublimetext.com/"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/telegraf
@@ -1,6 +1,7 @@
DEFVER=1
ARCHS_SUPPORTED="amd64 arm64 armhf"
ASC_KEY_URL="https://repos.influxdata.com/influxdb.key"
APT_LIST_NAME="influxdata"
APT_REPO_URL="https://repos.influxdata.com/debian stable main"
PRETTY_NAME="Telegraf"
WEBSITE="https://github.com/influxdata/telegraf"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/terraform
@@ -1,5 +1,6 @@
DEFVER=1
ASC_KEY_URL="https://apt.releases.hashicorp.com/gpg"
APT_LIST_NAME="hashicorp"
APT_REPO_URL="https://apt.releases.hashicorp.com ${UPSTREAM_CODENAME} main"
APT_REPO_OPTIONS="arch=${HOST_ARCH}"
PRETTY_NAME="Terraform"
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/vagrant
@@ -1,6 +1,7 @@
DEFVER=1
CODENAMES_SUPPORTED="buster bullseye focal jammy"
ASC_KEY_URL="https://apt.releases.hashicorp.com/gpg"
APT_LIST_NAME="hashicorp"
APT_REPO_URL="https://apt.releases.hashicorp.com ${UPSTREAM_CODENAME} main"
PRETTY_NAME="Vagrant"
WEBSITE="https://www.vagrantup.com/"
Expand Down
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -60,7 +60,8 @@ cog.out(f"```\n{help}\n```")
```

deb-get {update [--repos-only] | upgrade | show <pkg list> | install <pkg list>
| reinstall <pkg list> | remove <pkg list> | purge <pkg list>
| reinstall <pkg list> | remove [--remove-repo] <pkg list>
| purge [--remove-repo] <pkg list>
| search [--include-unsupported] <regex> | cache | clean
| list [--include-unsupported] [--raw|--installed|--not-installed]
| prettylist [<repo>] | csvlist [<repo>] | fix-installed [--old-apps]
Expand Down Expand Up @@ -90,11 +91,13 @@ reinstall

remove
remove is identical to install except that packages are removed instead of
installed.
installed. When --remove-repo is provided, also remove the apt repository
of apt/ppa packages.

purge
purge is identical to remove except that packages are removed and purged
(any configuration files are deleted too).
(any configuration files are deleted too). When --remove-repo is provided,
also remove the apt repository of apt/ppa packages.

clean
clean clears out the local repository (/var/cache/deb-get) of retrieved
Expand Down
95 changes: 75 additions & 20 deletions deb-get
Expand Up @@ -20,7 +20,8 @@ cat <<HELP
Usage

deb-get {update [--repos-only] | upgrade | show <pkg list> | install <pkg list>
| reinstall <pkg list> | remove <pkg list> | purge <pkg list>
| reinstall <pkg list> | remove [--remove-repo] <pkg list>
| purge [--remove-repo] <pkg list>
| search [--include-unsupported] <regex> | cache | clean
| list [--include-unsupported] [--raw|--installed|--not-installed]
| prettylist [<repo>] | csvlist [<repo>] | fix-installed [--old-apps]
Expand Down Expand Up @@ -50,11 +51,13 @@ reinstall

remove
remove is identical to install except that packages are removed instead of
installed.
installed. When --remove-repo is provided, also remove the apt repository
of apt/ppa packages.

purge
purge is identical to remove except that packages are removed and purged
(any configuration files are deleted too).
(any configuration files are deleted too). When --remove-repo is provided,
also remove the apt repository of apt/ppa packages.

clean
clean clears out the local repository (/var/cache/deb-get) of retrieved
Expand Down Expand Up @@ -257,17 +260,17 @@ function install_apt() {
((PACKAGE_INSTALLATION_TRIES++))
add_apt_repo
if ! update_only_repo; then
remove_repo
remove_repo --remove-repo --quiet
return
fi

if ! package_is_installed "${APP}"; then
if ! eula; then
remove_repo
remove_repo --remove-repo --quiet
return
fi
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${APP}"; then
remove_repo
remove_repo --remove-repo --quiet
return
fi
add_installed
Expand Down Expand Up @@ -374,7 +377,7 @@ function remove_deb() {
fi
;;
apt|ppa)
remove_repo;;
remove_repo "${3}";;
esac

}
Expand Down Expand Up @@ -1067,7 +1070,7 @@ function fix_installed() {
if [ "${DEFVER}" != "${OLD_DEFVER}" ]; then
remove_installed "${APP}"
if [[ " apt ppa " =~ " ${OLD_METHOD} " ]]; then
remove_repo
remove_repo --remove-repo
fi
if [ "${METHOD}" = apt ]; then
add_apt_repo
Expand Down Expand Up @@ -1100,22 +1103,64 @@ function remove_old_ppa_repo() {
}

function remove_repo() {
fancy_message info "Removing /usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
${ELEVATE} rm -f "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
fancy_message info "Removing /etc/apt/sources.list.d/${APT_LIST_NAME}.list"
${ELEVATE} rm -f "/etc/apt/sources.list.d/${APT_LIST_NAME}.list"
local count=""
if [ -e "${ETC_DIR}/aptrepos" ]; then
count="$(grep -m 1 "^${APT_LIST_NAME} " "${ETC_DIR}/aptrepos" | cut -d " " -f 2)"
fi
if [ -z "${count}" ]; then
count=0
fi
if [ "${count}" -gt 0 ]; then
((count--))
${ELEVATE} sed -i -E "/^${APT_LIST_NAME} [0-9]+/d" "${ETC_DIR}/aptrepos"
echo "${APT_LIST_NAME} ${count}" | ${ELEVATE} tee -a "${ETC_DIR}/aptrepos" > /dev/null
fi
if [ "${1}" == --remove-repo ]; then
if [ "${count}" -eq 0 ]; then
if [ "${2}" != --quiet ]; then
fancy_message info "Removing /usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
fi
${ELEVATE} rm -f "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
if [ "${2}" != --quiet ]; then
fancy_message info "Removing /etc/apt/sources.list.d/${APT_LIST_NAME}.list"
fi
${ELEVATE} rm -f "/etc/apt/sources.list.d/${APT_LIST_NAME}.list"
if [ -e "${ETC_DIR}/aptrepos" ]; then
${ELEVATE} sed -i -E "/^${APT_LIST_NAME} [0-9]+/d" "${ETC_DIR}/aptrepos"
fi
elif [ "${2}" != --quiet ]; then
fancy_message warn "/etc/apt/sources.list.d/${APT_LIST_NAME}.list was not removed because other packages depend on it."
fi
fi
}

function add_apt_repo() {
local count=""
if [ -e "${ETC_DIR}/aptrepos" ]; then
count="$(grep -m 1 "^${APT_LIST_NAME} " "${ETC_DIR}/aptrepos" | cut -d " " -f 2)"
fi
if [ -z "${count}" ]; then
count=0
fi
if [ "${count}" -eq 0 ] && [ -e "/etc/apt/sources.list.d/${APT_LIST_NAME}.list" ]; then
((count++))
fi
((count++))
if [ -e "${ETC_DIR}/aptrepos" ]; then
${ELEVATE} sed -i -E "/^${APT_LIST_NAME} [0-9]+/d" "${ETC_DIR}/aptrepos"
fi
echo "${APT_LIST_NAME} ${count}" | ${ELEVATE} tee -a "${ETC_DIR}/aptrepos" > /dev/null
if [ ! -d /usr/share/keyrings ]; then
${ELEVATE} mkdir -p /usr/share/keyrings 2>/dev/null
fi
if [ -n "${ASC_KEY_URL}" ]; then
${ELEVATE} wget -q "${ASC_KEY_URL}" -O "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
${ELEVATE} gpg --yes --dearmor "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
${ELEVATE} rm "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
else #GPG_KEY_URL
${ELEVATE} wget -q "${GPG_KEY_URL}" -O "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
if [ ! -e "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg" ]; then
if [ -n "${ASC_KEY_URL}" ]; then
${ELEVATE} wget -q "${ASC_KEY_URL}" -O "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
${ELEVATE} gpg --yes --dearmor "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
${ELEVATE} rm "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring"
else #GPG_KEY_URL
${ELEVATE} wget -q "${GPG_KEY_URL}" -O "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
fi
fi

#TODO: https://superuser.com/questions/1641291/gpg-only-download-a-key-from-a-keyserver
Expand Down Expand Up @@ -1395,6 +1440,11 @@ case "${ACTION}" in
csvlist_debs "${1}";;
purge)
elevate_privs
opt_remove_repo=""
if [ "${1}" == --remove-repo ]; then
opt_remove_repo=--remove-repo
shift
fi
for APP in "${@,,}"; do
FULL_APP="$(IFS=$'\n'; echo "${APPS[*]}" | grep -m 1 "/${APP}$")"
if [ -z "${FULL_APP}" ]; then
Expand All @@ -1407,10 +1457,15 @@ case "${ACTION}" in
exit 1
fi
validate_deb "${FULL_APP}"
remove_deb "${APP}" purge
remove_deb "${APP}" purge "${opt_remove_repo}"
done;;
remove)
elevate_privs
opt_remove_repo=""
if [ "${1}" == --remove-repo ]; then
opt_remove_repo=--remove-repo
shift
fi
for APP in "${@,,}"; do
FULL_APP="$(IFS=$'\n'; echo "${APPS[*]}" | grep -m 1 "/${APP}$")"
if [ -z "${FULL_APP}" ]; then
Expand All @@ -1423,7 +1478,7 @@ case "${ACTION}" in
exit 1
fi
validate_deb "${FULL_APP}"
remove_deb "${APP}"
remove_deb "${APP}" "" "${opt_remove_repo}"
done;;
search)
if [ "${1}" == --include-unsupported ]; then
Expand Down
18 changes: 12 additions & 6 deletions deb-get_completion
Expand Up @@ -9,15 +9,21 @@ function _deb-get() {
if [ "${COMP_CWORD}" = 2 ] && [ "${command}" = update ]; then
COMPREPLY=($(compgen -W "--repos-only" "\\${COMP_WORDS[2]}"))
elif [ "${command}" = show ]; then
COMPREPLY=($(compgen -W "$(./deb-get list --include-unsupported --raw | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
COMPREPLY=($(compgen -W "$(deb-get list --include-unsupported --raw | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
elif [ "${COMP_CWORD}" = 2 ] && [ "${command}" = search ]; then
COMPREPLY=($(compgen -W "--include-unsupported $(./deb-get list --raw | tr "\n" " ")" "\\${COMP_WORDS[${COMP_CWORD}]}"))
COMPREPLY=($(compgen -W "--include-unsupported $(deb-get list --raw | tr "\n" " ")" "\\${COMP_WORDS[${COMP_CWORD}]}"))
elif [ "${COMP_CWORD}" = 3 ] && [ "${command}" = search ] && [ "${COMP_WORDS[2]}" = --include-unsupported ]; then
COMPREPLY=($(compgen -W "$(./deb-get list --include-unsupported --raw | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
COMPREPLY=($(compgen -W "$(deb-get list --include-unsupported --raw | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
elif [ "${command}" = install ]; then
COMPREPLY=($(compgen -W "$(./deb-get list --not-installed | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
elif [[ " reinstall remove purge " =~ " ${command} " ]]; then
COMPREPLY=($(compgen -W "$(./deb-get list --installed | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
COMPREPLY=($(compgen -W "$(deb-get list --not-installed | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
elif [ "${command}" = reinstall ]; then
COMPREPLY=($(compgen -W "$(deb-get list --installed | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
elif [[ " remove purge " =~ " ${command} " ]]; then
if [ "${COMP_CWORD}" = 2 ]; then
COMPREPLY=($(compgen -W "--remove-repo $(deb-get list --installed | tr "\n" " ")" "\\${COMP_WORDS[2]}"))
else
COMPREPLY=($(compgen -W "$(deb-get list --installed | tr "\n" " ")" "${COMP_WORDS[${COMP_CWORD}]}"))
fi
elif [ "${command}" = list ]; then
COMPREPLY=($(compgen -W "--include-unsupported --raw --installed --not-installed" "\\${COMP_WORDS[${COMP_CWORD}]}"))
elif [ "${COMP_CWORD}" = 2 ] && [[ " pretty_list prettylist csv_list csvlist csv " =~ " ${command} " ]]; then
Expand Down
7 changes: 6 additions & 1 deletion docs/deb-get.1
Expand Up @@ -26,7 +26,8 @@ deb-get - An installation manager for 3rd-Party deb packages
.nf
\f[C]
deb-get {update [--repos-only] | upgrade | show <pkg list> | install <pkg list>
| reinstall <pkg list> | remove <pkg list> | purge <pkg list>
| reinstall <pkg list> | remove [--remove-repo] <pkg list>
| purge [--remove-repo] <pkg list>
| search [--include-unsupported] <regex> | cache | clean
| list [--include-unsupported] [--raw|--installed|--not-installed]
| prettylist [<repo>] | csvlist [<repo>] | fix-installed [--old-apps]
Expand Down Expand Up @@ -62,10 +63,14 @@ packages) desired for reinstallation.
\f[B]remove\f[R]
remove is identical to install except that packages are removed instead
of installed.
When \[en]remove-repo is provided, also remove the apt repository of
apt/ppa packages.
.TP
\f[B]purge\f[R]
purge is identical to remove except that packages are removed and purged
(any configuration files are deleted too).
When \[en]remove-repo is provided, also remove the apt repository of
apt/ppa packages.
.TP
\f[B]clean\f[R]
clean clears out the local repository (/var/cache/deb-get) of retrieved
Expand Down
7 changes: 4 additions & 3 deletions docs/deb-get.1.md
Expand Up @@ -17,7 +17,8 @@ deb-get - An installation manager for 3rd-Party deb packages

```
deb-get {update [--repos-only] | upgrade | show <pkg list> | install <pkg list>
| reinstall <pkg list> | remove <pkg list> | purge <pkg list>
| reinstall <pkg list> | remove [--remove-repo] <pkg list>
| purge [--remove-repo] <pkg list>
| search [--include-unsupported] <regex> | cache | clean
| list [--include-unsupported] [--raw|--installed|--not-installed]
| prettylist [<repo>] | csvlist [<repo>] | fix-installed [--old-apps]
Expand Down Expand Up @@ -45,10 +46,10 @@ repositories or via direct download.
: reinstall is followed by one package (or a space-separated list of packages) desired for reinstallation.

**remove**
: remove is identical to install except that packages are removed instead of installed.
: remove is identical to install except that packages are removed instead of installed. When --remove-repo is provided, also remove the apt repository of apt/ppa packages.

**purge**
: purge is identical to remove except that packages are removed and purged (any configuration files are deleted too).
: purge is identical to remove except that packages are removed and purged (any configuration files are deleted too). When --remove-repo is provided, also remove the apt repository of apt/ppa packages.

**clean**
: clean clears out the local repository (/var/cache/deb-get) of retrieved package files.
Expand Down