135 lines
2.9 KiB
Bash
Executable File
135 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# mp-pool-clean | MatterLinux pool cleanup script
|
|
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
|
|
|
# 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
|
|
# (at your option) 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 <https://www.gnu.org/licenses/>.
|
|
|
|
#############################
|
|
## import common functions ##
|
|
#############################
|
|
location=$(dirname "${0}")
|
|
location=$(realpath "${location}")
|
|
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
|
|
|
source "${commonsh}" > /dev/null
|
|
|
|
if [ "${?}" != "0" ]; then
|
|
echo "Failed to import mtsc-common"
|
|
exit 1
|
|
fi
|
|
|
|
#################
|
|
## main script ##
|
|
#################
|
|
target="${1}"
|
|
|
|
if [ -z "${target}" ]; then
|
|
error "Please specify a pool directory"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "${target}" ]; then
|
|
error "Pool directory \"${target}\" does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
cd "${target}"
|
|
check_ret "Failed to change directory into \"${target}\""
|
|
|
|
if [ ! -f "pool.sh" ]; then
|
|
error "Package directory does not contain a pool script (pool.sh)"
|
|
exit 1
|
|
fi
|
|
|
|
# source and verify the package script
|
|
source "pool.sh"
|
|
check_ret "Failed to source the pool script"
|
|
|
|
check_pool_vars
|
|
check_ret
|
|
|
|
# setup package directories
|
|
pkgpath="$(realpath .)"
|
|
distpath="$(realpath 'dist')"
|
|
srcpath="$(realpath "${SRCDIR}")"
|
|
|
|
if [ ! -d "${srcpath}" ]; then
|
|
error "Source path does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "${distpath}" ]; then
|
|
info "Nothing to do (dist directory does not exist)"
|
|
exit 1
|
|
fi
|
|
|
|
# source and store every package
|
|
files=("INFO" "LIST")
|
|
pc="$(ls -1q "${srcpath}" | wc -l)"
|
|
pi=0
|
|
|
|
info "Sourcing all the packages"
|
|
set_indent
|
|
|
|
for pkg in "${srcpath}/"*; do
|
|
pkg_name=$(basename "${pkg}")
|
|
pi=$((pi+1))
|
|
|
|
if should_ignore "${pkg_name}"; then
|
|
info "(${pi}/${pc}) Ignoring \"${pkg_name}\""
|
|
continue
|
|
fi
|
|
|
|
info "(${pi}/${pc}) Sourcing \"${pkg_name}\""
|
|
|
|
source "${pkg}/pkg.sh"
|
|
check_ret "(${pi}/${pc}) Failed to import the source script for \"${pkg_name}\""
|
|
|
|
check_pkg_vars
|
|
check_ret
|
|
|
|
files+=("${NAME}_${VERSION}.mpf")
|
|
files+=("${NAME}_${VERSION}.mpf.sig")
|
|
|
|
clean_pkg_vars
|
|
done
|
|
|
|
success "Completed"
|
|
unset_indent
|
|
|
|
info "Cleaning up old archives and signatures"
|
|
pushd "${distpath}" > /dev/null
|
|
set_indent
|
|
|
|
for file in *; do
|
|
found=0
|
|
for f in "${files[@]}"; do
|
|
if [ "${file}" == "${f}" ]; then
|
|
found=1
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ $found -eq 0 ]; then
|
|
info "Removing ${file}"
|
|
rm "${file}"
|
|
check_ret "Failed to remove ${file}"
|
|
fi
|
|
done
|
|
|
|
popd > /dev/null
|
|
success "Completed"
|
|
unset_indent
|