diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-01-08 14:57:50 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-01-08 15:04:27 -0500 |
commit | 7485bf9277afa53158672dca08a022630ff1d748 (patch) | |
tree | 0c3098a0ebe21b4cc3841f2abb4ca71d0d4b185c | |
parent | e3e92ddb466d04608a4d07e00dda435f9ccd31b1 (diff) |
work on moz-normalize-PKGBUILD, touch moz-normalize-mozconfig
-rwxr-xr-x | moz-normalize-PKGBUILD | 78 | ||||
-rw-r--r-- | moz-normalize-mozconfig | 0 |
2 files changed, 60 insertions, 18 deletions
diff --git a/moz-normalize-PKGBUILD b/moz-normalize-PKGBUILD index 54f15a7..f56639c 100755 --- a/moz-normalize-PKGBUILD +++ b/moz-normalize-PKGBUILD @@ -2,33 +2,75 @@ tempdir="$(mktemp -d --tmpdir mozilla-normalize.XXXXXXXXXXX)" -cat > "$tempdir/PKGBUILD" -for var in {make,check,}depends; do - # extract, normalize the data +################################################################################ + +# BUG: can insert empty lines +format_array=" +s/\(/& / # force whitespace after the opening 'var=(' bit +s/\)/ &/ # force whitespace after the trailing ')' bit +s/\s+/\n /g # delimit array elements with '\n ' +" + +format-array() { + local var=$1 + local file=$2 + sed -ri \ + -e "/^$var=\(.*\)/{ $format_array } # single-line" \ + -e "/^$var=\(/,/\)/{ $format_array } # multi-line" \ + "$file" +} + +################################################################################ + +print_array=" +/\(/d # strip the opening 'var=(' line +/\)/d # strip the trailing ')' line +/./p # print everything else +" + +sort-array() { + local var=$1 + local file=$2 + # extract the data { - sed -nr " - /^$var=\(/,/\)/{ # select the variable array - s/.*\(/ / # remove the opening 'var=(' bit - s/\).*// # remove the trailing ')' bit - s/\s+/\n /g # delimit array elements with '\n ' - /./p # print array elements - }" \ + # HACK: strip empty lines; to work around bug in format-array + sed -nr "/^$var=\(/,/\)/{ $print_array }" \ | sed '/^\s*$/d' \ | sort -u - } < "$tempdir/PKGBUILD" > "$tempdir/$var" + } < "$file" > "$tempdir/$var" # remove it from the file - sed -i -e "/^$var=(/i @$var@" -e "/^$var=/,/)/d" "$tempdir/PKGBUILD" + sed -i -e "/^$var=(/i @$var@" -e "/^$var=/,/)/d" "$file" # re-insert it into the file sed -i \ -e "/^@$var@/a$var=(" \ -e "/^@$var@/r$tempdir/$var" \ -e "/^@$var@/a)" \ -e "/^@$var@/d" \ - "$tempdir/PKGBUILD" -done + "$file" +} + +################################################################################ + +normalize() { + local file=$1 + + for var in {make,check,opt,}depends arch license; do + format-array "$var" "$file" + sort-array "$var" "$file" + done + + # clean up whitespace + sed -ri 's/\s+$//' "$file" + + # generalize + sed -i 's/firefox/$pkgbase/g' "$file" +} -# clean up whitespace -sed -ri 's/\s+$//' "$tempdir/PKGBUILD" +main() { + cat > "$tempdir/PKGBUILD" + normalize "$tempdir/PKGBUILD" + cat "$tempdir/PKGBUILD" + rm -rf "$tempdir" +} -cat "$tempdir/PKGBUILD" -rm -rf "$tempdir" +main "$@" diff --git a/moz-normalize-mozconfig b/moz-normalize-mozconfig new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/moz-normalize-mozconfig |