- rules can be defined in optional .fg-submit config files, via commands
ALLOW, DENY, IGNORE, DEFAULT ... see documentation on top - make fg-upload arguments like the documentation says. (I had accidentally left $1=$PWD, $2=archive, $3=diff, while it should be $1=archive, $2=diff) - add -v option (verbose)
This commit is contained in:
parent
3f1b379e9a
commit
abc3b3ffa1
1 changed files with 139 additions and 27 deletions
|
@ -12,7 +12,10 @@
|
||||||
# of the diff correctness. It is not to be submitted. The script will
|
# of the diff correctness. It is not to be submitted. The script will
|
||||||
# not overwrite any file, but rather rename conflicting files.
|
# not overwrite any file, but rather rename conflicting files.
|
||||||
#
|
#
|
||||||
# Usage: fg-submit [<basename>]
|
# Usage: fg-submit [-v] [<basename>]
|
||||||
|
#
|
||||||
|
# Options:
|
||||||
|
# -v ... verbose output
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# $ cd $FG_ROOT/Aircraft/bo105
|
# $ cd $FG_ROOT/Aircraft/bo105
|
||||||
|
@ -28,6 +31,7 @@
|
||||||
# alias submit='fg-submit "${PWD/#*\/}-$(date +%Y-%m-%d)"'
|
# alias submit='fg-submit "${PWD/#*\/}-$(date +%Y-%m-%d)"'
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
#
|
||||||
# If the script finds an application named "fg-upload", then it calls
|
# If the script finds an application named "fg-upload", then it calls
|
||||||
# this at the end with two arguments:
|
# this at the end with two arguments:
|
||||||
#
|
#
|
||||||
|
@ -50,10 +54,66 @@
|
||||||
# else
|
# else
|
||||||
# echo "arghh ... HELP! HELP!"
|
# echo "arghh ... HELP! HELP!"
|
||||||
# fi
|
# fi
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Whether a file should be included in the archive or not, is decided
|
||||||
|
# by pattern rules. There is a set of reasonable default rules predefined,
|
||||||
|
# but alternative settings can be defined in a hidden configuration file
|
||||||
|
# named ".fg-submit". Such a file is searched in the current directory,
|
||||||
|
# in its parent directory, in its grand-parent directory and so on,
|
||||||
|
# and finally in the $HOME directory. The first found file is taken.
|
||||||
|
#
|
||||||
|
# A file can use a list of four keywords with arguments, each on a
|
||||||
|
# separate line:
|
||||||
|
#
|
||||||
|
# ALLOW <pattern-list> ... accept & report matching file
|
||||||
|
# DENY <pattern-list> ... reject & report matching file
|
||||||
|
# IGNORE <pattern-list> ... silently reject matching file
|
||||||
|
# DEFAULT ... adds default rules
|
||||||
|
#
|
||||||
|
# A <pattern-list> is a space-separated list of shell pattern.
|
||||||
|
# It may also be empty, in which case it has no effect. Examples:
|
||||||
|
#
|
||||||
|
# DENY test.blend
|
||||||
|
# ALLOW *.xcf *.blend
|
||||||
|
#
|
||||||
|
# A config file that only contains the keyword DEFAULT causes the
|
||||||
|
# same behavior as no config file at all. A config file without
|
||||||
|
# DEFAULT drops the built-in default rules (with the exception of
|
||||||
|
# a few very basic ones, such as rejection of CVS files). Comments
|
||||||
|
# using the hash character '#' are allowed and ignored.
|
||||||
|
#
|
||||||
|
# The list of pattern is checked in the same in order in which it
|
||||||
|
# is built. The first match causes a file to be accepted or rejected.
|
||||||
|
# Further matches are not considered.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# DENY test.xcf # throw out the test graphic, but ...
|
||||||
|
# ALLOW *.xcf # ... allow all other GIMP graphics (the following
|
||||||
|
# # DEFAULT keyword throws them out otherwise)
|
||||||
|
#
|
||||||
|
# DEFAULT # insert the default rules here
|
||||||
|
#
|
||||||
|
# ALLOW g.old # add this silly file :-)
|
||||||
|
# IGNORE *.old # throw out the old files (and don't report
|
||||||
|
# # that to the terminal)
|
||||||
|
#
|
||||||
|
# .fg-submit configuration files are sourced bash scripts, the
|
||||||
|
# keywords are simple shell functions. That means that you can
|
||||||
|
# also use other bash commands in that file, such as "echo".
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SELF=${0/#*\/}
|
SELF=${0/#*\/}
|
||||||
DIR=${PWD/#*\/}
|
DIR=${PWD/#*\/}
|
||||||
|
|
||||||
|
if [ "$1" == "-v" ]; then
|
||||||
|
DBG=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
BASE=${1:-$DIR}
|
BASE=${1:-$DIR}
|
||||||
BASE=${BASE// /%20}
|
BASE=${BASE// /%20}
|
||||||
|
|
||||||
|
@ -65,12 +125,36 @@ ARCHIVE=$BASE.tar.bz2
|
||||||
DIFF=$BASE.diff
|
DIFF=$BASE.diff
|
||||||
CDIFF=$DIFF.bz2
|
CDIFF=$DIFF.bz2
|
||||||
|
|
||||||
|
# these rules are always prepended (the leading ! makes silent rejects)
|
||||||
|
PREFIX_RULES="
|
||||||
|
!$DIFF* !$CDIFF* !$ARCHIVE*
|
||||||
|
!CVS/* !*/CVS/*
|
||||||
|
"
|
||||||
|
# these rules are used when no other rules are specified,
|
||||||
|
# and wherever the DEFAULT keyword is used
|
||||||
|
DEFAULT_RULES="
|
||||||
|
+.cvsignore +*/.cvsignore
|
||||||
|
-*~ -*. -*.bak -*.orig
|
||||||
|
-*.RGB -*.RGBA -*.MDL
|
||||||
|
-*.xcf -*.XCF -*.tga -*.TGA -*.bmp -*.BMP -*.png -*.PNG
|
||||||
|
-*.blend -*.blend[0-9] -*blend[0-9][0-9] -*.blend[0-9][0-9][0-9]
|
||||||
|
-*.gz -*.tgz -*.bz2 -*.zip -*.tar.gz* -*.tar.bz2*
|
||||||
|
"
|
||||||
|
# these rules are always appended; the last one accepts anything
|
||||||
|
# (throw out all hidden files that weren't explicitly allowed, and
|
||||||
|
# accept the rest)
|
||||||
|
POSTFIX_RULES="
|
||||||
|
!.* !*/.*
|
||||||
|
+*
|
||||||
|
"
|
||||||
|
|
||||||
|
|
||||||
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
||||||
function LOG { echo -e "\e[35m$*\e[m"; }
|
function LOG { echo -e "\e[35m$*\e[m"; }
|
||||||
function NEW { echo -e "\e[32m\t+ $*\e[m"; }
|
function NEW { echo -e "\e[32m\t+ $*\e[m"; }
|
||||||
function CHANGED { echo -e "\e[36m\t+ $*\e[m"; }
|
function CHANGED { echo -e "\e[36m\t+ $*\e[m"; }
|
||||||
function REJECT { echo -e "\e[31m\t- $*\e[m"; }
|
function REJECT { echo -e "\e[31m\t- $*\e[m"; }
|
||||||
|
function DEBUG { [ $DBG ] && echo -e "$*"; }
|
||||||
|
|
||||||
function diffstat {
|
function diffstat {
|
||||||
# output diff statistics, similar to the "diffstat" utility
|
# output diff statistics, similar to the "diffstat" utility
|
||||||
|
@ -109,6 +193,38 @@ function diffstat {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# set up accept/reject rules
|
||||||
|
function DEFAULT { RULES="$RULES $DEFAULT_RULES"; }
|
||||||
|
function ALLOW { for i in $*; do RULES="$RULES +$i"; done }
|
||||||
|
function DENY { for i in $*; do RULES="$RULES -$i"; done }
|
||||||
|
function IGNORE { for i in $*; do RULES="$RULES !$i"; done }
|
||||||
|
|
||||||
|
RULES=
|
||||||
|
HERE=$PWD
|
||||||
|
while true; do
|
||||||
|
if [ -f .fg-submit ]; then
|
||||||
|
CONFIG="$PWD/.fg-submit"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
cd ..
|
||||||
|
[ "$PWD" == "/" ] && break
|
||||||
|
done
|
||||||
|
cd "$HERE"
|
||||||
|
|
||||||
|
if [ "$CONFIG" ]; then
|
||||||
|
DEBUG "reading config $CONFIG"
|
||||||
|
source "$CONFIG"
|
||||||
|
elif [ -f ~/.fg-submitrc ]; then
|
||||||
|
DEBUG "reading config ~/.fg-submitrc"
|
||||||
|
source ~/.fg-submitrc
|
||||||
|
else
|
||||||
|
DEBUG "no config file found; using default rules"
|
||||||
|
RULES="$RULES $DEFAULT_RULES"
|
||||||
|
fi
|
||||||
|
RULES="$PREFIX_RULES $RULES $POSTFIX_RULES"
|
||||||
|
DEBUG "using these rules: $RULES"
|
||||||
|
|
||||||
|
|
||||||
# create temporary dir that's automatically removed on exit
|
# create temporary dir that's automatically removed on exit
|
||||||
TMP=$(mktemp -d /tmp/$SELF.$BASE.XXXXXX) || (echo "$0: can't create temporary dir"; exit 1)
|
TMP=$(mktemp -d /tmp/$SELF.$BASE.XXXXXX) || (echo "$0: can't create temporary dir"; exit 1)
|
||||||
trap "rm -rf $TMP" 0 1 2 3 13 15
|
trap "rm -rf $TMP" 0 1 2 3 13 15
|
||||||
|
@ -166,31 +282,27 @@ done
|
||||||
# classify and filter files
|
# classify and filter files
|
||||||
if [ -f $TMP/check ]; then
|
if [ -f $TMP/check ]; then
|
||||||
for i in $(cat $TMP/check); do
|
for i in $(cat $TMP/check); do
|
||||||
case "$i" in
|
DEBUG "checking whether file '$i' matches"
|
||||||
$ARCHIVE*|$DIFF*) # don't add files generated by the script
|
for r in $RULES; do
|
||||||
;;
|
DEBUG "\t\trule $r"
|
||||||
*/.*|.*) # silently drop hidden files
|
R=${r#?}
|
||||||
;;
|
case "!$i" in $r)
|
||||||
*~|*.|*.bak|*.orig)
|
DEBUG "\t\t\t\"silently\" rejected\t\t(rule $R)"
|
||||||
REJECT "$i\t\t(backup file)"
|
break
|
||||||
;;
|
|
||||||
CVS/*|*/CVS/*)
|
|
||||||
REJECT "$i\t\t(CVS file)"
|
|
||||||
;;
|
|
||||||
*.tar.gz*|*.tar.bz2*|*.tgz|*.zip)
|
|
||||||
REJECT "$i\t\t(archive)"
|
|
||||||
;;
|
|
||||||
*.blend|*.blend[0-9]|*.blend[0-9][0-9])
|
|
||||||
REJECT "$i\t\t(blender file)"
|
|
||||||
;;
|
|
||||||
*.xcf|*.tga|*.bmp|*.BMP|*.png)
|
|
||||||
REJECT "$i\t\t(graphics file)"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
NEW "$i"
|
|
||||||
echo "$i" >>$TMP/files
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
case "-$i" in $r)
|
||||||
|
REJECT "$i\t\t(rule $R)"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case "+$i" in $r)
|
||||||
|
NEW "$i\t\t(rule $R)"
|
||||||
|
echo "$i" >>$TMP/files
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -214,7 +326,7 @@ else
|
||||||
RESULT=$ARCHIVE
|
RESULT=$ARCHIVE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -x "$UPLOAD" -a -f $RESULT ] && $UPLOAD "$PWD" $RESULT $DIFF
|
[ -x "$UPLOAD" -a -f $RESULT ] && $UPLOAD $RESULT $DIFF
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue