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