Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active December 15, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou1okada/5207270 to your computer and use it in GitHub Desktop.
Save kou1okada/5207270 to your computer and use it in GitHub Desktop.
setup.ini maker for cygwin
#!/usr/bin/env bash
# Copyright (c) 2013 Koichi OKADA. All rights reserved.
# This script is distributed under the MIT license.
# http://www.opensource.org/licenses/mit-license.php
SCRIPTNAME=${0##*/}
function usage ()
{
cat <<EOD
Usage: ${SCRIPTNAME} [options]
setup.ini maker for cygwin
options:
--direct -d Do not backup.
--update -u Update setup.ini
--quiet -q Quiet (when -u option is gived).
--help -h Show this help.
This script find setup.hint files from under x86 and x86_64 directories
and collect package informations.
The setup.hint file must have follow lines:
-------------------------------------------
@ packagename
sdesc: "short description"
ldesc: "long description
...
"
category: categories
requires: require packages
@ packagename
...
-------------------------------------------
Brank line separates packages.
EOD
}
function mkbackup ()
{
if [ -e "$1" ]; then
local BAK="$1.$(date -r "$1" +%Y%m%d_%H%M%S)~"
$OPT_q || echo "backup $1 to $BAK" > /dev/stderr
mv "$1" "$BAK"
fi
}
# splitentry SETUPHINT PKGNAME
function splitentry ()
{
grep -A10000 "@ $2" "$1" \
| awk '
function isinstr(s, instr){
while (s!="") {
if (instr) {
if (match(s, /^([^"\\]*|\\x[0-9a-fA-f][0-9a-fA-F]?|\\[0-9][0-9]?[0-9]?|\\.|\\$)*/))
s = substr(s, RSTART + RLENGTH);
} else {
if (match(s, /^[^"]*/))
s = substr(s, RSTART + RLENGTH);
}
if (match(s,/^"/)) {
s = substr(s, RSTART + RLENGTH);
instr = !instr
}
}
return instr
}
{
if (!instr && $0 == "") {
exit;
}
print $0;
instr = isinstr($0, instr);
}
' \
| grep -v '^version:\|^install:' \
| sed -e 's/\r\n/\n/g'
}
function upset () {
find $1 -type f -name '*.tar.bz2' -or -name '*.tar.xz' | sed -r 's:^./::g' | while read i; do
[ "$OPT_u" == "true" -a "$OPT_q" == "false" ] && echo -n . >&2
local FILEPATH="$i"
local BASEPATH="${FILEPATH%/*}"
local SETUPHINT="${BASEPATH}/setup.hint"
if [ -e $SETUPHINT ]; then
local FILENAME="${FILEPATH##*/}"
local FILENAMEBODY="${FILENAME%.tar*}"
local PKGNAME="${BASEPATH##*/}"
local VERSION="$(echo "${FILENAMEBODY}" | cut -b$[ ${#PKGNAME} + 2 ]- )"
local HASH="$(md5sum $i | cut -d" " -f1)"
local SIZE="$(ls -l $FILEPATH | cut -d" " -f5)"
splitentry "$SETUPHINT" "$PKGNAME" && \
echo version: $VERSION && \
echo install: $FILEPATH $SIZE $HASH && \
echo
fi
done
}
OPT_q=false
OPT_d=false
OPT_u=false
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
usage
exit
;;
--direct|-d)
OPT_d=true
shift
;;
--update|-u)
OPT_u=true
shift
;;
--quiet|-q)
OPT_q=true
shift
;;
*)
echo -e "\e[31;1mError:\e[21m unknown parameter:\e[0m $1"
echo
usage
exit
;;
esac
done
for i in x86 x86_64; do
if "$OPT_u"; then
$OPT_d || mkbackup $i/setup.ini
$OPT_q || echo -n "updating $i/setup.ini " >&2
upset $i > $i/setup.ini
$OPT_q || echo -e "\ndone" >&2
else
upset $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment