AptlyOnDemand/aptly.boot

52 lines
1.4 KiB
Clojure
Executable File

#!/bin/bash
function usage {
echo "usage:"
echo "aptly.boot <port> <packages_folder> <dataset_folder>"
echo
echo "port: tcp port to publish repository"
echo "packages_folder: folder to mount containing packages"
echo "dataset_folder: folder where to write repository public key and source list"
echo
exit 0
}
if [ $# -ne 3 ]
then
usage
fi
PORT=$1
PACKAGES_FOLDER="$(realpath $2)"
DATASET_FOLDER="$(realpath $3)"
if [ ! -e "${PACKAGES_FOLDER}" ]
then
mkdir "${PACKAGES_FOLDER}"
echo "${PACKAGES_FOLDER} est vide"
fi
if [ ! -e "${DATASET_FOLDER}" ]
then
mkdir "${DATASET_FOLDER}"
fi
container_id=$(docker run -d -v ${PACKAGES_FOLDER}:/packages:z -v ${DATASET_FOLDER}:/signing-key:z -p $PORT:8080 -e USER_EMAIL="$(git config user.email)" -e USER_NAME="$(git config user.name)" -e PASSPHRASE="$(pwgen -1 -n 20)" cadoles/aptly:dev)
docker ps -q --no-trunc | grep -q ${container_id}
res=$?
if [ "${res}" -eq 0 ]
then
echo "container with id $container_id started"
echo "Send ${DATASET_FOLDER}/aptly.key to remote host, load it in gpg ring with apt-key"
echo "and add repo to apt source list"
echo "echo \"deb [arch=amd64] http://$(ip -f inet address show dev enp5s0 | grep -Po 'inet \K[\d.]+'):${PORT}/ ubuntu main\" > /etc/apt/sources.list.d/aptly.list"
echo "deb [arch=amd64] http://$(ip -f inet address show dev enp5s0 | grep -Po 'inet \K[\d.]+'):${PORT}/ ubuntu main" > ${DATASET_FOLDER}/aptly.list
else
echo "container not started"
fi
exit 0