| 1 |
# Wanna be a helpfull file with routine functions. |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (C) 2004 Piotr Pokora <piotr.pokora@infoglob.pl> |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
# Copy all files from directory tree to another dir. |
|---|
| 7 |
# mgd_copy_files path/to/dir dest/dir filter |
|---|
| 8 |
|
|---|
| 9 |
USE_BSD=0 |
|---|
| 10 |
if [ `uname | grep -c BSD` = "1" ] || [ `uname | grep -c Darwin` = "1" ];then |
|---|
| 11 |
USE_BSD=1 |
|---|
| 12 |
fi |
|---|
| 13 |
|
|---|
| 14 |
# Set CVSROOT |
|---|
| 15 |
export CVSROOT=':pserver:anoncvs@cvs.tigris.org:/cvs' |
|---|
| 16 |
|
|---|
| 17 |
mgd_copy_files() |
|---|
| 18 |
{ |
|---|
| 19 |
local SRC_DIR=$1 |
|---|
| 20 |
local DEST_DIR=$2 |
|---|
| 21 |
local CFILES=$3 |
|---|
| 22 |
local DIRS="" |
|---|
| 23 |
|
|---|
| 24 |
if [ ! -e $DEST_DIR ];then |
|---|
| 25 |
mkdir $DEST_DIR |
|---|
| 26 |
fi |
|---|
| 27 |
|
|---|
| 28 |
if [ ! -n "$GDEST_DIR" ];then |
|---|
| 29 |
GDEST_DIR=$PWD/$DEST_DIR |
|---|
| 30 |
fi |
|---|
| 31 |
|
|---|
| 32 |
PWD=`pwd` |
|---|
| 33 |
|
|---|
| 34 |
for DIRS in `ls -R $SRC_DIR | sed 's/://'`; do |
|---|
| 35 |
if [ -d $DIRS ]; then |
|---|
| 36 |
for FILES in `ls $DIRS | grep $CFILES`; do |
|---|
| 37 |
cp $DIRS/$FILES $DEST_DIR |
|---|
| 38 |
done |
|---|
| 39 |
fi |
|---|
| 40 |
done |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
# Check if cvs version has changed. |
|---|
| 45 |
# RET is 0 if changed , -1 if not. |
|---|
| 46 |
# MIDGARD_VERSION is latest version ( either changed or not ) |
|---|
| 47 |
|
|---|
| 48 |
mgd_is_cvs_changed() |
|---|
| 49 |
{ |
|---|
| 50 |
local MGD_CVS_VERSION |
|---|
| 51 |
local MGD_CVS_VERSIONF |
|---|
| 52 |
local LAST_CVS_VERSION |
|---|
| 53 |
|
|---|
| 54 |
MGD_CVS_VERSIONF=`./midgard-cvs-version` |
|---|
| 55 |
MGD_CVS_VERSION=`echo $MGD_CVS_VERSIONF | sed 's/^.*cvs-//1'` |
|---|
| 56 |
|
|---|
| 57 |
if [ ! -f "$PWD/last_cvs_version" ];then |
|---|
| 58 |
touch "$PWD/last_cvs_version" |
|---|
| 59 |
fi |
|---|
| 60 |
|
|---|
| 61 |
LAST_CVS_VERSION="`cat ./last_cvs_version`" |
|---|
| 62 |
LAST_CVS_VERSION=`echo $LAST_CVS_VERSION | sed 's/^.*cvs-//1'` |
|---|
| 63 |
|
|---|
| 64 |
if [ "$LAST_CVS_VERSION" = "" ]; then |
|---|
| 65 |
LAST_CVS_VERSION=0 |
|---|
| 66 |
fi |
|---|
| 67 |
|
|---|
| 68 |
if [ $MGD_CVS_VERSION -gt $LAST_CVS_VERSION ];then |
|---|
| 69 |
RET=0 |
|---|
| 70 |
echo $MGD_CVS_VERSIONF > "$PWD/last_cvs_version" |
|---|
| 71 |
MIDGARD_VERSION="`cat ./last_cvs_version`" |
|---|
| 72 |
else |
|---|
| 73 |
RET=-1 |
|---|
| 74 |
MIDGARD_VERSION="`cat ./last_cvs_version`" |
|---|
| 75 |
fi |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
# Updates Midgard src dir from CVS |
|---|
| 80 |
# Creates cvs.log cache file for faster usage |
|---|
| 81 |
# If you don't want it to be created, use parameter "nocvslog" |
|---|
| 82 |
# Returns 0 when there were changes, 1 when not |
|---|
| 83 |
|
|---|
| 84 |
mgd_cvs_update() |
|---|
| 85 |
{ |
|---|
| 86 |
local CVS_LOG=0 |
|---|
| 87 |
local BEFORE |
|---|
| 88 |
local AFTER |
|---|
| 89 |
local DATE |
|---|
| 90 |
local TIME |
|---|
| 91 |
|
|---|
| 92 |
if [ "$1" = "nocvslog" ]; then |
|---|
| 93 |
CVS_LOG=1 |
|---|
| 94 |
fi |
|---|
| 95 |
|
|---|
| 96 |
DATE=`mgd_cvs_date` |
|---|
| 97 |
TIME=`mgd_cvs_time` |
|---|
| 98 |
BEFORE=${DATE}${TIME} |
|---|
| 99 |
|
|---|
| 100 |
# Remove the CVS log cache file before update |
|---|
| 101 |
# We don't want to see ? mark about it :) |
|---|
| 102 |
rm -f cvs.log |
|---|
| 103 |
|
|---|
| 104 |
# Do the actual update |
|---|
| 105 |
#cvs -Q -z3 update -CdR |
|---|
| 106 |
|
|---|
| 107 |
# Do checkout |
|---|
| 108 |
cvs -z3 checkout midgard |
|---|
| 109 |
|
|---|
| 110 |
if [ $CVS_LOG -eq 0 ]; then |
|---|
| 111 |
# Cache CVS log for faster usage |
|---|
| 112 |
cvs -Q log > cvs.log |
|---|
| 113 |
fi |
|---|
| 114 |
|
|---|
| 115 |
DATE=`mgd_cvs_date` |
|---|
| 116 |
TIME=`mgd_cvs_time` |
|---|
| 117 |
AFTER=${DATE}${TIME} |
|---|
| 118 |
|
|---|
| 119 |
if [ "$BEFORE" != "$AFTER" ]; then |
|---|
| 120 |
return 0 |
|---|
| 121 |
else |
|---|
| 122 |
return 1 |
|---|
| 123 |
fi |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
# Prints the CVS log |
|---|
| 128 |
|
|---|
| 129 |
mgd_cvs_log() |
|---|
| 130 |
{ |
|---|
| 131 |
# Use the cache file if it exists |
|---|
| 132 |
if [ -r cvs.log ] |
|---|
| 133 |
then |
|---|
| 134 |
cat cvs.log |
|---|
| 135 |
else |
|---|
| 136 |
cvs -Q log |
|---|
| 137 |
fi |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
# Prints last CVS modification date in format %Y%m%d |
|---|
| 142 |
|
|---|
| 143 |
mgd_cvs_date() |
|---|
| 144 |
{ |
|---|
| 145 |
mgd_cvs_log | grep "^date:" | sort -r | head -1 | cut -f2 -d" " | sed "s/\///g" |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
# Prints last CVS modification time in format "date -u +%H%M%S" |
|---|
| 150 |
|
|---|
| 151 |
mgd_cvs_time() |
|---|
| 152 |
{ |
|---|
| 153 |
mgd_cvs_log | grep "^date:" | sort -r | head -1 | cut -f3 -d" " | cut -f1 -d";" | sed s/://g |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
# Prints all stable releases (tag name must begin with "release-") |
|---|
| 158 |
|
|---|
| 159 |
mgd_releases() |
|---|
| 160 |
{ |
|---|
| 161 |
mgd_cvs_log | grep "release-" | cut -f2 | cut -f1 -d":" | sort -ur | sed s/release-// | sed s/-/./g | sed s/_/./g | grep -v "[0-9]\(.\)[a-z]" |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
# Prints the current stable release version |
|---|
| 166 |
# Note that you should append "cvsYYYYMMDD" to CVS snapshots |
|---|
| 167 |
|
|---|
| 168 |
mgd_release() |
|---|
| 169 |
{ |
|---|
| 170 |
mgd_releases | head -1 |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
# Prints the CVS snapshot release version |
|---|
| 175 |
# This should be used with CVS snapshots |
|---|
| 176 |
# With stable releases you should call "mgd_release" instead |
|---|
| 177 |
|
|---|
| 178 |
mgd_cvs_release() |
|---|
| 179 |
{ |
|---|
| 180 |
local RELEASE |
|---|
| 181 |
local DATE |
|---|
| 182 |
RELEASE=`mgd_release` |
|---|
| 183 |
if [ x$RELEASE != x ]; then |
|---|
| 184 |
# Midgard generation, major and minor version number part |
|---|
| 185 |
MIDGARD_GENERATION=${RELEASE%%.*} |
|---|
| 186 |
RELSTR=${RELEASE#*.} |
|---|
| 187 |
MIDGARD_MINOR=${RELEASE##*.} |
|---|
| 188 |
MIDGARD_MAJOR=${RELSTR%%.*} |
|---|
| 189 |
if [ $RELSTR = $MIDGARD_MINOR ]; then |
|---|
| 190 |
MIDGARD_MINOR="" |
|---|
| 191 |
MIDGARD_MAJOR=${RELSTR%%[^0-9]*} |
|---|
| 192 |
MIDGARD_STR=${RELSTR#${MIDGARD_MAJOR}} |
|---|
| 193 |
fi |
|---|
| 194 |
if [ x$MIDGARD_MINOR != x ]; then |
|---|
| 195 |
MIDGARD_STR=${MIDGARD_MINOR%%[^0-9]*} |
|---|
| 196 |
MIDGARD_STR=${MIDGARD_MINOR#${MIDGARD_STR}} |
|---|
| 197 |
MIDGARD_MINOR=${MIDGARD_MINOR%%[^0-9]*} |
|---|
| 198 |
fi |
|---|
| 199 |
if [ $MIDGARD_GENERATION -le 1 ]; then |
|---|
| 200 |
if [ $MIDGARD_MAJOR -lt 8 ]; then |
|---|
| 201 |
# Mark release as future 1.8 but without minor number |
|---|
| 202 |
# This keeps packagers happy but tells that we are at HEAD, not branch-1-7 |
|---|
| 203 |
# Well, for getting packagers to work, you should modify this according to |
|---|
| 204 |
# which release is the latest, if no alpha1 yet, define "alpha0" (pre-alpha). |
|---|
| 205 |
# When alpha1 is out --> "alpha1", when "beta1" is out --> "beta1". |
|---|
| 206 |
RELEASE=1.8alpha0 |
|---|
| 207 |
fi |
|---|
| 208 |
fi |
|---|
| 209 |
fi |
|---|
| 210 |
DATE=`mgd_cvs_date` |
|---|
| 211 |
echo ${RELEASE}_${DATE} |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
# Tells if a string name matches with the provided list |
|---|
| 216 |
|
|---|
| 217 |
mgd_in_list() |
|---|
| 218 |
{ |
|---|
| 219 |
local FILE=$1 |
|---|
| 220 |
local FILES=$2 |
|---|
| 221 |
local ret=1 |
|---|
| 222 |
|
|---|
| 223 |
for file in $FILES; do |
|---|
| 224 |
if [ "$file" = "$FILE" ]; then |
|---|
| 225 |
ret=0 |
|---|
| 226 |
fi |
|---|
| 227 |
done |
|---|
| 228 |
|
|---|
| 229 |
return $ret |
|---|
| 230 |
} |
|---|