From d71403c189f3f008f25c8a39b498ed02ea9701b9 Mon Sep 17 00:00:00 2001 From: oklopfer <104327997+oklopfer@users.noreply.github.com> Date: Thu, 7 Mar 2024 19:51:24 -0500 Subject: [PATCH] fix merge conflicts (#9) Co-authored-by: oklopfer <104327997+oklopfer@users.noreply.github.com> Co-authored-by: ook37 Co-authored-by: Elsie Co-authored-by: Elsie Co-authored-by: V <150687949+vigress8@users.noreply.github.com> Co-authored-by: David Brochero <65723952+D-Brox@users.noreply.github.com> fix({download,install}-local.sh): use more `clean_fail_down` (#1043) fix(search.sh): mapfile append (#1049) fix(upgrade.sh): export `CARCH` & `DISTRO` (#1047) --- .github/workflows/publish-docker.yml | 166 +++++++++++++++++++++++++++ install.sh | 6 +- misc/scripts/build-local.sh | 163 +++++++++++++++----------- misc/scripts/checks.sh | 134 ++++++++++++++------- misc/scripts/download-local.sh | 163 +++++++++++++++----------- misc/scripts/download.sh | 10 +- misc/scripts/install-local.sh | 143 ++++++++++++----------- misc/scripts/search.sh | 2 +- misc/scripts/upgrade.sh | 40 ++++++- pacstall | 14 +-- 10 files changed, 582 insertions(+), 259 deletions(-) create mode 100644 .github/workflows/publish-docker.yml mode change 100644 => 100755 misc/scripts/build-local.sh mode change 100644 => 100755 misc/scripts/download-local.sh diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 000000000..1dd90ba53 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,166 @@ +name: Publish Pacstall Docker Images + +on: + workflow_dispatch: + inputs: + vertag: + description: 'Version Tag' + required: false + push: + branches: + - develop + - master + tags: + - '*' +env: + INPUT_VERTAG: ${{ github.event.inputs.vertag }} + REGISTRY: ghcr.io + +jobs: + + build: + strategy: + matrix: + OS: ["ubuntu:latest", "ubuntu:devel", "ubuntu:rolling", "debian:stable", "debian:testing", "debian:unstable"] + platform: ["linux/amd64", "linux/arm64"] + fail-fast: true + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Dockerfile + run: | + vertag=${{ env.INPUT_VERTAG }} + if [[ -z ${vertag} ]]; then + vertag=${{ github.ref_name }} + fi + platform=${{ matrix.platform }} + arch=${platform#*/} + distro=${{ matrix.OS }} + distro_tag="${distro/:/-}" + curl -fsSL https://raw.githubusercontent.com/pacstall/docker/master/pacstall-docker-builder -o pacstall-docker-builder + chmod +x pacstall-docker-builder + ./pacstall-docker-builder -f -a ${arch} -d ${distro} -v ${vertag} + echo "BUILT_DOCKFILE=Dockerfile-Pacstall-${vertag}-${arch}-${distro_tag}-$(date +%Y%m%d)" >> $GITHUB_ENV + echo "DOCK_LABEL=${vertag}" >> $GITHUB_ENV + echo "PLATFORM_PAIR=${distro_tag}-${arch}" >> $GITHUB_ENV + echo "REGISTRY_IMAGE=${{ env.REGISTRY }}/${{ github.repository_owner }}/${distro_tag}" >> $GITHUB_ENV + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=${{ env.DOCK_LABEL }} + flavor: latest=true + + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./${{ env.BUILT_DOCKFILE }} + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + strategy: + matrix: + OS: ["ubuntu:latest", "ubuntu:devel", "ubuntu:rolling", "debian:stable", "debian:testing", "debian:unstable"] + fail-fast: true + runs-on: ubuntu-latest + needs: [build] + steps: + - name: Load envars + run: | + vertag=${{ env.INPUT_VERTAG }} + if [[ -z ${vertag} ]]; then + vertag=${{ github.ref_name }} + fi + distro=${{ matrix.OS }} + distro_tag="${distro/:/-}" + echo "DOCK_LABEL=${vertag}" >> $GITHUB_ENV + if [[ ${vertag} == "develop" ]]; then + echo "FLAVOR_LATEST=false" >> $GITHUB_ENV + echo "HASH_DOCK_LABEL=${vertag}-${GITHUB_SHA:0:8}" >> $GITHUB_ENV + elif [[ ${vertag} == "master" ]]; then + echo "FLAVOR_LATEST=true" >> $GITHUB_ENV + echo "HASH_DOCK_LABEL=${vertag}-${GITHUB_SHA:0:8}" >> $GITHUB_ENV + else + echo "FLAVOR_LATEST=true" >> $GITHUB_ENV + fi + echo "DISTRO_TAG=${distro_tag}" >> $GITHUB_ENV + echo "REGISTRY_IMAGE=${{ env.REGISTRY }}/${{ github.repository_owner }}/${distro_tag}" >> $GITHUB_ENV + + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-${{ env.DISTRO_TAG }}* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + version: v0.12.0 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=${{ env.DOCK_LABEL }} + type=raw,value=${{ env.HASH_DOCK_LABEL }} + flavor: latest=${{ env.FLAVOR_LATEST }} + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create \ + --annotation "index:org.opencontainers.image.description=Contains amd64/x86_64 + arm64/aarch64 pacstall:${{ env.DOCK_LABEL }} images for ${{ matrix.OS }}, from $(date +%Y%m%d)." \ + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/install.sh b/install.sh index a5387f9f4..5c9176815 100755 --- a/install.sh +++ b/install.sh @@ -117,7 +117,7 @@ apt-get install -qq -y curl wget build-essential unzip git zstd iputils-ping lsb LOGDIR="/var/lib/pacstall/metadata" STGDIR="/usr/share/pacstall" -SRCDIR="/tmp/pacstall" +PACDIR="/tmp/pacstall" PACSTALL_USER=$(logname 2> /dev/null || echo "${SUDO_USER:-${USER}}") fancy_message info "Making directories" @@ -125,8 +125,8 @@ mkdir -p "$STGDIR" mkdir -p "$STGDIR/scripts" mkdir -p "$STGDIR/repo" -mkdir -p "$SRCDIR" -chown "$PACSTALL_USER" -R "$SRCDIR" +mkdir -p "$PACDIR" +chown "$PACSTALL_USER" -R "$PACDIR" mkdir -p "$LOGDIR" mkdir -p "/var/log/pacstall/error_log" diff --git a/misc/scripts/build-local.sh b/misc/scripts/build-local.sh old mode 100644 new mode 100755 index fda4947e4..1ec5e46bf --- a/misc/scripts/build-local.sh +++ b/misc/scripts/build-local.sh @@ -24,27 +24,28 @@ function cleanup() { if [[ -n $KEEP ]]; then - rm -rf "/tmp/pacstall-keep/$name" - mkdir -p "/tmp/pacstall-keep/$name" + rm -rf "/tmp/pacstall-keep/$pkgname" + mkdir -p "/tmp/pacstall-keep/$pkgname" if [[ -f /tmp/pacstall-pacdeps-"$PACKAGE" ]]; then - sudo mv /tmp/pacstall-pacdep/* "/tmp/pacstall-keep/$name" + sudo mv /tmp/pacstall-pacdep/* "/tmp/pacstall-keep/$pkgname" else - sudo mv "${SRCDIR:?}"/* "/tmp/pacstall-keep/$name" + sudo mv "${PACDIR:?}"/* "/tmp/pacstall-keep/$pkgname" fi fi if [[ -f "/tmp/pacstall-pacdeps-$PACKAGE" ]]; then sudo rm -rf "/tmp/pacstall-pacdeps-$PACKAGE" sudo rm -rf /tmp/pacstall-pacdep else - sudo rm -rf "${SRCDIR:?}"/* - # just in case we quit before $name is declared, we should be able to remove a fake directory so it doesn't exit out the script - sudo rm -rf "${STOWDIR:-/usr/src/pacstall}/${name:-raaaaaaaandom}" + sudo rm -rf "${PACDIR:?}"/* + if [[ -n $pkgname ]]; then + sudo rm -rf "${STOWDIR:-/usr/src/pacstall}/${pkgname}" + fi rm -rf /tmp/pacstall-gives fi - sudo rm -rf "${STOWDIR}/${name:-$PACKAGE}.deb" + sudo rm -rf "${STOWDIR}/${pkgname:-$PACKAGE}.deb" rm -f /tmp/pacstall-select-options - unset name repology pkgver git_pkgver epoch url source depends makedepends breaks replace gives pkgdesc hash optdepends ppa arch maintainer pacdeps patch PACPATCH NOBUILDDEP provides incompatible optinstall pkgbase homepage backup pkgrel mask pac_functions repo priority noextract 2> /dev/null - unset -f post_install post_remove pre_install prepare build package 2> /dev/null + unset pkgname repology pkgver git_pkgver epoch source_url source depends makedepends conflicts breaks replaces gives pkgdesc hash optdepends ppa arch maintainer pacdeps patch PACPATCH NOBUILDDEP provides incompatible optinstall srcdir url backup pkgrel mask pac_functions repo priority noextract 2> /dev/null + unset -f pre_install pre_upgrade pre_remove post_install post_upgrade post_remove prepare build package 2> /dev/null sudo rm -f "${pacfile}" } @@ -52,12 +53,12 @@ function deblog() { local key="$1" shift local content=("$@") - echo "$key: ${content[*]}" | sudo tee -a "$STOWDIR/$name/DEBIAN/control" > /dev/null + echo "$key: ${content[*]}" | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/control" > /dev/null } function clean_builddir() { - sudo rm -rf "${STOWDIR}/${name:?}" - sudo rm -f "${STOWDIR}/${name}.deb" + sudo rm -rf "${STOWDIR}/${pkgname:?}" + sudo rm -f "${STOWDIR}/${pkgname}.deb" } function prompt_optdepends() { @@ -181,7 +182,7 @@ function prompt_optdepends() { function generate_changelog() { printf "%s (%s) %s; urgency=medium\n\n * Version now at %s.\n\n -- %s %(%a, %d %b %Y %T %z)T\n" \ - "${name}" "${full_version}" "$(lsb_release -sc)" "${full_version}" "${maintainer[0]}" + "${pkgname}" "${full_version}" "$(lsb_release -sc)" "${full_version}" "${maintainer[0]}" } function clean_logdir() { @@ -192,7 +193,7 @@ function clean_logdir() { } function createdeb() { - local name="$1" + local pkgname="$1" if ((PACSTALL_INSTALL == 0)); then # We are not going to immediately install, meaning the user might want to share their deb with someone else, so create the highest compression. local flags=("-19" "-T0" "-q") @@ -204,7 +205,7 @@ function createdeb() { local compression="gz" local command="gzip" fi - cd "$STOWDIR/$name" || return 1 + cd "$STOWDIR/$pkgname" || return 1 # https://tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO/#AEN66 echo "2.0" | sudo tee debian-binary > /dev/null sudo tar -cf "$PWD/control.tar" -T /dev/null @@ -231,19 +232,19 @@ function createdeb() { fancy_message sub "Compressing" sudo "$command" "${flags[@]}" "$DATA_LOCATION" "$CONTROL_LOCATION" - sudo ar -rU "$name.deb" debian-binary control.tar."$compression" data.tar."$compression" > /dev/null 2>&1 - sudo mv "$name.deb" .. + sudo ar -rU "$pkgname.deb" debian-binary control.tar."$compression" data.tar."$compression" > /dev/null 2>&1 + sudo mv "$pkgname.deb" .. sudo rm -f debian-binary control.tar."$compression" data.tar."$compression" } function makedeb() { # It looks weird for it to say: `Packaging foo as foo` - if [[ -n $gives && $name != "$gives" ]]; then - fancy_message info "Packaging ${BGreen}$name${NC} as ${BBlue}$gives${NC}" + if [[ -n $gives && $pkgname != "$gives" ]]; then + fancy_message info "Packaging ${BGreen}$pkgname${NC} as ${BBlue}$gives${NC}" else - fancy_message info "Packaging ${BGreen}$name${NC}" + fancy_message info "Packaging ${BGreen}$pkgname${NC}" fi - deblog "Package" "${gives:-$name}" + deblog "Package" "${gives:-$pkgname}" if [[ $pkgver =~ ^[0-9] ]]; then deblog "Version" "${full_version}" @@ -273,10 +274,10 @@ function makedeb() { deblog "Priority" "${priority:-optional}" fi - if [[ $name == *-git ]]; then + if [[ $pkgname == *-git ]]; then parse_source_entry "${source[0]}" # shellcheck disable=SC2031 - local vcsurl="${url#file://}" + local vcsurl="${source_url#file://}" vcsurl="${vcsurl#git+}" if [[ -n ${git_branch} ]]; then deblog "Vcs-Git" "${vcsurl} -b ${git_branch}" @@ -297,15 +298,25 @@ function makedeb() { deblog "Provides" "$(sed 's/ /, /g' <<< "${provides[@]}")" fi - if [[ -n $replace ]]; then + if [[ -n ${conflicts[*]} ]]; then + # shellcheck disable=SC2001 + deblog "Conflicts" "$(sed 's/ /, /g' <<< "${conflicts[@]}")" + fi + + if [[ -n ${breaks[*]} ]]; then + # shellcheck disable=SC2001 + deblog "Breaks" "$(sed 's/ /, /g' <<< "${breaks[@]}")" + fi + + if [[ -n ${replaces[*]} ]]; then # shellcheck disable=SC2001 - deblog "Conflicts" "$(sed 's/ /, /g' <<< "${replace[@]}")" + deblog "Conflicts" "$(sed 's/ /, /g' <<< "${replaces[@]}")" # shellcheck disable=SC2001 - deblog "Replace" "$(sed 's/ /, /g' <<< "${replace[@]}")" + deblog "Replaces" "$(sed 's/ /, /g' <<< "${replaces[@]}")" fi - if [[ -n ${homepage} ]]; then - deblog "Homepage" "${homepage}" + if [[ -n ${url} ]]; then + deblog "Homepage" "${url}" fi if [[ -n ${maintainer[*]} ]]; then @@ -340,12 +351,28 @@ function makedeb() { else deblog "Description" "${pkgdesc}" fi + if is_package_installed "${pkgname}"; then + if type -t pre_upgrade &> /dev/null; then + pre_inst_upg="pre_upgrade" + else + pre_inst_upg="pre_install" + fi + if type -t post_upgrade &> /dev/null; then + post_inst_upg="post_upgrade" + else + post_inst_upg="post_install" + fi + else + pre_inst_upg="pre_install" + post_inst_upg="post_install" + fi - for i in {post_remove,post_install,pre_install}; do + for i in {"${pre_inst_upg}",pre_remove,"${post_inst_upg}",post_remove}; do case "$i" in + "${pre_inst_upg}") export deb_post_file="preinst" ;; + pre_remove) export deb_post_file="prerm" ;; + "${post_inst_upg}") export deb_post_file="postinst" ;; post_remove) export deb_post_file="postrm" ;; - post_install) export deb_post_file="postinst" ;; - pre_install) export deb_post_file="preinst" ;; esac if is_function "$i"; then local pac_min_functions pacmf_out @@ -363,21 +390,21 @@ function makedeb() { 'eval echo ~"$PACSTALL_USER"' '}' 'export homedir="$(get_homedir)"' 'if [[ -n $PACSTALL_BUILD_CORES ]];then' 'declare -g NCPU="${PACSTALL_BUILD_CORES:-1}"' 'else' 'declare -g NCPU="$(nproc)"' 'fi' ) - echo '#!/bin/bash' | sudo tee "$STOWDIR/$name/DEBIAN/$deb_post_file" > /dev/null + echo '#!/bin/bash' | sudo tee "$STOWDIR/$pkgname/DEBIAN/$deb_post_file" > /dev/null for pacmf_out in "${pac_min_functions[@]}"; do - echo "${pacmf_out}" | sudo tee -a "$STOWDIR/$name/DEBIAN/$deb_post_file" > /dev/null + echo "${pacmf_out}" | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/$deb_post_file" > /dev/null done { cat "${pacfile}" echo -e "\n$i" - } | sudo tee -a "$STOWDIR/$name/DEBIAN/$deb_post_file" > /dev/null + } | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/$deb_post_file" > /dev/null fi done - echo -e "sudo rm -f $METADIR/$name\nsudo rm -f /etc/apt/preferences.d/$name-pin" | sudo tee -a "$STOWDIR/$name/DEBIAN/postrm" > /dev/null + echo -e "sudo rm -f $METADIR/$pkgname\nsudo rm -f /etc/apt/preferences.d/$pkgname-pin" | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/postrm" > /dev/null local postfile for postfile in {postrm,postinst,preinst}; do - sudo chmod -x "$STOWDIR/$name/DEBIAN/${postfile}" &> /dev/null - sudo chmod 755 "$STOWDIR/$name/DEBIAN/${postfile}" &> /dev/null + sudo chmod -x "$STOWDIR/$pkgname/DEBIAN/${postfile}" &> /dev/null + sudo chmod 755 "$STOWDIR/$pkgname/DEBIAN/${postfile}" &> /dev/null done # Handle `backup` key @@ -397,27 +424,27 @@ function makedeb() { if [[ ${file:2:1} == "/" ]]; then fancy_message warn "'${file}' cannot contain path starting with '/'... Skipping" && continue fi - if [[ -f "$STOWDIR/$name/${file:2}" ]]; then + if [[ -f "$STOWDIR/$pkgname/${file:2}" ]]; then fancy_message warn "'${file}' is inside the package... Skipping" && continue fi - echo "remove-on-upgrade /${file:2}" | sudo tee -a "$STOWDIR/$name/DEBIAN/conffiles" > /dev/null + echo "remove-on-upgrade /${file:2}" | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/conffiles" > /dev/null else if [[ ${file:0:1} == "/" ]]; then fancy_message warn "'${file}' cannot contain path starting with '/'... Skipping" && continue fi - echo "/${file}" | sudo tee -a "$STOWDIR/$name/DEBIAN/conffiles" > /dev/null + echo "/${file}" | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/conffiles" > /dev/null fi done fi - deblog "Installed-Size" "$(sudo du -s --apparent-size --exclude=DEBIAN -- "$STOWDIR/$name" | cut -d$'\t' -f1)" - install_size="$(sudo du -s --apparent-size --exclude=DEBIAN -- "$STOWDIR/$name" | cut -d$'\t' -f1 | numfmt --to=iec)" + deblog "Installed-Size" "$(sudo du -s --apparent-size --exclude=DEBIAN -- "$STOWDIR/$pkgname" | cut -d$'\t' -f1)" + install_size="$(sudo du -s --apparent-size --exclude=DEBIAN -- "$STOWDIR/$pkgname" | cut -d$'\t' -f1 | numfmt --to=iec)" export install_size - generate_changelog | sudo tee -a "$STOWDIR/$name/DEBIAN/changelog" > /dev/null + generate_changelog | sudo tee -a "$STOWDIR/$pkgname/DEBIAN/changelog" > /dev/null cd "$STOWDIR" || return 1 - if ! createdeb "$name"; then + if ! createdeb "$pkgname"; then fancy_message error "Could not create package" error_log 5 "install $PACKAGE" fancy_message info "Cleaning up" @@ -427,44 +454,44 @@ function makedeb() { if ((PACSTALL_INSTALL != 0)); then # --allow-downgrades is to allow git packages to "downgrade", because the commits aren't necessarily a higher number than the last version - if ! sudo -E apt-get install --reinstall "$STOWDIR/$name.deb" -y --allow-downgrades 2> /dev/null; then + if ! sudo -E apt-get install --reinstall "$STOWDIR/$pkgname.deb" -y --allow-downgrades 2> /dev/null; then echo -ne "\t" - fancy_message error "Failed to install $name deb" + fancy_message error "Failed to install $pkgname deb" error_log 8 "install $PACKAGE" - sudo dpkg -r --force-all "$name" > /dev/null + sudo dpkg -r --force-all "$pkgname" > /dev/null fancy_message info "Cleaning up" cleanup exit 1 fi - if [[ -f /tmp/pacstall-pacdeps-"$name" ]]; then - sudo apt-mark auto "${gives:-$name}" 2> /dev/null + if [[ -f /tmp/pacstall-pacdeps-"$pkgname" ]]; then + sudo apt-mark auto "${gives:-$pkgname}" 2> /dev/null fi - sudo rm -rf "$STOWDIR/$name" - sudo rm -rf "$SRCDIR/$name.deb" + sudo rm -rf "$STOWDIR/$pkgname" + sudo rm -rf "$PACDIR/$pkgname.deb" if ! [[ -d /etc/apt/preferences.d/ ]]; then sudo mkdir -p /etc/apt/preferences.d fi - local combined_pinning=("${provides[@]}" "${gives:-${name}}") - echo "Package: ${combined_pinning[*]}" | sudo tee "/etc/apt/preferences.d/${name}-pin" > /dev/null - echo "Pin: version *" | sudo tee -a "/etc/apt/preferences.d/${name}-pin" > /dev/null - echo "Pin-Priority: -1" | sudo tee -a "/etc/apt/preferences.d/${name}-pin" > /dev/null + local combined_pinning=("${provides[@]}" "${gives:-${pkgname}}") + echo "Package: ${combined_pinning[*]}" | sudo tee "/etc/apt/preferences.d/${pkgname}-pin" > /dev/null + echo "Pin: version *" | sudo tee -a "/etc/apt/preferences.d/${pkgname}-pin" > /dev/null + echo "Pin-Priority: -1" | sudo tee -a "/etc/apt/preferences.d/${pkgname}-pin" > /dev/null return 0 else - sudo mv "$STOWDIR/$name.deb" "$PACDEB_DIR" - sudo chown "$PACSTALL_USER":"$PACSTALL_USER" "$PACDEB_DIR/$name.deb" - fancy_message info "Package built at ${BGreen}$PACDEB_DIR/$name.deb${NC}" - fancy_message info "Moving ${BGreen}$STOWDIR/$name${NC} to ${BGreen}/tmp/pacstall-no-build/$name${NC}" - sudo rm -rf "/tmp/pacstall-no-build/$name" - mkdir -p "/tmp/pacstall-no-build/$name" - sudo mv "$STOWDIR/$name" "/tmp/pacstall-no-build/$name" + sudo mv "$STOWDIR/$pkgname.deb" "$PACDEB_DIR" + sudo chown "$PACSTALL_USER":"$PACSTALL_USER" "$PACDEB_DIR/$pkgname.deb" + fancy_message info "Package built at ${BGreen}$PACDEB_DIR/$pkgname.deb${NC}" + fancy_message info "Moving ${BGreen}$STOWDIR/$pkgname${NC} to ${BGreen}/tmp/pacstall-no-build/$pkgname${NC}" + sudo rm -rf "/tmp/pacstall-no-build/$pkgname" + mkdir -p "/tmp/pacstall-no-build/$pkgname" + sudo mv "$STOWDIR/$pkgname" "/tmp/pacstall-no-build/$pkgname" cleanup exit 0 fi } function write_meta() { - echo "_name=\"$name\"" + echo "_name=\"$pkgname\"" echo "_version=\"${full_version}\"" echo "_install_size=\"${install_size}\"" printf '_date=\"%(%a %b %_d %r %Z %Y)T\"\n' @@ -476,13 +503,13 @@ function write_meta() { if [[ -n $ppa ]]; then echo "_ppa=(${ppa[*]})" fi - if [[ -n $homepage ]]; then - echo "_homepage=\"${homepage}\"" + if [[ -n $url ]]; then + echo "_homepage=\"${url}\"" fi if [[ -n $gives ]]; then echo "_gives=\"$gives\"" fi - if [[ -f /tmp/pacstall-pacdeps-"$name" ]]; then + if [[ -f /tmp/pacstall-pacdeps-"$pkgname" ]]; then echo '_pacstall_depends="true"' fi if [[ $local == 'no' ]]; then @@ -527,7 +554,7 @@ function meta_log() { fi # Metadata writing - write_meta | sudo tee "$METADIR/$name" > /dev/null + write_meta | sudo tee "$METADIR/$pkgname" > /dev/null } # vim:set ft=sh ts=4 sw=4 noet: diff --git a/misc/scripts/checks.sh b/misc/scripts/checks.sh index 2385b4a39..04d1ebdb6 100755 --- a/misc/scripts/checks.sh +++ b/misc/scripts/checks.sh @@ -24,32 +24,32 @@ # A collection of checks to verify a pacscript is correct -function lint_name() { +function lint_pkgname() { local ret=0 - if [[ -z $name ]]; then - fancy_message error "Package does not contain name" + if [[ -z $pkgname ]]; then + fancy_message error "Package does not contain 'pkgname'" return 1 fi - if [[ $name != "$PACKAGE" ]]; then + if [[ $pkgname != "$PACKAGE" ]]; then fancy_message error "Package name does not match file" - suggested_solution "Change '${UPurple}name${NC}' to '${UCyan}$PACKAGE${NC}'" "Change package name to '${UCyan}$name${NC}'" + suggested_solution "Change '${UPurple}pkgname${NC}' to '${UCyan}$PACKAGE${NC}'" "Change package name to '${UCyan}$pkgname${NC}'" ret=1 fi # https://www.debian.org/doc/debian-policy/ch-controlfields.html#source - if ((${#name} < 2)); then - fancy_message error "'name' must be at least two characters long" + if ((${#pkgname} < 2)); then + fancy_message error "'pkgname' must be at least two characters long" ret=1 fi - if [[ ${name:0:1} == [.\-+] ]]; then - fancy_message error "'name' must start with an alphanumeric character" + if [[ ${pkgname:0:1} == [.\-+] ]]; then + fancy_message error "'pkgname' must start with an alphanumeric character" ret=1 fi - if [[ $name =~ [[:upper:]] ]]; then - fancy_message error "'name' contains uppercase characters" + if [[ $pkgname =~ [[:upper:]] ]]; then + fancy_message error "'pkgname' contains uppercase characters" ret=1 fi - if [[ $name == *[^[:alnum:]+.-]* ]]; then - fancy_message error "'name' contains characters that are not lowercase, digits, minus, or periods" + if [[ $pkgname == *[^[:alnum:]+.-]* ]]; then + fancy_message error "'pkgname' contains characters that are not lowercase, digits, minus, or periods" ret=1 fi return "${ret}" @@ -57,7 +57,7 @@ function lint_name() { function lint_gives() { local ret=0 - if [[ -z $gives && $name == *-deb ]]; then + if [[ -z $gives && $pkgname == *-deb ]]; then fancy_message warn "Deb package does not contain gives" ret=1 fi @@ -130,8 +130,8 @@ function lint_source_deb_test() { # shellcheck disable=SC2206 local input_source=($@) for i in "${!input_source[@]}"; do - local url="${input_source[$i]}" - local file_name="${url##*/}" + local test_source_url="${input_source[$i]}" + local file_name="${test_source_url##*/}" if [[ ${file_name} == *"?"* ]]; then file_name="${file_name%%\?*}" fi @@ -174,8 +174,8 @@ function lint_source() { if [[ -n ${!source_arch} ]]; then test_source=() if [[ -n ${source[0]} ]]; then - # shellcheck disable=SC2206 - test_source+=(${source[*]}) + # shellcheck disable=SC2206 + test_source+=(${source[*]}) fi # shellcheck disable=SC2206 test_source+=(${!source_arch}) @@ -188,7 +188,7 @@ function lint_source() { fi done if [[ -n ${source[1]} ]]; then - lint_source_deb_test "${source[@]}" + lint_source_deb_test "${source[@]}" fi fi return "${ret}" @@ -302,6 +302,20 @@ function lint_optdepends() { return "${ret}" } +function lint_conflicts() { + local ret=0 conflict idx=0 + if [[ -n ${conflicts[*]} ]]; then + for conflict in "${conflicts[@]}"; do + if [[ -z ${conflict} ]]; then + fancy_message error "'conflicts' index '${idx}' cannot be empty" + ret=1 + fi + ((idx++)) + done + fi + return "${ret}" +} + function lint_breaks() { local ret=0 break idx=0 if [[ -n ${breaks[*]} ]]; then @@ -316,12 +330,12 @@ function lint_breaks() { return "${ret}" } -function lint_replace() { +function lint_replaces() { local ret=0 repl idx=0 - if [[ -n ${replace[*]} ]]; then - for repl in "${replace[@]}"; do + if [[ -n ${replaces[*]} ]]; then + for repl in "${replaces[@]}"; do if [[ -z ${repl} ]]; then - fancy_message error "'replace' index '${idx}' cannot be empty" + fancy_message error "'replaces' index '${idx}' cannot be empty" ret=1 fi ((idx++)) @@ -331,31 +345,73 @@ function lint_replace() { } function lint_hash() { - local ret=0 test_hash known_archs_hash=() - mapfile -t known_archs_hash < <(dpkg-architecture --list-known) - for i in "${!known_archs_hash[@]}"; do - # shellcheck disable=SC2004 - known_archs_hash[$i]=${known_archs_hash[$i]//-/_} + local ret=0 test_hash harch test_hashsum_type test_hashsum_style test_hash_arch test_hashsum_method test_hashsum_value + local known_archs_hash=("amd64" "arm64" "armel" "armhf" "i386" "mips64el" "ppc64el" "riscv64" "s390x") + local test_hashsums=("b2" "sha512" "sha384" "sha256" "sha224" "sha1" "md5") + for test_hashsum_type in "${test_hashsums[@]}"; do + test_hashsum_style="${test_hashsum_type}sums[*]" + if [[ -n ${!test_hashsum_style} ]]; then + if [[ -z ${test_hash[*]} ]]; then + # shellcheck disable=SC2206 + test_hash=(${!test_hashsum_style}) + test_hashsum_method="${test_hashsum_type}" + else + fancy_message error "Only one checksum method can be provided for hashes" + unset test_hash + ret=1 + break + fi + fi done - if [[ -n ${hash} ]]; then - # shellcheck disable=SC2206 - test_hash+=(${hash[*]}) - fi - for harch in "${known_archs_hash[@]}"; do - local hash_arch="hash_${harch}[*]" - if [[ -n ${!hash_arch} ]]; then - # shellcheck disable=SC2206 - test_hash+=(${!hash_arch}) + for test_hashsum_type in "${test_hashsums[@]}"; do + if ((ret == 1)); then + break fi + test_hashsum_style="${test_hashsum_type}sums[*]" + for harch in "${known_archs_hash[@]}"; do + test_hash_arch="${test_hashsum_type}sums_${harch}[*]" + if [[ -n ${!test_hash_arch} ]]; then + if [[ -z ${!test_hashsum_style} && -z ${test_hash[*]} ]]; then + if [[ -z ${test_hashsum_method} ]]; then + # shellcheck disable=SC2206 + test_hash=(${!test_hash_arch}) + test_hashsum_method="${test_hashsum_type}" + else + fancy_message error "Only one checksum method can be provided for hashes" + unset test_hash + ret=1 + break + fi + elif [[ -n ${test_hashsum_method} && ${test_hashsum_method} == "${test_hashsum_type}" ]]; then + # shellcheck disable=SC2206 + test_hash+=(${!test_hash_arch}) + else + fancy_message error "Only one checksum method can be provided for hashes" + unset test_hash + ret=1 + break + fi + fi + done done # shellcheck disable=SC2128 if [[ -n ${test_hash} ]]; then + case ${test_hashsum_method} in + "${test_hashsums[0]}" | "${test_hashsums[1]}") test_hashsum_value=128 ;; + "${test_hashsums[2]}") test_hashsum_value=96 ;; + "${test_hashsums[3]}") test_hashsum_value=64 ;; + "${test_hashsums[4]}") test_hashsum_value=56 ;; + "${test_hashsums[5]}") test_hashsum_value=40 ;; + "${test_hashsums[6]}") test_hashsum_value=32 ;; + esac for i in ${!test_hash[*]}; do if [[ ${test_hash[i]} == "SKIP" ]]; then ret=0 - elif ((${#test_hash[i]} != 64)); then + + elif ((${#test_hash[i]} != test_hashsum_value)) || [[ ! ${test_hash[i]} =~ ^[a-fA-F0-9]+$ ]]; then fancy_message error "'hash' is improperly formatted" ret=1 + break fi done fi @@ -498,7 +554,7 @@ function lint_priority() { } function checks() { - local ret=0 check linting_checks=(lint_name lint_gives lint_pkgrel lint_epoch lint_version lint_source lint_pkgdesc lint_maintainer lint_makedepends lint_depends lint_pacdeps lint_ppa lint_optdepends lint_breaks lint_replace lint_hash lint_patch lint_provides lint_incompatible lint_arch lint_mask lint_priority) + local ret=0 check linting_checks=(lint_pkgname lint_gives lint_pkgrel lint_epoch lint_version lint_source lint_pkgdesc lint_maintainer lint_makedepends lint_depends lint_pacdeps lint_ppa lint_optdepends lint_conflicts lint_breaks lint_replaces lint_hash lint_patch lint_provides lint_incompatible lint_arch lint_mask lint_priority) for check in "${linting_checks[@]}"; do "${check}" || ret=1 done diff --git a/misc/scripts/download-local.sh b/misc/scripts/download-local.sh old mode 100644 new mode 100755 index 390c39e37..6b5d2d53f --- a/misc/scripts/download-local.sh +++ b/misc/scripts/download-local.sh @@ -29,34 +29,34 @@ source "${STGDIR}/scripts/build-local.sh" || { } function parse_source_entry() { - unset url dest git_branch git_tag git_commit + unset source_url dest git_branch git_tag git_commit local entry="$1" - url="${entry#*::}" + source_url="${entry#*::}" dest="${entry%%::*}" if [[ $entry != *::* && $entry == *#*=* ]]; then - dest="${url%%#*}" + dest="${source_url%%#*}" dest="${dest##*/}" fi - case $url in + case $source_url in *#branch=*) - git_branch="${url##*#branch=}" - url="${url%%#branch=*}" + git_branch="${source_url##*#branch=}" + source_url="${source_url%%#branch=*}" ;; *#tag=*) - git_tag="${url##*#tag=}" - url="${url%%#tag=*}" + git_tag="${source_url##*#tag=}" + source_url="${source_url%%#tag=*}" ;; *#commit=*) - git_commit="${url##*#commit=}" - url="${url%%#commit=*}" + git_commit="${source_url##*#commit=}" + source_url="${source_url%%#commit=*}" ;; esac - url="${url%%#*}" + source_url="${source_url%%#*}" if [[ $entry == *::* ]]; then dest="${entry%%::*}" elif [[ $entry != *#*=* ]]; then - url="$entry" - dest="${url##*/}" + source_url="$entry" + dest="${source_url##*/}" fi if [[ ${dest} == *"?"* ]]; then dest="${dest%%\?*}" @@ -66,17 +66,17 @@ function parse_source_entry() { function calc_git_pkgver() { unset comp_git_pkgver local calc_commit - if [[ $url == git+* ]]; then - url="${url#git+}" + if [[ $source_url == git+* ]]; then + source_url="${source_url#git+}" fi if [[ -n ${git_branch} ]]; then - calc_commit="$(git ls-remote "${url}" "${git_branch}")" + calc_commit="$(git ls-remote "${source_url}" "${git_branch}")" elif [[ -n ${git_tag} ]]; then - calc_commit="$(git ls-remote "${url}" "${git_tag}")" + calc_commit="$(git ls-remote "${source_url}" "${git_tag}")" elif [[ -n ${git_commit} ]]; then calc_commit="${git_commit}" else - calc_commit="$(git ls-remote "${url}" HEAD)" + calc_commit="$(git ls-remote "${source_url}" HEAD)" fi comp_git_pkgver="${calc_commit:0:8}" } @@ -84,7 +84,7 @@ function calc_git_pkgver() { function genextr_declare() { unset ext_method ext_deps # shellcheck disable=SC2031,SC2034 - case "${url,,}" in + case "${source_url,,}" in *.zip) ext_method="unzip -qo" ext_deps=("unzip") @@ -155,15 +155,15 @@ function clean_fail_down() { } function hashcheck() { - local inputFile="${1}" inputHash="${2}" fileHash + local inputFile="${1}" inputHash="${2}" hashMethod="${3}sum" fileHash # Get hash of file - fileHash="$(sha256sum "${inputFile}")" + fileHash="$(${hashMethod} "${inputFile}")" fileHash="${fileHash%% *}" # Check if the input hash is the same as of the downloaded file. # Skip this test if the hash variable doesn't exist in the pacscript. if [[ -n ${inputHash} && ${inputHash} != "${fileHash}" ]]; then - fancy_message error "Hashes do not match" + fancy_message error "Hashes do not match (with method ${hashMethod})" fancy_message sub "Got: ${BRed}${fileHash}${NC}" fancy_message sub "Expected: ${BGreen}${inputHash}${NC}" error_log 16 "install $PACKAGE" @@ -178,23 +178,23 @@ function fail_down() { } function gather_down() { - if [[ -z ${pkgbase} ]]; then + if [[ -z ${srcdir} ]]; then if [[ -n $PACSTALL_PAYLOAD ]]; then - export pkgbase="/tmp/pacstall-pacdep" + export srcdir="/tmp/pacstall-pacdep" else - export pkgbase="${SRCDIR}/${PACKAGE}~${pkgver}" + export srcdir="${PACDIR}/${PACKAGE}~${pkgver}" fi fi - mkdir -p "${pkgbase}" - if ! [[ ${PWD} == "${pkgbase}" ]]; then - find "${PWD}" -mindepth 1 -maxdepth 1 ! -wholename "${pkgbase}" \ - ! -wholename "${SRCDIR}" \ + mkdir -p "${srcdir}" + if ! [[ ${PWD} == "${srcdir}" ]]; then + find "${PWD}" -mindepth 1 -maxdepth 1 ! -wholename "${srcdir}" \ + ! -wholename "${PACDIR}" \ ! -wholename "/tmp/pacstall-pacdep" \ ! -wholename "/tmp/pacstall-pacdeps-$PACKAGE" \ - -exec mv {} "${pkgbase}/" \; - cd "${pkgbase}" || { + -exec mv {} "${srcdir}/" \; + cd "${srcdir}" || { error_log 1 "gather-main $PACKAGE" - fancy_message error "Could not enter into the main directory ${YELLOW}${pkgbase}${NC}" + fancy_message error "Could not enter into the main directory ${YELLOW}${srcdir}${NC}" clean_fail_down } fi @@ -221,7 +221,7 @@ function git_down() { fi # git clone quietly, with no history, and if submodules are there, download with 10 jobs # shellcheck disable=SC2086,SC2031 - git clone --quiet --depth=1 --jobs=10 "${url}" "${dest}" ${gitopts} &> /dev/null || fail_down + git clone --quiet --depth=1 --jobs=10 "${source_url}" "${dest}" ${gitopts} &> /dev/null || fail_down # cd into the directory cd "./${dest}" 2> /dev/null || { error_log 1 "install $PACKAGE" @@ -248,20 +248,20 @@ function git_down() { cd .. gather_down else - export pkgbase="${PWD}" + export srcdir="${PWD}" fi } function net_down() { fancy_message info "Downloading ${BPurple}${dest}${NC}" # shellcheck disable=SC2031 - download "$url" "$dest" || fail_down + download "$source_url" "$dest" || fail_down } function hashcheck_down() { if [[ -n ${expectedHash} && ${expectedHash} != "SKIP" ]]; then fancy_message sub "Checking hash ${YELLOW}${expectedHash:0:8}${NC}[${YELLOW}...${NC}]" - hashcheck "${dest}" "${expectedHash}" || return 1 + hashcheck "${dest}" "${expectedHash}" "${hashsum_method}" || return 1 fi } @@ -287,7 +287,7 @@ function genextr_down() { fancy_message warn "Could not enter into the extracted archive" gather_down } - export pkgbase="${PWD}" + export srcdir="${PWD}" else gather_down fi @@ -295,7 +295,13 @@ function genextr_down() { function deb_down() { hashcheck_down - if type -t pre_install &> /dev/null; then + if is_package_installed "${pkgname}" && type -t pre_upgrade &> /dev/null; then + if ! pre_upgrade; then + error_log 5 "pre_upgrade hook" + fancy_message error "Could not run preinst hook successfully" + exit 1 + fi + elif type -t pre_install &> /dev/null; then if ! pre_install; then error_log 5 "pre_install hook" fancy_message error "Could not run preinst hook successfully" @@ -304,8 +310,8 @@ function deb_down() { fi if sudo apt install -y -f ./"${dest}" 2> /dev/null; then meta_log - if [[ -f /tmp/pacstall-pacdeps-"$name" ]]; then - sudo apt-mark auto "${gives:-$name}" 2> /dev/null + if [[ -f /tmp/pacstall-pacdeps-"$pkgname" ]]; then + sudo apt-mark auto "${gives:-$pkgname}" 2> /dev/null fi if type -t post_install &> /dev/null; then if ! post_install; then @@ -329,7 +335,7 @@ function deb_down() { else fancy_message error "Failed to install the package" error_log 14 "install $PACKAGE" - sudo apt purge "${gives:-$name}" -y > /dev/null + sudo apt purge "${gives:-$pkgname}" -y > /dev/null clean_fail_down fi } @@ -337,7 +343,7 @@ function deb_down() { function file_down() { fancy_message info "Copying local archive ${BPurple}${dest}${NC}" # shellcheck disable=SC2031 - cp -r "${url}" "${dest}" || fail_down + cp -r "${source_url}" "${dest}" || fail_down genextr_declare if [[ -n ${ext_method} ]]; then genextr_down @@ -347,25 +353,52 @@ function file_down() { fancy_message warn "Could not enter into the copied archive" gather_down } - export pkgbase="${PWD}" + export srcdir="${PWD}" else + hashcheck_down gather_down fi } -function append_arch_entry() { - local source_arch hash_arch +function append_archAndHash_entry() { + local source_arch hash_arch hashsum_type hashsum_style hashsums=("b2" "sha512" "sha384" "sha256" "sha224" "sha1" "md5") + unset hashsum_method # shellcheck disable=SC2153 source_arch="source_${CARCH}[*]" - hash_arch="hash_${CARCH}[*]" if [[ -n ${!source_arch} ]]; then - # shellcheck disable=SC2206 - source+=(${!source_arch}) - fi - if [[ -n ${!hash_arch} ]]; then - # shellcheck disable=SC2206 - hash+=(${!hash_arch}) + if [[ -z ${source[*]} ]]; then + # shellcheck disable=SC2206 + source=(${!source_arch}) + else + # shellcheck disable=SC2206 + source+=(${!source_arch}) + fi fi + for hashsum_type in "${hashsums[@]}"; do + hashsum_style="${hashsum_type}sums[*]" + if [[ -n ${!hashsum_style} ]]; then + # shellcheck disable=SC2206 + hash=(${!hashsum_style}) + export hashsum_method="${hashsum_type}" + break + fi + done + for hashsum_type in "${hashsums[@]}"; do + hashsum_style="${hashsum_type}sums[*]" + # shellcheck disable=SC2153 + hash_arch="${hashsum_type}sums_${CARCH}[*]" + if [[ -n ${!hash_arch} ]]; then + if [[ -z ${!hashsum_style} && -z ${hash[*]} ]]; then + # shellcheck disable=SC2206 + hash=(${!hash_arch}) + export hashsum_method="${hashsum_type}" + else + # shellcheck disable=SC2206 + hash+=(${!hash_arch}) + fi + break + fi + done } function calc_distro() { @@ -488,13 +521,11 @@ function install_builddepends() { done if ((${#not_installed_yet_builddepends[@]} != 0)); then - fancy_message info "${BLUE}$name${NC} requires ${CYAN}${not_installed_yet_builddepends[*]}${NC} to install" + fancy_message info "${BLUE}$pkgname${NC} requires ${CYAN}${not_installed_yet_builddepends[*]}${NC} to install" if ! sudo apt-get install -y "${not_installed_yet_builddepends[@]}"; then fancy_message error "Failed to install build dependencies" error_log 8 "install $PACKAGE" - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi fi fi @@ -516,16 +547,16 @@ function compare_remote_version() { local remotever remotever="$( unset pkgrel - source <(curl -s -- "$remoterepo/packages/$crv_input/$crv_input.pacscript") && \ - if [[ ${name} == *-git ]]; then - parse_source_entry "${source[0]}" - calc_git_pkgver - echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git${comp_git_pkgver}" - elif [[ ${name} == *-deb ]]; then - echo "${epoch+$epoch:}${pkgver}" - else - echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}" - fi + source <(curl -s -- "$remoterepo/packages/$crv_input/$crv_input.pacscript") \ + && if [[ ${pkgname} == *-git ]]; then + parse_source_entry "${source[0]}" + calc_git_pkgver + echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git${comp_git_pkgver}" + elif [[ ${pkgname} == *-deb ]]; then + echo "${epoch+$epoch:}${pkgver}" + else + echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}" + fi )" > /dev/null if [[ $crv_input == *"-git" ]]; then if [[ $(pacstall -Qi "$crv_input" version) != "$remotever" ]]; then diff --git a/misc/scripts/download.sh b/misc/scripts/download.sh index 10103c1f7..4fb21bf87 100755 --- a/misc/scripts/download.sh +++ b/misc/scripts/download.sh @@ -26,14 +26,14 @@ if check_url "${URL}"; then if [[ $type == "install" ]]; then - mkdir -p "$SRCDIR" || { - if ! [[ -w $SRCDIR ]]; then - suggested_solution "Run '${UCyan}sudo chown -R $PACSTALL_USER:$PACSTALL_USER $SRCDIR'${NC}" + mkdir -p "$PACDIR" || { + if ! [[ -w $PACDIR ]]; then + suggested_solution "Run '${UCyan}sudo chown -R $PACSTALL_USER:$PACSTALL_USER $PACDIR'${NC}" fi } - if ! cd "$SRCDIR"; then + if ! cd "$PACDIR"; then error_log 1 "install $PACKAGE" - fancy_message error "Could not enter ${SRCDIR}" + fancy_message error "Could not enter ${PACDIR}" exit 1 fi fi diff --git a/misc/scripts/install-local.sh b/misc/scripts/install-local.sh index 6ad3cecda..5d401f369 100755 --- a/misc/scripts/install-local.sh +++ b/misc/scripts/install-local.sh @@ -36,10 +36,10 @@ source "${STGDIR}/scripts/download-local.sh" || { function trap_ctrlc() { fancy_message warn "\nInterrupted, cleaning up" - if is_apt_package_installed "${name}"; then - sudo apt-get purge "${gives:-$name}" -y > /dev/null + if is_apt_package_installed "${pkgname}"; then + sudo apt-get purge "${gives:-$pkgname}" -y > /dev/null fi - sudo rm -f "/etc/apt/preferences.d/${name:-$PACKAGE}-pin" + sudo rm -f "/etc/apt/preferences.d/${pkgname:-$PACKAGE}-pin" cleanup exit 1 } @@ -92,13 +92,11 @@ export DISTRO="$(set_distro)" if ! source "${pacfile}"; then fancy_message error "Could not source pacscript" error_log 12 "install $PACKAGE" - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi # Running `-B` on a deb package doesn't make sense, so let's download instead -if ((PACSTALL_INSTALL == 0)) && [[ ${name} == *-deb ]]; then +if ((PACSTALL_INSTALL == 0)) && [[ ${pkgname} == *-deb ]]; then if ! download "${source[0]}"; then fancy_message error "Failed to download '${source[0]}'" return 1 @@ -109,11 +107,11 @@ fi masked_packages=() getMasks masked_packages if ((${#masked_packages[@]} != 0)); then - if array.contains masked_packages "${name:-${PACKAGE}}"; then - offending_pkg="$(getMasks_offending_pkg "${name:-${PACKAGE}}")" + if array.contains masked_packages "${pkgname:-${PACKAGE}}"; then + offending_pkg="$(getMasks_offending_pkg "${pkgname:-${PACKAGE}}")" # shellcheck disable=SC2181 if (($? == 0)); then - fancy_message error "The package ${BBlue}${offending_pkg}${NC} is masking ${BBlue}${name:-${PACKAGE}}${NC}. By installing the masked package, you may cause damage to your operating system" + fancy_message error "The package ${BBlue}${offending_pkg}${NC} is masking ${BBlue}${pkgname:-${PACKAGE}}${NC}. By installing the masked package, you may cause damage to your operating system" exit 1 else fancy_message error "Somehow, 'getMasks' found masked packages that match the package you want to install, but 'getMasks_offending_pkg' could not find it. Report this upstream" @@ -142,19 +140,17 @@ elif [[ -n ${incompatible[*]} ]]; then fi clean_builddir -sudo mkdir -p "$STOWDIR/$name/DEBIAN" -sudo chmod a+rx "$STOWDIR" "$STOWDIR/$name" "$STOWDIR/$name/DEBIAN" +sudo mkdir -p "$STOWDIR/$pkgname/DEBIAN" +sudo chmod a+rx "$STOWDIR" "$STOWDIR/$pkgname" "$STOWDIR/$pkgname/DEBIAN" # Run checks function if ! checks; then error_log 6 "install $PACKAGE" - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi # If priority exists and is required, and also that this package has not been installed before (first time) -if [[ -n ${priority} && ${priority} == 'essential' ]] && ! is_package_installed "${name}"; then +if [[ -n ${priority} && ${priority} == 'essential' ]] && ! is_package_installed "${pkgname}"; then ask "This package has 'priority=essential', meaning once this is installed, it should be assumed to be uninstallable. Do you want to continue?" Y if ((answer == 0)); then cleanup @@ -163,13 +159,13 @@ if [[ -n ${priority} && ${priority} == 'essential' ]] && ! is_package_installed fi # shellcheck disable=SC2031 -if [[ ${name} == *-git ]]; then +if [[ ${pkgname} == *-git ]]; then parse_source_entry "${source[0]}" calc_git_pkgver full_version="${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git${comp_git_pkgver}" git_pkgver="${comp_git_pkgver}" export git_pkgver -elif [[ ${name} == *-deb ]]; then +elif [[ ${pkgname} == *-deb ]]; then full_version="${epoch+$epoch:}${pkgver}" else full_version="${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}" @@ -201,8 +197,7 @@ if [[ -n $pacdeps ]]; then if ! pacstall "$cmd" "${i}${repo}"; then fancy_message error "Failed to install dependency" error_log 8 "install $PACKAGE" - cleanup - return 1 + clean_fail_down fi else fancy_message info "The pacstall dependency ${i} is already installed and at latest version" @@ -211,48 +206,63 @@ if [[ -n $pacdeps ]]; then elif fancy_message info "Installing $i" && ! pacstall "$cmd" "${i}${repo}"; then fancy_message error "Failed to install dependency" error_log 8 "install $PACKAGE" - cleanup - return 1 + clean_fail_down fi unset repo rm -f "/tmp/pacstall-pacdeps-$i" done fi -if ! is_package_installed "${name}"; then - if [[ -n $breaks ]]; then +if ! is_package_installed "${pkgname}"; then + if [[ -n ${conflicts[*]} ]]; then + for pkg in "${conflicts[@]}"; do + # Do we have an apt package installed (but not pacstall)? + if is_apt_package_installed "${pkg}" && ! is_package_installed "${pkg}"; then + # Check if anything in conflicts variable is installed already + # shellcheck disable=SC2031 + fancy_message error "${RED}$pkgname${NC} conflicts with $pkg, which is currently installed by apt" + suggested_solution "Remove the apt package by running '${UCyan}sudo apt purge $pkg${NC}'" + error_log 13 "install $PACKAGE" + clean_fail_down + fi + if [[ ${pkg} != "${pkgname}" ]] && is_package_installed "${pkg}"; then + # Same thing, but check if anything is installed with pacstall + # shellcheck disable=SC2031 + fancy_message error "${RED}$pkgname${NC} conflicts with $pkg, which is currently installed by pacstall" + suggested_solution "Remove the pacstall package by running '${UCyan}pacstall -R $pkg${NC}'" + error_log 13 "install $PACKAGE" + clean_fail_down + fi + done + fi + + if [[ -n ${breaks[*]} ]]; then for pkg in "${breaks[@]}"; do # Do we have an apt package installed (but not pacstall)? if is_apt_package_installed "${pkg}" && ! is_package_installed "${pkg}"; then # Check if anything in breaks variable is installed already - fancy_message error "${RED}$name${NC} breaks $pkg, which is currently installed by apt" + fancy_message error "${RED}$pkgname${NC} breaks $pkg, which is currently installed by apt" suggested_solution "Remove the apt package by running '${UCyan}sudo apt purge $pkg${NC}'" error_log 13 "install $PACKAGE" - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi - if [[ ${pkg} != "${name}" ]] && is_package_installed "${pkg}"; then + if [[ ${pkg} != "${pkgname}" ]] && is_package_installed "${pkg}"; then # Same thing, but check if anything is installed with pacstall - fancy_message error "${RED}$name${NC} breaks $pkg, which is currently installed by pacstall" + fancy_message error "${RED}$pkgname${NC} breaks $pkg, which is currently installed by pacstall" suggested_solution "Remove the pacstall package by running '${UCyan}pacstall -R $pkg${NC}'" error_log 13 "install $PACKAGE" - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi done fi - if [[ -n ${replace[*]} ]]; then + if [[ -n ${replaces[*]} ]]; then # Ask user if they want to replace the program - for pkg in "${replace[@]}"; do + for pkg in "${replaces[@]}"; do if is_apt_package_installed "${pkg}"; then ask "This script replaces ${pkg}. Do you want to proceed?" Y if ((answer == 0)); then - fancy_message info "Cleaning up" - cleanup - return 1 + clean_fail_down fi if [[ ${priority} == "essential" ]]; then sudo apt-get remove -y "${pkg}" --allow-remove-essential @@ -266,15 +276,15 @@ fi unset dest_list declare -A dest_list -append_arch_entry +append_archAndHash_entry for i in "${!source[@]}"; do parse_source_entry "${source[$i]}" dest="${dest%.git}" - if [[ -n ${dest_list[$dest]} && ${dest_list[$dest]} != "${url}" ]]; then + if [[ -n ${dest_list[$dest]} && ${dest_list[$dest]} != "${source_url}" ]]; then fancy_message error "${dest} is associated with multiple source entries" clean_fail_down else - dest_list["${dest}"]="${url}" + dest_list["${dest}"]="${source_url}" fi genextr_declare unset ext_dep make_dep in_make_deps @@ -304,15 +314,15 @@ if [[ -f /tmp/pacstall-pacdeps-"$PACKAGE" ]]; then exit 1 fi else - mkdir -p "$SRCDIR" - if ! cd "$SRCDIR" 2> /dev/null; then + mkdir -p "$PACDIR" + if ! cd "$PACDIR" 2> /dev/null; then error_log 1 "install $PACKAGE" - fancy_message error "Could not enter ${SRCDIR}" + fancy_message error "Could not enter ${PACDIR}" exit 1 fi fi -mkdir -p "${SRCDIR}" +mkdir -p "${PACDIR}" for i in "${!source[@]}"; do parse_source_entry "${source[$i]}" @@ -320,15 +330,23 @@ for i in "${!source[@]}"; do if [[ -n $PACSTALL_PAYLOAD && ! -f "/tmp/pacstall-pacdeps-$PACKAGE" ]]; then dest="${PACSTALL_PAYLOAD##*/}" fi - case "${url,,}" in + if [[ $source_url != *://* ]]; then + if [[ -z ${REPO} ]]; then + # shellcheck disable=SC2086 + REPO="$(< ${STGDIR}/repo/pacstallrepo)" + fi + # shellcheck disable=SC2031 + source_url="${REPO}/packages/${pkgname}/${source_url}" + fi + case "${source_url,,}" in *file://*) - url="${url#file://}" - url="${url#git+}" + source_url="${source_url#file://}" + source_url="${source_url#git+}" file_down ;; *.git | git+*) - if [[ $url == git+* ]]; then - url="${url#git+}" + if [[ $source_url == git+* ]]; then + source_url="${source_url#git+}" fi git_down ;; @@ -344,18 +362,17 @@ for i in "${!source[@]}"; do *) net_down hashcheck_down - if [[ ${source[i]} != "${source[0]}" ]]; then - gather_down - fi + gather_down ;; esac - unset expectedHash dest url git_branch git_tag git_commit ext_deps ext_method + unset expectedHash dest source_url git_branch git_tag git_commit ext_deps ext_method done +unset hashsum_method -export srcdir="$PWD" +export pacdir="$PWD" sudo chown -R "$PACSTALL_USER":"$PACSTALL_USER" . 2> /dev/null -export pkgdir="$STOWDIR/$name" +export pkgdir="$STOWDIR/$pkgname" export -f ask fancy_message select_options # Trap so that we can clean up (hopefully without messing up anything) @@ -372,10 +389,8 @@ function fail_out_functions() { error_log 5 "$func $PACKAGE" echo -ne "\t" fancy_message error "Could not $func $PACKAGE properly" - sudo dpkg -r "${gives:-$name}" > /dev/null - fancy_message info "Cleaning up" - cleanup - exit 1 + sudo dpkg -r "${gives:-$pkgname}" > /dev/null + clean_fail_down } function run_function() { @@ -385,7 +400,7 @@ function run_function() { sudo mkdir -p "${LOGDIR}" fi # NOTE: https://stackoverflow.com/a/29163890 (shorthand for 2>&1 |) - $func |& sudo tee "${LOGDIR}/$(printf '%(%Y-%m-%d_%T)T')-$name-$func.log" && return "${PIPESTATUS[0]}" + $func |& sudo tee "${LOGDIR}/$(printf '%(%Y-%m-%d_%T)T')-$pkgname-$func.log" && return "${PIPESTATUS[0]}" } function safe_run() { @@ -435,10 +450,8 @@ sudo mkdir -p "/var/cache/pacstall/$PACKAGE/${full_version}" if ! cd "$DIR" 2> /dev/null; then error_log 1 "install $PACKAGE" fancy_message error "Could not enter into ${DIR}" - sudo dpkg -r "${gives:-$name}" > /dev/null - fancy_message info "Cleaning up" - cleanup - exit 1 + sudo dpkg -r "${gives:-$pkgname}" > /dev/null + clean_fail_down fi sudo cp -r "${pacfile}" "/var/cache/pacstall/$PACKAGE/${full_version}" diff --git a/misc/scripts/search.sh b/misc/scripts/search.sh index 374aeb771..5830a91d5 100755 --- a/misc/scripts/search.sh +++ b/misc/scripts/search.sh @@ -201,7 +201,7 @@ elif [[ -n $UPGRADE ]]; then REPOS=() # Return list of repos with the package for IDX in $IDXSEARCH; do - mapfile -t REPOS <<< "${URLLIST[$IDX]}" + mapfile -t -O"${#REPOS[@]}" REPOS <<< "${URLLIST[$IDX]}" done export REPOS return 0 diff --git a/misc/scripts/upgrade.sh b/misc/scripts/upgrade.sh index 9545a0aa3..ff93c4b94 100755 --- a/misc/scripts/upgrade.sh +++ b/misc/scripts/upgrade.sh @@ -28,6 +28,12 @@ source "${STGDIR}/scripts/dep-tree.sh" || { return 1 } +# shellcheck source=./misc/scripts/download-local.sh +source "${STGDIR}/scripts/download-local.sh" || { + fancy_message error "Could not find download-local.sh" + return 1 +} + function ver_compare() { local first second first="${1#"${1/[0-9]*/}"}" @@ -36,7 +42,27 @@ function ver_compare() { return $(dpkg --compare-versions "$first" lt "$second") } +function calc_repo_ver() { + local compare_repo="$1" compare_package="$2" + unset comp_repo_ver + # shellcheck disable=SC2031 + source <(curl -s -- "$compare_repo"/packages/"$compare_package"/"$compare_package".pacscript) \ + && if [[ ${pkgname} == *-deb ]]; then + comp_repo_ver="${epoch+$epoch:}${pkgver}" + elif [[ ${pkgname} == *-git ]]; then + parse_source_entry "${source[0]}" + calc_git_pkgver + comp_repo_ver="${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git${comp_git_pkgver}" + else + comp_repo_ver="${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}" + fi +} + export UPGRADE="yes" +# shellcheck disable=SC2155 +export CARCH="$(dpkg --print-architecture)" +# shellcheck disable=SC2155 +export DISTRO="$(set_distro)" fancy_message info "Checking for updates" @@ -85,7 +111,9 @@ N="$(nproc)" IDXMATCH=$(printf "%s\n" "${REPOS[@]}" | awk "\$1 ~ /^${remoterepo//\//\\/}$/ {print NR-1}") if [[ -n $IDXMATCH ]]; then - remotever=$(source <(curl -s -- "$remoterepo/packages/$i/$i.pacscript") && if [[ ${name} == *-deb ]]; then echo "${epoch+$epoch:}${pkgver}"; else type pkgver &> /dev/null && echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git$(pkgver)" || echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}"; fi) > /dev/null + calc_repo_ver "$remoterepo" "$i" \ + && remotever="${comp_repo_ver}" + unset comp_repo_ver remoteurl="${REPOS[$IDXMATCH]}" else fancy_message warn "Package ${GREEN}${i}${CYAN} is not on ${CYAN}$(parseRepo "${remoterepo}")${NC} anymore" @@ -98,7 +126,9 @@ N="$(nproc)" if ((IDX == IDXMATCH)); then continue else - ver=$(source <(curl -s -- "${REPOS[$IDX]}"/packages/"$i"/"$i".pacscript) && if [[ ${name} == *-deb ]]; then echo "${epoch+$epoch:}${pkgver}"; else type pkgver &> /dev/null && echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}~git$(pkgver)" || echo "${epoch+$epoch:}${pkgver}-pacstall${pkgrel:-1}"; fi) > /dev/null + calc_repo_ver "${REPOS[$IDX]}" "$i" \ + && ver="${comp_repo_ver}" + unset comp_repo_ver if ! ver_compare "$alterver" "$ver"; then alterver="$ver" alterurl="$REPO" @@ -153,10 +183,10 @@ ${BOLD}$(cat "${up_print}")${NC}\n" upgrade=("${update_order[@]}") export local='no' - mkdir -p "$SRCDIR" - if ! cd "$SRCDIR" 2> /dev/null; then + mkdir -p "$PACDIR" + if ! cd "$PACDIR" 2> /dev/null; then error_log 1 "upgrade" - fancy_message error "Could not enter ${SRCDIR}" + fancy_message error "Could not enter ${PACDIR}" exit 1 fi for to_upgrade in "${upgrade[@]}"; do diff --git a/pacstall b/pacstall index fed3ada9f..215556bd4 100755 --- a/pacstall +++ b/pacstall @@ -28,7 +28,7 @@ export METADIR="/var/lib/pacstall/metadata" export LOGDIR="/var/log/pacstall/error_log" printf -v LOGFILE "${LOGDIR}/%(%F_%T)T.log" export LOGFILE -export SRCDIR="/tmp/pacstall" +export PACDIR="/tmp/pacstall" export STGDIR="/usr/share/pacstall" export STOWDIR="/usr/src/pacstall" @@ -468,7 +468,7 @@ function getMasks() { } function getMasks_offending_pkg() { - local pkgname="${1}" + local the_name="${1}" mapfile -t pkgs < <(pacstall -L) if ((${#pkgs[@]} == 0)); then return 0 @@ -476,7 +476,7 @@ function getMasks_offending_pkg() { for pkg in "${pkgs[@]}"; do source "${METADIR}/${pkg}" if [[ -n ${_mask[*]} ]]; then - if array.contains _mask "${pkgname}"; then + if array.contains _mask "${the_name}"; then echo "${pkg}" return 0 fi @@ -568,8 +568,8 @@ if [[ -n $PACSTALL_PAYLOAD && ! -f "/tmp/pacstall-pacdeps-$PACKAGE" ]]; then fancy_message error "Payload not found" exit 1 fi - mkdir -p "${SRCDIR:?}" - cp "$PACSTALL_PAYLOAD" "${SRCDIR:?}" + mkdir -p "${PACDIR:?}" + cp "$PACSTALL_PAYLOAD" "${PACDIR:?}" fi while [[ $1 != "--" ]]; do @@ -644,7 +644,7 @@ Helpful links: function trap_ctrlc() { fancy_message warn "The installation of ${PACKAGE:-package} was interrupted, removing files" - rm -rf "${SRCDIR:?}"/* # :? makes bash error out in case SRCDIR is empty, saving us from yoinking /* directory by mistake + rm -rf "${PACDIR:?}"/* # :? makes bash error out in case PACDIR is empty, saving us from yoinking /* directory by mistake exit 2 } # Begin trapping @@ -722,7 +722,7 @@ Helpful links: if ! source "$STGDIR/scripts/install-local.sh"; then fancy_message error "Failed to install ${GREEN}${PACKAGE}${NC}" if ! [[ -f "/tmp/pacstall-pacdeps-$PACKAGE" ]]; then - sudo rm -rf "${SRCDIR:?}" + sudo rm -rf "${PACDIR:?}" fi exit 1 fi