#!/usr/bin/env bash incoming_dir="/home/dhl/upload/incoming" aptly_dir="/home/dhl/.aptly" dsc_state_file="/var/tmp/dsc-state" if [[ -d ${incoming_dir} ]]; then # # Remove old stuff older than a week # find ${incoming_dir} -type f -mtime +7 -delete # # Import Binary and Source packages # for dist in ${aptly_dir}/public/dists/*/; do dist_name="$(basename ${dist})" dist_dir="${incoming_dir}/${dist_name}" if [[ -d "${dist_dir}" ]]; then # # Look only for files which haven't changed within the last 2 minutes # This skips (big) files which are still uploading # find "${dist_dir}" -type f -mmin +2 | while read import_file ; do # # Source packages # if [[ "${import_file}" == *.dsc ]]; then # # For a source package, # we have to check if all listed files are already uploaded # # If at least one files is missing # or is still uploading, we skip the dsc import until the next run # touch ${dsc_state_file} awk '/^\s/ && NF == 3 { print $3}' ${import_file} | sort -u | while read source_file; do if [[ -f "${dist_dir}/${source_file}" ]]; then if [[ $(( ( $(date +%s) - $(date -r "${dist_dir}/${source_file}" +%s) ) / 60 )) -lt 2 ]]; then rm -f ${dsc_state_file} && echo "${import_file} not imported because ${dist_dir}/${source_file} too young" fi else rm -f ${dsc_state_file} && echo "${import_file} not imported because ${dist_dir}/${source_file} missing" fi done if [[ -f ${dsc_state_file} ]]; then aptly repo add -remove-files ${dist_name}-main ${import_file} aptly publish update ${dist_name} fi fi # # Binary packages can be imported directly # if [[ "${import_file}" = *.deb ]]; then aptly repo add -remove-files ${dist_name}-main ${import_file} aptly publish update ${dist_name} fi done else # # Create folder structure, if missing # echo "[+] Creating ${dist_dir}" mkdir -p "${dist_dir}" fi done else echo "${incoming_dir} missing. Please create as root for SSH chroot" exit 1 fi