Improve the process for GNU tools
[minix3.git] / external / bsd / kyua-cli / prepare-import.sh
blob09d2e587167a6b042fc017ef5d315cc04aac7112
1 #!/bin/sh
2 # $NetBSD: prepare-import.sh,v 1.1 2013/02/23 14:16:49 jmmv Exp $
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.
10 set -e
12 ProgName=${0##*/}
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} m4"
24 CLEAN_PATTERNS="${CLEAN_PATTERNS} utils/defs.hpp"
26 err() {
27 echo "${ProgName}:" "${@}" 1>&2
28 exit 1
31 log() {
32 echo "${ProgName}:" "${@}"
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
45 extract_distfile() {
46 local distfile="${1}"; shift
47 local distname="${1}"; shift
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
56 get_distname() {
57 local distfile="${1}"; shift
58 basename "${distfile}" | sed -e 's,\.tar.*,,'
61 cleanup_dist() {
62 log "Removing unnecessary files from dist"
63 ( cd dist && rm -rf ${CLEAN_PATTERNS} )
66 diff_dirs() {
67 local old_dir="${1}"; shift
68 local new_dir="${1}"; shift
70 local old_list=$(mktemp -t kyua-cli-import.XXXXXX)
71 local new_list=$(mktemp -t kyua-cli-import.XXXXXX)
72 local diff=$(mktemp -t kyua-cli-import.XXXXXX)
73 trap "rm -f '${old_list}' '${new_list}' '${diff}'; exit 1" \
74 HUP INT QUIT TERM
76 ( cd "${old_dir}" && find . | sort >>"${old_list}" )
77 ( cd "${new_dir}" && find . | sort >>"${new_list}" )
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!"
89 rm -f "${old_list}" "${new_list}" "${diff}"
92 main() {
93 [ ${#} -eq 1 ] || err "Must provide a distfile name"
94 local distfile="${1}"; shift
96 [ -f Makefile -a -f prepare-import.sh ] || \
97 err "Must be run from the src/external/bsd/kyua-cli subdirectory"
99 local distname="$(get_distname ${distfile})"
101 backup_dist
102 extract_distfile "${distfile}" "${distname}"
103 cleanup_dist
104 diff_dirs dist.old dist
107 main "${@}"