1*11be35a1SLionel Sambuc#!/bin/sh 2*11be35a1SLionel Sambuc# $NetBSD: prepare-import.sh,v 1.1 2013/02/23 14:16:49 jmmv Exp $ 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Use this script to recreate the 'dist' subdirectory from a newly released 5*11be35a1SLionel Sambuc# distfile. The script takes care of unpacking the distfile, removing any 6*11be35a1SLionel Sambuc# files that are not relevant to NetBSD and checking if there are any new 7*11be35a1SLionel Sambuc# files in the new release that need to be addressed. 8*11be35a1SLionel Sambuc# 9*11be35a1SLionel Sambuc 10*11be35a1SLionel Sambucset -e 11*11be35a1SLionel Sambuc 12*11be35a1SLionel SambucProgName=${0##*/} 13*11be35a1SLionel Sambuc 14*11be35a1SLionel SambucCLEAN_PATTERNS= 15*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} *.m4" 16*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} INSTALL TODO" 17*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} Doxyfile*" 18*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} Makefile* */Makefile* */*/Makefile*" 19*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} admin" 20*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} api-docs" 21*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} config.h.in" 22*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} configure*" 23*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} m4" 24*11be35a1SLionel SambucCLEAN_PATTERNS="${CLEAN_PATTERNS} utils/defs.hpp" 25*11be35a1SLionel Sambuc 26*11be35a1SLionel Sambucerr() { 27*11be35a1SLionel Sambuc echo "${ProgName}:" "${@}" 1>&2 28*11be35a1SLionel Sambuc exit 1 29*11be35a1SLionel Sambuc} 30*11be35a1SLionel Sambuc 31*11be35a1SLionel Sambuclog() { 32*11be35a1SLionel Sambuc echo "${ProgName}:" "${@}" 33*11be35a1SLionel Sambuc} 34*11be35a1SLionel Sambuc 35*11be35a1SLionel Sambucbackup_dist() { 36*11be35a1SLionel Sambuc if [ -d dist.old ]; then 37*11be35a1SLionel Sambuc log "Removing dist; dist.old exists" 38*11be35a1SLionel Sambuc rm -rf dist 39*11be35a1SLionel Sambuc else 40*11be35a1SLionel Sambuc log "Backing up dist as dist.old" 41*11be35a1SLionel Sambuc mv dist dist.old 42*11be35a1SLionel Sambuc fi 43*11be35a1SLionel Sambuc} 44*11be35a1SLionel Sambuc 45*11be35a1SLionel Sambucextract_distfile() { 46*11be35a1SLionel Sambuc local distfile="${1}"; shift 47*11be35a1SLionel Sambuc local distname="${1}"; shift 48*11be35a1SLionel Sambuc 49*11be35a1SLionel Sambuc log "Extracting ${distfile}" 50*11be35a1SLionel Sambuc tar -xzf "${distfile}" 51*11be35a1SLionel Sambuc [ -d "${distname}" ] || err "Distfile did not create ${distname}" 52*11be35a1SLionel Sambuc log "Renaming ${distname} to dist" 53*11be35a1SLionel Sambuc mv "${distname}" dist 54*11be35a1SLionel Sambuc} 55*11be35a1SLionel Sambuc 56*11be35a1SLionel Sambucget_distname() { 57*11be35a1SLionel Sambuc local distfile="${1}"; shift 58*11be35a1SLionel Sambuc basename "${distfile}" | sed -e 's,\.tar.*,,' 59*11be35a1SLionel Sambuc} 60*11be35a1SLionel Sambuc 61*11be35a1SLionel Sambuccleanup_dist() { 62*11be35a1SLionel Sambuc log "Removing unnecessary files from dist" 63*11be35a1SLionel Sambuc ( cd dist && rm -rf ${CLEAN_PATTERNS} ) 64*11be35a1SLionel Sambuc} 65*11be35a1SLionel Sambuc 66*11be35a1SLionel Sambucdiff_dirs() { 67*11be35a1SLionel Sambuc local old_dir="${1}"; shift 68*11be35a1SLionel Sambuc local new_dir="${1}"; shift 69*11be35a1SLionel Sambuc 70*11be35a1SLionel Sambuc local old_list=$(mktemp -t kyua-cli-import.XXXXXX) 71*11be35a1SLionel Sambuc local new_list=$(mktemp -t kyua-cli-import.XXXXXX) 72*11be35a1SLionel Sambuc local diff=$(mktemp -t kyua-cli-import.XXXXXX) 73*11be35a1SLionel Sambuc trap "rm -f '${old_list}' '${new_list}' '${diff}'; exit 1" \ 74*11be35a1SLionel Sambuc HUP INT QUIT TERM 75*11be35a1SLionel Sambuc 76*11be35a1SLionel Sambuc ( cd "${old_dir}" && find . | sort >>"${old_list}" ) 77*11be35a1SLionel Sambuc ( cd "${new_dir}" && find . | sort >>"${new_list}" ) 78*11be35a1SLionel Sambuc 79*11be35a1SLionel Sambuc diff -u "${old_list}" "${new_list}" | grep '^+\.' >>"${diff}" || true 80*11be35a1SLionel Sambuc if [ -s "${diff}" ]; then 81*11be35a1SLionel Sambuc log "New files found" 82*11be35a1SLionel Sambuc diff -u "${old_list}" "${new_list}" | grep '^+\.' 83*11be35a1SLionel Sambuc log "Check if any files have to be cleaned up and update" \ 84*11be35a1SLionel Sambuc "the prepare-import.sh script accordingly" 85*11be35a1SLionel Sambuc else 86*11be35a1SLionel Sambuc log "No new files; all good!" 87*11be35a1SLionel Sambuc fi 88*11be35a1SLionel Sambuc 89*11be35a1SLionel Sambuc rm -f "${old_list}" "${new_list}" "${diff}" 90*11be35a1SLionel Sambuc} 91*11be35a1SLionel Sambuc 92*11be35a1SLionel Sambucmain() { 93*11be35a1SLionel Sambuc [ ${#} -eq 1 ] || err "Must provide a distfile name" 94*11be35a1SLionel Sambuc local distfile="${1}"; shift 95*11be35a1SLionel Sambuc 96*11be35a1SLionel Sambuc [ -f Makefile -a -f prepare-import.sh ] || \ 97*11be35a1SLionel Sambuc err "Must be run from the src/external/bsd/kyua-cli subdirectory" 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambuc local distname="$(get_distname ${distfile})" 100*11be35a1SLionel Sambuc 101*11be35a1SLionel Sambuc backup_dist 102*11be35a1SLionel Sambuc extract_distfile "${distfile}" "${distname}" 103*11be35a1SLionel Sambuc cleanup_dist 104*11be35a1SLionel Sambuc diff_dirs dist.old dist 105*11be35a1SLionel Sambuc} 106*11be35a1SLionel Sambuc 107*11be35a1SLionel Sambucmain "${@}" 108