2 # Yes, this intends to be a true POSIX script file.
7 # Parse the tools' paths configuration
12 Usage: ${myname} <src_dir> <dst_dir> <base> <inc> [sed_re]
13 Renumbers all patches found in 'src_dir', starting at 'base', with an
14 increment of 'inc', and puts the renumbered patches in 'dst_dir'.
15 Leading digits are replaced with the new indexes, and a subsequent '_'
16 is replaced with a '-'.
17 If 'sed_re' is given, it is interpreted as a valid sed expression, and
18 is be applied to the patch name.
19 If the environment variable FAKE is set to 'y', then nothing gets done,
20 the command to run is only be printed, and not executed (so you can
22 'dst_dir' must not yet exist.
24 patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10
25 patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;'
29 [ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; }
36 if [ ! -d "${src}" ]; then
37 printf "%s: '%s': not a directory\n" "${myname}" "${src}"
40 if [ -d "${dst}" ]; then
41 printf "%s: '%s': directory already exists\n" "${myname}" "${dst}"
46 if [ -n "${FAKE}" ]; then
47 printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}"
51 ${Q} mkdir -pv "${dst}"
52 for p in "${src}/"*.patch*; do
53 [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
54 newname="$(printf "%03d-%s" \
57 |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
61 ${Q} cp -v "${p}" "${dst}/${newname}"