diff --git a/build.sh b/build.sh index 2a4df5e..cb32ddd 100755 --- a/build.sh +++ b/build.sh @@ -45,49 +45,23 @@ echo "App packaged successfully." cd .. echo "Package(s) deploy..." +DIST_DIR="project/dist" INCOMING_DIR="repo/incoming" - -mkdir -p ${INCOMING_DIR} - READY_SUFFIX=".ready" -DIST_DIR="project/dist" -for ENTRY in "${DIST_DIR}"/*.deb; do - # If is not a file skip - if [ -f "${ENTRY}" ]; then - FILENAME=$(basename "${ENTRY}") - #scp "${ENTRY}" reposerver:"${INCOMING_DIR}/${FILENAME}" - #scp "${ENTRY}" reposerver:"${INCOMING_DIR}/${FILENAME}${READY_SUFFIX}" - cp "${ENTRY}" "${INCOMING_DIR}/${FILENAME}" - cp "${ENTRY}" "${INCOMING_DIR}/${FILENAME}${READY_SUFFIX}" - fi -done +mkdir -p "${INCOMING_DIR}" +./deploy.sh "${DIST_DIR}" "${INCOMING_DIR}" "${READY_SUFFIX}" echo "Moving package(s) to the repo..." -MAIN_DIR="repo/main" mkdir -p "${MAIN_DIR}" - -for ENTRY in "${INCOMING_DIR}"/*"${READY_SUFFIX}"; do - # If is not a file skip - if [ -f "${ENTRY}" ]; then - FILENAME_DEB=$(basename --suffix="${READY_SUFFIX}" "${ENTRY}") - BASEDIRPATH=$(dirname "${ENTRY}") - mv "${BASEDIRPATH}/${FILENAME_DEB}" "${MAIN_DIR}/${FILENAME_DEB}" - rm "${ENTRY}" - fi -done +./movedebs.sh "${MAIN_DIR}" "${INCOMING_DIR}" "${READY_SUFFIX}" echo "Installing repository build dependencies (apt)..." apt-get -qq -y --no-install-recommends install apt-utils > /dev/null -TEMP_DIR="$(mktemp -d)" - echo "Updating the repo..." -initial_position="$(pwd)" -cd repo -apt-ftparchive packages . > "${TEMP_DIR}/Packages" -cd "${initial_position}" -gzip -k -f "${TEMP_DIR}/Packages" --to-stdout > "${TEMP_DIR}/Packages.gz" -apt-ftparchive release "${TEMP_DIR}" > "${TEMP_DIR}/Release" +REPO_PATH="repo" +TEMP_DIR="$(mktemp -d)" +./repo-update.sh "${REPO_PATH}" "${TEMP_DIR}" apt-get -qq -y --no-install-recommends install gpg gpg-agent @@ -96,50 +70,9 @@ mkdir -p keys chmod 600 keys export GNUPGHOME="${PWD}/keys" -if [ ! -f "keys/pubring.kbx" ]; then - echo "The file 'pubring.kbx' file has not been found. Generating automatically a new one with a new set of keys..." - KEY_NAME="Joe Tester" - KEY_PASSPHRASE="over-the-lazy-dog" - cat >foo_keys < keys/passphrase -fi - -if [ -z ${GPG_SUBKEY_ID+x} ]; then - echo "A GPG key id has not been defined. Automatically selecting a fingerprint..." - # List key and its subkey with their respective fingerprints | filter fingerprints of both keys | pick fingerprint of the second row - # (the subkey seems to be listed always after its respective subkey) - GPG_SUBKEY_ID="$(gpg --list-secret-key --with-subkey-fingerprint --with-colons | awk -F: '$1 == "fpr" {print $10;}' | sed -n '2 p')" -fi - -if [ ! -f repo/key.pub.asc ];then - echo "Public key not published. Generating and publishing it..." - gpg --armor --export "${GPG_SUBKEY_ID}" > repo/key.pub.asc -fi - -echo "Signing the repo..." -gpg --passphrase-file keys/passphrase --pinentry-mode loopback --default-key "${GPG_SUBKEY_ID}" -abs -o - "${TEMP_DIR}/Release" > "${TEMP_DIR}/Release.gpg" -gpg --passphrase-file keys/passphrase --pinentry-mode loopback --default-key "${GPG_SUBKEY_ID}" --clearsign -o - "${TEMP_DIR}/Release" > "${TEMP_DIR}/InRelease" -echo "Done." +./repo-sign.sh echo "Committing changes..." -mv "${TEMP_DIR}"/* repo/ +mv "${TEMP_DIR}"/* "${REPO_PATH}"/ #echo "deb file:/repo /" > /etc/apt/sources.list.d/custom-repo.list diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..ab1a180 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + echo "No arguments provided. Aborting..." + exit 1 +fi + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "usage: ./deploy.sh [-h] [DIST_DIR INCOMING_DIR READY_SUFFIX] + +Deploys packages for you. + +Possible values for the arguments: + +DIST_DIR path of the binary package(s) to deploy +INCOMING_DIR remote path of the 'incoming' directory +READY_SUFFIX suffix used to flag a complete transfer of a file + +Dependencies: openssh-client +" + exit 0 +fi + +if [ $# -lt 4 ]; then + echo "Mandatory arguments: 'DIST_DIR', 'INCOMING_DIR', 'INCOMING_DIR'. Aborting..." + exit 1 +fi + +DIST_DIR="${1}" +INCOMING_DIR="${2}" +READY_SUFFIX="${3}" + +for ENTRY in "${DIST_DIR}"/*.deb; do + # If is not a file skip + if [ -f "${ENTRY}" ]; then + FILENAME=$(basename "${ENTRY}") + #scp "${ENTRY}" reposerver:"${INCOMING_DIR}/${FILENAME}" + #scp "${ENTRY}" reposerver:"${INCOMING_DIR}/${FILENAME}${READY_SUFFIX}" + cp "${ENTRY}" "${INCOMING_DIR}/${FILENAME}" + cp "${ENTRY}" "${INCOMING_DIR}/${FILENAME}${READY_SUFFIX}" + fi +done diff --git a/movedebs.sh b/movedebs.sh new file mode 100755 index 0000000..050633f --- /dev/null +++ b/movedebs.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + echo "No arguments provided. Aborting..." + exit 1 +fi + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "usage: ./movedebs.sh [-h] [MAIN_DIR INCOMING_DIR READY_SUFFIX] + +Deploys packages for you. + +Possible values for the arguments: + +MAIN_DIR path of the directory inside the repository where the packages will be storaged +INCOMING_DIR local path of the 'incoming' directory +READY_SUFFIX suffix used to flag a complete transfer of a file + +Dependencies: - +" + exit 0 +fi + +if [ $# -lt 4 ]; then + echo "Mandatory arguments: 'MAIN_DIR', 'INCOMING_DIR', 'INCOMING_DIR'. Aborting..." + exit 1 +fi + +MAIN_DIR="${1}" +INCOMING_DIR="${2}" +READY_SUFFIX="${3}" + +for ENTRY in "${INCOMING_DIR}"/*"${READY_SUFFIX}"; do + # If is not a file skip + if [ -f "${ENTRY}" ]; then + FILENAME_DEB=$(basename --suffix="${READY_SUFFIX}" "${ENTRY}") + BASEDIRPATH=$(dirname "${ENTRY}") + mv "${BASEDIRPATH}/${FILENAME_DEB}" "${MAIN_DIR}/${FILENAME_DEB}" + rm "${ENTRY}" + fi +done diff --git a/repo-sign.sh b/repo-sign.sh new file mode 100755 index 0000000..602d119 --- /dev/null +++ b/repo-sign.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + echo "No arguments provided. Aborting..." + exit 1 +fi + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "usage: ./repo-sign.sh [-h] [REPO_PATH GPG_SUBKEY_ID] + +Deploys packages for you. + +Possible values for the arguments: + +REPO_PATH path of the repositpry +GPG_SUBKEY_ID fingerprint of the (sub)key to use to sign + +Dependencies: - +" + exit 0 +fi + +if [ $# -lt 1 ]; then + echo "Mandatory arguments: 'REPO_PATH'. Aborting..." + exit 1 +fi + +REPO_PATH="${1}" +[ -n "${2+x}" ] && GPG_SUBKEY_ID="${2}" + +if [ ! -f "${GNUPGHOME}/pubring.kbx" ]; then + echo "The file 'pubring.kbx' file has not been found. Generating automatically a new one with a new set of keys..." + KEY_NAME="Joe Tester" + KEY_PASSPHRASE="over-the-lazy-dog" + cat >foo_keys < "${GNUPGHOME}/passphrase" +fi + +if [ -z "${GPG_SUBKEY_ID+x}" ]; then + echo "A GPG key id has not been defined. Automatically selecting a fingerprint..." + # List key and its subkey with their respective fingerprints | filter fingerprints of both keys | pick fingerprint of the second row + # (the subkey seems to be listed always after its respective subkey) + GPG_SUBKEY_ID="$(gpg --list-secret-key --with-subkey-fingerprint --with-colons | awk -F: '$1 == "fpr" {print $10;}' | sed -n '2 p')" +fi + +if [ ! -f "${REPO_PATH}"/key.pub.asc ];then + echo "Public key not published. Generating and publishing it..." + gpg --armor --export "${GPG_SUBKEY_ID}" > "${REPO_PATH}"/key.pub.asc +fi + +echo "Signing the repo..." +gpg --passphrase-file "${GNUPGHOME}/passphrase" --pinentry-mode loopback --default-key "${GPG_SUBKEY_ID}" -abs -o - "${REPO_PATH}/Release" > "${REPO_PATH}/Release.gpg" +gpg --passphrase-file "${GNUPGHOME}/passphrase" --pinentry-mode loopback --default-key "${GPG_SUBKEY_ID}" --clearsign -o - "${REPO_PATH}/Release" > "${REPO_PATH}/InRelease" +echo "Done." diff --git a/repo-update.sh b/repo-update.sh new file mode 100755 index 0000000..4168f93 --- /dev/null +++ b/repo-update.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + echo "No arguments provided. Aborting..." + exit 1 +fi + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "usage: ./repo-update.sh [-h] [REPO_PATH TEMP_DIR] + +Deploys packages for you. + +Possible values for the arguments: + +REPO_PATH path of the repositpry +TEMP_DIR path of the temporary folder + +Dependencies: - +" + exit 0 +fi + +if [ $# -lt 3 ]; then + echo "Mandatory arguments: 'REPO_PATH', 'TEMP_DIR'. Aborting..." + exit 1 +fi + +REPO_PATH="${1}" +TEMP_DIR="${2}" + +initial_position="$(pwd)" +cd "${REPO_PATH}" +apt-ftparchive packages . > "${TEMP_DIR}/Packages" +cd "${initial_position}" +gzip -k -f "${TEMP_DIR}/Packages" --to-stdout > "${TEMP_DIR}/Packages.gz" +apt-ftparchive release "${TEMP_DIR}" > "${TEMP_DIR}/Release"