From 3910ef98a7639c3ebf139135f7bc8384849b2d80 Mon Sep 17 00:00:00 2001 From: Martin Dvorak Date: Sun, 12 Nov 2023 13:05:04 +0100 Subject: [PATCH] Adding scripts to build Debian PPA(s) for all Debian releases. --- build/Makefile | 56 +++++- build/debian/debian-ppa-aptly-build.sh | 229 +++++++++++++++++++++++++ build/debian/index-all-ppas.html | 24 +++ build/debian/index-ppa.html | 34 ++++ 4 files changed, 340 insertions(+), 3 deletions(-) create mode 100755 build/debian/debian-ppa-aptly-build.sh create mode 100644 build/debian/index-all-ppas.html create mode 100644 build/debian/index-ppa.html diff --git a/build/Makefile b/build/Makefile index 11ef102f..ea7d355c 100644 --- a/build/Makefile +++ b/build/Makefile @@ -45,7 +45,7 @@ help: @echo "dist-deb build Debian distribution" @echo "dist-rpm build .rpm package on Fedora" @echo "dist-dmg build macOS Disk iMaGe .dmg package" - @echo "dist-debian-ppa add .deb to aptly PPA" + @echo "dist-debian-ppa create PPA for all Debian releases" @echo "statistic show source code statistic" @echo "doc-to-wiki mindforger-documentation to mindforger.wiki" @echo "api-reference generate Doxygen documentation" @@ -130,9 +130,59 @@ dist-dmg: @echo "Building .dmg package..." cd macos && ./mindforger-build.sh && ./dmg-package-build.sh +# +# Debian +# +# MindForger PPA: https://www.mindforger.com/debian is managed by aptly +# +# - information about MindForger's Debian PPAs can be found in +# https://www.mindforger.com/debian/index.html +# +# - aptly CANNOT be used to build one PPA for all Debian releases +# therefore every release has it's own PPA +# +# - the structure looks like this (from deprecated debian/ to new debian-ppa/): +# +# https://www.mindforger.com/debian-ppa/ +# stretch/ +# dists/ ... export from ~/.aptly/public +# pool/ +# index.html ... created by me w/ how to set it up +# ... +# trixie/ +# dists/ ... export from ~/.aptly/public +# pool/ +# index.html ... created by me w/ how to set it up +# +# - source Debian packages for every version (which are used by aptly) +# are stored in +# +# ~/p/mindforger/debian/aptly/ +# hstr/ +# 9-stretch/ +# ... +# 13-trixie/ +# mindforger/ +# 9-stretch/ +# mindforger-*.*.*.deb +# ... +# 13-trixie/ +# mindforger-*.*.*.deb +# +# - Makefile targets below are used to manage Debian PPAs and generate them +# + +# future repos : trixie-main +# CURRENT repos : bookworm-main, bullseye-main, buster-main, stretch-main +# obsolete repos: jessie-main + .PHONY: dist-debian-ppa -dist-debian-ppa: - cd debian && ./debian-aptly-add-deb.sh +dist-debian-aptly-create-ppa: + cd ./build/debian && ./debian-ppa-aptly-build.sh + +# +# ^ Debian +# .PHONY: dist-all-clean dist-all-clean: diff --git a/build/debian/debian-ppa-aptly-build.sh b/build/debian/debian-ppa-aptly-build.sh new file mode 100755 index 00000000..a367e7cf --- /dev/null +++ b/build/debian/debian-ppa-aptly-build.sh @@ -0,0 +1,229 @@ +#!/bin/bash +# +# MindForger knowledge management tool +# +# Copyright (C) 2016-2023 Martin Dvorak +# +# 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 2 +# 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 . + + + +# +# This script builds MindForger/HSTR Debian PPA for a particular Debian release. +# - it adds all .deb pacakges in given directory to aptly repository. +# +# Usage: +# +# MF_DEBIAN_DISTRO_DIR=... MF_DEBIAN_RELEASE=... ./debian-aptly-add-deb.sh +# +# Example: +# +# MF_DEBIAN_DEB_DIR=~/p/mindforger/debian/aptly/mindforger/12-bookworm \ +# MF_DEBIAN_RELEASE=bookworm \ +# ./debian-release-aptly-build.sh +# +# aptly abstractions hierarchy: +# +# - repository +# - packages +# ^ snapshots +# ^ publish +# +# See 'MindForger Release Guide#Debian and my PPA' notebook for detailed steps description. + +export MF_IN_DEB_PACKAGES_DIR="/home/dvorka/p/mindforger/debian/aptly" +# ^ must have the following structure: +#. +#├── hstr +#│   └── 09-stretch +#│   ├── hstr_1.27.0-1_amd64.deb +#│   ├── hstr_2.0.0-1_amd64.deb +#│   └── hstr_2.4.0-1_amd64.deb +#└── mindforger +# ├── 09-stretch +# │   ├── mindforger_1.42.0-1_amd64.deb +# │   ├── ... +# │   └── mindforger_1.53.0-1_amd64.deb +# ├── ... +# └── 13-trixie +#    └── mindforger_1.54.0-1_amd64.deb +# +export MF_OUT_PPA_ALL_DEBIAN_RELEASES_DIR="/home/dvorka/p/mindforger/debian/debian-ppa.mindforger.com" +# ^ PPAs for all releases side-by-side + + + +# Add ONE .deb package to aptly repository: +# +# Parameters: +# $1 - MF version e.g. 1.55.0 +# $2 - Debian release e.g. stretch +# +function add_deb { + NEW_MF_VERSION=${1} + NEW_DEBIAN_RELEASE=${2} + + export NEW_MF_RELEASE_NAME="mindforger_${NEW_MF_VERSION}" + export NEW_DEB_NAME="${NEW_MF_RELEASE_NAME}-1_amd64.deb" + + export MY_APTLY_PATH="/home/dvorka/.aptly" + export MY_APTLY_UPLOAD_PATH="${MY_APTLY_PATH}/public" + export MY_APTLY_VERSION="$(aptly version)" + # PPA REPOSITORY name (aptly can manage multiple - this identifier) + export MY_APTLY_REPO_NAME="${NEW_DEBIAN_RELEASE}-main" + # PPA repository SNAPSHOT is entity which is published + #export MY_APTLY_SNAPSHOT_NAME="$(aptly snapshot list --raw)" + export MY_APTLY_SNAPSHOT_NAME="${NEW_DEBIAN_RELEASE}-snapshot" + # PUBLISH of repository snapshot is stored to ~/.aptly/public so that it can be uploaded + #export MY_APTLY_PUBLISH="$(aptly publish list)" + #export MY_APTLY_PUBLISH_NAME="$(aptly publish list --raw | while read A B; do echo ${B}; done)" + export MY_APTLY_PUBLISH_NAME="${NEW_DEBIAN_RELEASE}-publish" + + echo + echo "= Local aptly repository overview: ====================================" + # echo " ${MY_APTLY_VERSION}" + echo " aptly repository path: ${MY_APTLY_PATH}" + echo " aptly config path : ${MY_APTLY_PATH}.config" + echo "New snapshot:" + echo " Debian release : ${NEW_DEBIAN_RELEASE}" + echo " MF release : ${NEW_MF_VERSION}" + echo " .deb file : ${NEW_DEB_NAME}" + echo " publish name : ${MY_APTLY_PUBLISH_NAME}" + echo " snapshot name : ${MY_APTLY_SNAPSHOT_NAME}" + echo " repository name : ${MY_APTLY_REPO_NAME}" + echo "# BEFORE repos ========================================================" + aptly repo list + echo "# BEFORE repo =========================================================" + aptly repo create "${MY_APTLY_REPO_NAME}" + aptly repo show -with-packages "${MY_APTLY_REPO_NAME}" + echo "# BEFORE snapshots ====================================================" + aptly snapshot list + echo "# BEFORE snapshot =====================================================" + aptly snapshot show -with-packages "${MY_APTLY_SNAPSHOT_NAME}" + echo "# BEFORE publishes ====================================================" + aptly publish list + echo "# BEFORE publish ======================================================" + aptly publish show "${MY_APTLY_PUBLISH_NAME}" + echo "> RUN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + echo + + # checks + if [[ ! -f "${NEW_DEB_NAME}" ]] + then + echo "Error: File with package to be released not found: ${NEW_DEB_NAME}" + exit 1 + fi + + #echo "STEP: .aptly/ backup:" + #export timestamp=`date +%Y-%m-%d--%H-%M-%S` + #tar zcf ~/p/mindforger/debian/aptly/backup-aptly-${timestamp}.tgz ~/.aptly + #echo "DONE: backup" + + echo "STEP: drop publish > snapshot > repo" + aptly publish drop ${NEW_DEBIAN_RELEASE} + aptly snapshot drop ${MY_APTLY_SNAPSHOT_NAME} + + echo "STEP: add .deb to repo > snapshot > publish" + # aptly repo edit -distribution="${NEW_DEBIAN_RELEASE}" "${MY_APTLY_REPO_NAME}" + aptly repo add ${MY_APTLY_REPO_NAME} ${NEW_DEB_NAME} + aptly snapshot create ${MY_APTLY_SNAPSHOT_NAME} from repo ${MY_APTLY_REPO_NAME} + aptly publish snapshot -distribution=${NEW_DEBIAN_RELEASE} ${MY_APTLY_SNAPSHOT_NAME} + echo "DONE: add .deb" + + # upload + #echo -e "\n${MY_APTLY_UPLOAD_PATH} can be UPLOADED to www.mindforger.com/debian:" + #tree ${MY_APTLY_UPLOAD_PATH} + + # copy it to ALL Debian releases dir + export MY_PPA_DISTR_DIR="${MF_OUT_PPA_ALL_DEBIAN_RELEASES_DIR}/${NEW_DEBIAN_RELEASE}" + rm -rvf ${MY_PPA_DISTR_DIR} + mkdir -pv ${MY_PPA_DISTR_DIR} + cp -vrf ${MY_APTLY_UPLOAD_PATH}/* ${MY_PPA_DISTR_DIR} + # ensure index.html for the Debian release + echo "STEP: create index.html for the Debian release" + cat ./index-ppa.html | sed -e "s/DISTRO/${NEW_DEBIAN_RELEASE}/g" > "${MY_PPA_DISTR_DIR}/index.html" + + tree ${MF_OUT_PPA_ALL_DEBIAN_RELEASES_DIR} +} + +function add_debian_release { + export MF_DEBIAN_RELEASE_DIR=${1} + export MF_DEBIAN_RELEASE=${2} + + find ${MF_DEBIAN_RELEASE_DIR} -name "*.deb" | while read P + do + export MF_DEB_FILE_NAME=$(basename ${P}) + + echo ${MF_DEB_FILE_NAME} | tr "_" " " | while read A B C + do + echo $B | tr "-" " " | while read X Y + do + echo $X + done + done | while read MF_RELEASE_VERSION + do + echo "Debinan release: ${MF_DEBIAN_RELEASE}" + echo "Input file : ${P}" + echo ".deb file name : ${MF_DEB_FILE_NAME}" + echo "MF version : ${MF_RELEASE_VERSION}" + + # prepare .deb file to the current directory + rm -f ${MF_DEB_FILE_NAME} + cp -f ${P} . + + # add .deb to repo + add_deb ${MF_RELEASE_VERSION} ${MF_DEBIAN_RELEASE} + + # cleanup + rm -f ${MF_DEB_FILE_NAME} + done + done +} + +# +# MAIN +# + +# purge debian-ppa.mindforger.com +rm -rvf "${MF_OUT_PPA_ALL_DEBIAN_RELEASES_DIR}" + +# FOR every Debian release in the input directory +find "${MF_IN_DEB_PACKAGES_DIR}/mindforger" -maxdepth 1 -mindepth 1 -type d | while read MF_DEBIAN_RELEASE_DIR +do + export MF_DEBIAN_RELEASE=$(basename ${MF_DEBIAN_RELEASE_DIR} | tr "-" " " | while read A B; do echo ${B}; done) + echo "Debinan release: ${MF_DEBIAN_RELEASE}" + echo "Input dir : ${MF_DEBIAN_RELEASE_DIR}" + + export MY_APTLY_REPO_NAME="${MF_DEBIAN_RELEASE}-main" + export MY_APTLY_SNAPSHOT_NAME="${MF_DEBIAN_RELEASE}-snapshot" + + echo "STEP: DROP it all: snapshots, publishes, repos" + aptly publish drop ${MF_DEBIAN_RELEASE} + aptly snapshot drop ${MY_APTLY_SNAPSHOT_NAME} + aptly repo drop ${MY_APTLY_REPO_NAME} + aptly repo drop "bookworm-main" + aptly repo drop "jessie-main" + + add_debian_release ${MF_DEBIAN_RELEASE_DIR} ${MF_DEBIAN_RELEASE} + + # purge aptly and start over + aptly publish drop ${MF_DEBIAN_RELEASE} + aptly snapshot drop ${MY_APTLY_SNAPSHOT_NAME} + aptly repo drop ${MY_APTLY_REPO_NAME} +done + +# HTML w/ links to for all Debian releases +cp -vf ./index-all-ppas.html "${MF_OUT_PPA_ALL_DEBIAN_RELEASES_DIR}/index.html" + +# eof diff --git a/build/debian/index-all-ppas.html b/build/debian/index-all-ppas.html new file mode 100644 index 00000000..b7131e42 --- /dev/null +++ b/build/debian/index-all-ppas.html @@ -0,0 +1,24 @@ + + + + MindForger Debian PPA repositories + + +

MindForger provides Debian PPA repositories

+ +

MindForger provides Debian PPA repositories for the following + Debian releases: + +

+ + There is not one repository for all Debian releases, + but per-Debian release repository. +

+ + + diff --git a/build/debian/index-ppa.html b/build/debian/index-ppa.html new file mode 100644 index 00000000..153796eb --- /dev/null +++ b/build/debian/index-ppa.html @@ -0,0 +1,34 @@ + + + + MindForger Debian "DISTRO" PPA repository + + +

MindForger Debian "DISTRO" PPA repository

+ +

This is Personal Package Archive (PPA) + for MindForger. +

+

To install programs from this PPA add new repository + to /etc/apt/sources.list as follows:

+

+ +
+      echo "deb http://www.mindforger.com/debian-ppa/DISTRO DISTRO main" | sudo tee /etc/apt/sources.list.d/mindforger.list      
+    
+ +

... and import key that is used to sign the release:

+ +
+      $ wget -qO - http://www.mindforger.com/gpgpubkey.txt | sudo apt-key add -
+    
+ +

After that you can install MindForger as any other software package:

+ +
+      $ sudo apt update
+      $ sudo apt install mindforger
+    
+ + +