Skip to content

Commit 05ac56a

Browse files
committed
add pin for packages that exist in native repo
1 parent d56f312 commit 05ac56a

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

deb-get

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ function install_apt() {
342342
remove_repo --remove-repo --quiet
343343
return
344344
fi
345+
if [[ "${APT_PIN}" == 1 ]]; then
346+
add_apt_pin "${APP}" "${APT_REPO_URL}"
347+
else
348+
remove_apt_pin "${APP}"
349+
fi
345350
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${APP}"; then
346351
remove_repo --remove-repo --quiet
347352
return
@@ -350,6 +355,11 @@ function install_apt() {
350355
maint_supported_cache
351356
else
352357
if [ "${ACTION}" == "reinstall" ]; then
358+
if [[ "${APT_PIN}" == 1 ]]; then
359+
add_apt_pin "${APP}" "${APT_REPO_URL}"
360+
else
361+
remove_apt_pin "${APP}"
362+
fi
353363
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y --reinstall --allow-downgrades install "${APP}"; then
354364
return
355365
fi
@@ -379,6 +389,11 @@ function install_deb() {
379389
if ! download_deb "${URL}" "${FILE}"; then
380390
return
381391
fi
392+
if [[ "${APT_PIN}" == 1 ]]; then
393+
add_apt_pin "${APP}"
394+
else
395+
remove_apt_pin "${APP}"
396+
fi
382397
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y install "${CACHE_DIR}/${FILE}"; then
383398
return
384399
fi
@@ -389,6 +404,11 @@ function install_deb() {
389404
if ! download_deb "${URL}" "${FILE}"; then
390405
return
391406
fi
407+
if [[ "${APT_PIN}" == 1 ]]; then
408+
add_apt_pin "${APP}"
409+
else
410+
remove_apt_pin "${APP}"
411+
fi
392412
if ! ${ELEVATE} apt-get -q=2 -o Dpkg::Progress-Fancy="1" -y --reinstall --allow-downgrades install "${CACHE_DIR}/${FILE}"; then
393413
return
394414
fi
@@ -440,7 +460,7 @@ function remove_deb() {
440460
apt|ppa)
441461
remove_repo "${3}";;
442462
esac
443-
463+
remove_apt_pin "${APP}"
444464
}
445465

446466
function version_deb() {
@@ -1345,6 +1365,27 @@ function remove_installed() {
13451365
${ELEVATE} sed -i "/^${1} /d" "${ETC_DIR}/installed"
13461366
}
13471367

1368+
function add_apt_pin() {
1369+
local DOMAIN="${2#*//}"; DOMAIN="${DOMAIN%%/*}"; DOMAIN="${DOMAIN%%[[:space:]]*}"
1370+
if ! [[ -d /etc/apt/preferences.d ]]; then ${ELEVATE} mkdir "/etc/apt/preferences.d"; fi
1371+
fancy_message info "Adding pin: /etc/apt/preferences.d/99_deb-get_${1}"
1372+
# if a second parameter is not passed, origin will be set to "" which will prioritize local deb files.
1373+
printf "%s\n" "Package: ${1}" "Pin: origin \"${DOMAIN}\"" "Pin-Priority: 1001" | ${ELEVATE} tee "/etc/apt/preferences.d/99_deb-get_${1}" > /dev/null
1374+
if [[ -n "${DOMAIN}" ]]; then
1375+
update_only_repo
1376+
else
1377+
update_apt
1378+
fi
1379+
}
1380+
1381+
function remove_apt_pin() {
1382+
if [[ -e "/etc/apt/preferences.d/99_deb-get_${1}" ]]; then
1383+
fancy_message info "Removing /etc/apt/preferences.d/99_deb-get_${1}"
1384+
${ELEVATE} rm "/etc/apt/preferences.d/99_deb-get_${1}"
1385+
update_apt
1386+
fi
1387+
}
1388+
13481389
function list_apps() {
13491390
list_local_apps; list_repo_apps
13501391
declare -F | sed -n -e 's|declare -f deb_|00-builtin/|gp'

0 commit comments

Comments
 (0)