xref: /minix/external/bsd/tmux/prepare-import.sh (revision 0a6a1f1d)
1#! /bin/sh
2# $NetBSD: prepare-import.sh,v 1.4 2014/07/24 15:16:26 christos 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# See the README file for general instructions.
10#
11
12set -e
13
14ProgName=${0##*/}
15
16CLEAN_PATTERNS=
17CLEAN_PATTERNS="${CLEAN_PATTERNS} [A-Z]*"
18CLEAN_PATTERNS="${CLEAN_PATTERNS} aclocal.m4"
19CLEAN_PATTERNS="${CLEAN_PATTERNS} etc"
20CLEAN_PATTERNS="${CLEAN_PATTERNS} configure*"
21
22err() {
23	echo "${ProgName}:" "${@}" 1>&2
24	exit 1
25}
26
27log() {
28	echo "${ProgName}:" "${@}"
29}
30
31backup_dist() {
32	if [ -d dist.old ]; then
33		log "Removing dist; dist.old exists"
34		rm -rf dist
35	else
36		log "Backing up dist as dist.old"
37		mv dist dist.old
38	fi
39}
40
41extract_distfile() {
42	local distfile="${1}"; shift
43	local distname="${1}"; shift
44
45	log "Extracting ${distfile}"
46	tar -xzf "${distfile}"
47	[ -d "${distname}" ] || err "Distfile did not create ${distname}"
48	log "Renaming ${distname} to dist"
49	mv "${distname}" dist
50}
51
52get_distname() {
53	local distfile="${1}"; shift
54	basename "${distfile}" | sed -e 's,\.tar.*,,'
55}
56
57cleanup_dist() {
58	log "Removing unnecessary files from dist"
59	( cd dist && rm -rf ${CLEAN_PATTERNS} )
60	find dist -name .deps -exec rm -fr {} +
61	find dist -name .dirstamp -exec rm -f {} +
62}
63
64diff_dirs() {
65	local old_dir="${1}"; shift
66	local new_dir="${1}"; shift
67
68	local old_list=$(mktemp -t tmux-import.XXXXXX)
69	local new_list=$(mktemp -t tmux-import.XXXXXX)
70	local diff=$(mktemp -t tmux-import.XXXXXX)
71	trap "rm -f '${old_list}' '${new_list}' '${diff}'; exit 1" \
72	    HUP INT QUIT TERM
73
74	( cd "${old_dir}" && find . | sort >>"${old_list}" )
75	( cd "${new_dir}" && find . | sort >>"${new_list}" )
76
77	diff -u "${old_list}" "${new_list}" | grep '^+\.' >>"${diff}" || true
78	if [ -s "${diff}" ]; then
79		log "New files found"
80		diff -u "${old_list}" "${new_list}" | grep '^+\.'
81		log "Check if any files have to be cleaned up and update" \
82		    "the prepare-import.sh script accordingly"
83	else
84		log "No new files; all good!"
85	fi
86
87	rm -f "${old_list}" "${new_list}" "${diff}"
88}
89
90main() {
91	[ ${#} -eq 1 ] || err "Must provide a distfile name"
92	local distfile="${1}"; shift
93
94	[ -f Makefile -a -f prepare-import.sh ] || \
95	    err "Must be run from the src/external/bsd/tmux subdirectory"
96
97	local distname="$(get_distname ${distfile})"
98
99	backup_dist
100	extract_distfile "${distfile}" "${distname}"
101	cleanup_dist
102	diff_dirs dist.old dist
103	cleantags dist
104	log "Don't forget to update the -D flags in usr.bin/tmux/Makefile" \
105	    "and to update the version in doc/3RDPARTY"
106}
107
108main "${@}"
109