#!/bin/bash # # shellcheck disable=SC1091,SC2086 # # @license http://www.gnu.org/licenses/gpl.html GPL Version 3 # @author OpenMediaVault Plugin Developers # @copyright Copyright (c) 2015-2026 openmediavault plugin developers # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . . /etc/default/openmediavault . /usr/share/openmediavault/scripts/helper-functions . /usr/share/openmediavault/sysinfo/functions declare -i i=0 OMV_APT_KERNEL_BACKPORTS_PINPRIORITY=${OMV_APT_KERNEL_BACKPORTS_PINPRIORITY:-500} export LC_ALL=C ((i++)) echo "${i}. Cleaning apt cache files..." /usr/bin/apt-get clean ((i++)) echo -e "\n${i}. Clearing available dpkg packages..." /usr/bin/dpkg --clear-avail 2>/dev/null ((i++)) echo -e "\n${i}. Removing apt lists..." rm -rfv /var/lib/apt/lists/* ((i++)) echo -e "\n${i}. Removing OpenMediaVault cache packages..." rm -fv /var/cache/openmediavault/archives/* ((i++)) echo -e "\n${i}. Creating new OpenMediaVault packages file..." touch /var/cache/openmediavault/archives/Packages # add repos if [ "${1}" = "repos" ]; then arch="$(dpkg --print-architecture)" backports=${OMV_APT_USE_KERNEL_BACKPORTS:-"yes"} docker=$(omv_config_get "/config/system/omvextras/docker") dist="$(lsb_release --codename --short)" omv_codename=$(omv_product_info "versionname") # repo and key mirrors in priority order, used unless overridden repo_urls=("https://openmediavault-plugin-developers.github.io/packages/debian" "https://omv-extras.org/debian2") key_urls=("https://openmediavault-plugin-developers.github.io/packages/debian/omvextras2030.gpg" "https://omv-extras.org/omvextras2030.gpg") if [ -n "${OMV_EXTRAS_APT_REPOSITORY_URL}" ]; then repo_urls=("${OMV_EXTRAS_APT_REPOSITORY_URL}") fi if [ -n "${OMV_EXTRAS_KEY_URL}" ]; then key_urls=("${OMV_EXTRAS_KEY_URL}") fi docker_url=${OMV_DOCKER_APT_REPOSITORY_URL:-"https://download.docker.com/linux/debian"} docker_key_url=${OMV_DOCKER_KEY_URL:-"https://download.docker.com/linux/debian/gpg"} key="/usr/share/keyrings/omvextras.gpg" docker_key="/usr/share/keyrings/docker.gpg" list="/etc/apt/sources.list.d/omvextras.sources" docker_list="/etc/apt/sources.list.d/omvdocker.sources" pref="/etc/apt/preferences.d/omvextras.pref" mirrors="/etc/apt/mirrors/omvextras.txt" ((i++)) echo -e "\n${i}. Remove old omv-extras apt list files..." grep -l 'openmediavault-plugin-developers' /etc/apt/sources.list.d/* | sudo xargs -r rm -fv rm -fv /etc/apt/keyrings/docker.gpg ((i++)) echo -e "\n${i}. Adding omv-extras repo and key..." mkdir -pv "$(dirname ${key})" rm -f ${mirrors} if [ ${#repo_urls[@]} -gt 1 ]; then # apt only tries the next mirror if a file could not be retrieved mkdir -pv "$(dirname ${mirrors})" for ((j=0; j<${#repo_urls[@]}; j++)); do echo -e "${repo_urls[j]}\tpriority:$((j+1))" >> ${mirrors} done chmod 644 ${mirrors} uris="mirror+file:${mirrors}" else uris="${repo_urls[0]}" fi echo -e "Types: deb\nURIs: ${uris}\nSuites: ${omv_codename,,}\nComponents: main\nSigned-By: ${key}" > ${list} chmod 644 ${list} # only replace the existing key if a download succeeds tmpkey="$(mktemp)" for key_url in "${key_urls[@]}"; do if wget --quiet --output-document=- "${key_url}" | gpg --dearmor > "${tmpkey}" && [ -s "${tmpkey}" ]; then mv -f "${tmpkey}" "${key}" chmod 644 ${key} break fi echo "Failed to download key from ${key_url}" done rm -f "${tmpkey}" # backports pinning rm -f ${pref} if omv_checkyesno ${backports}; then ((i++)) echo -e "\n${i}. Adding backports pinning..." pkgs=("src:zfs-linux" "libvirt*" "qemu*" "seabios") for ((j=0; j<${#pkgs[@]}; j++)); do echo -e "Package: ${pkgs[j]}\nPin: release n=${dist}-backports\nPin-Priority: ${OMV_APT_KERNEL_BACKPORTS_PINPRIORITY}\n" >> ${pref} done chmod 644 ${pref} fi # docker repo grep -l 'docker' /etc/apt/sources.list.d/* | sudo xargs -r rm -fv if omv_checkyesno ${docker}; then ((i++)) echo -e "\n${i}. Adding docker repo and key..." echo -e "Types: deb\nURIs: ${docker_url}\nSuites: ${dist,,}\nComponents: stable\nSigned-By: ${docker_key}" > ${docker_list} wget --quiet --output-document=- "${docker_key_url}" | gpg --dearmor > "${docker_key}" chmod 644 ${docker_list} ${docker_key} fi fi ((i++)) echo -e "\n${i}. Updating apt..." /usr/bin/apt-get update ((i++)) echo -e "\n${i}. Saving current package list..." packages="/var/cache/openmediavault/currently_installed_packages.list" /usr/bin/dpkg -l | awk '$1 == "ii" { print $2 "=" $3 " \\"}' > ${packages} ((i++)) echo -e "\n${i}. Updating plugin index..." /usr/sbin/omv-mkaptidx exit 0