Changeset 103 for confman/confmanlib.sh
- Timestamp:
- 05/18/2006 20:41:10 (6 years ago)
- File:
-
- 1 edited
-
confman/confmanlib.sh (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
confman/confmanlib.sh
r94 r103 13 13 # Checks out the conf tree if we don't already have it. Updates it if we do. 14 14 function conf_checkout_tree { 15 if [ ! -d ${WORK_PATH} ] ; then 16 local path=`echo ${WORK_PATH} | sed -E 's:/[^/]+$::'` 17 mkdir -p ${WORK_PATH} 18 19 # This makes sure nobody can enter your working copy. We relax the 20 # permissions during the rollout, and restrict them again at the end. 21 chmod 700 ${WORK_PATH} 22 23 svn checkout ${REPO_URI} ${WORK_PATH} 24 rm -rf ${path}/.svn 25 else 26 svn update ${WORK_PATH} 27 fi 15 if [ ! -d ${WORK_PATH} ] ; then 16 local path=`echo ${WORK_PATH} | sed -E 's:/[^/]+$::'` 17 mkdir -p ${WORK_PATH} 18 19 # This makes sure nobody can enter your working copy. We relax the 20 # permissions during the rollout, and restrict them again at 21 # the end. 22 chmod 700 ${WORK_PATH} 23 24 svn checkout ${REPO_URI} ${WORK_PATH} 25 rm -rf ${path}/.svn 26 else 27 svn update ${WORK_PATH} 28 fi 28 29 } 29 30 30 31 # I update the working copy of a given module to the repository's copy. 31 32 function conf_update_module { 32 local module="$1"33 svn update ${WORK_PATH}/${module}33 local module="$1" 34 svn update ${WORK_PATH}/${module} 34 35 } 35 36 36 37 # Updates the whole source tree 37 38 function conf_update_tree { 38 svn update ${WORK_PATH}39 svn update ${WORK_PATH} 39 40 } 40 41 41 42 # Revert a working file 42 43 function conf_revert { 43 svn revert $*44 svn revert $* 44 45 } 45 46 46 47 # Assumes that we already have core setup in our work path. 47 48 function conf_create_module { 48 local module=$149 svn mkdir ${WORK_PATH}/$module50 svn mkdir ${WORK_PATH}/${REPO_CHECKPTS}/$module51 svn commit ${WORK_PATH}/${module} ${WORK_PATH}/${REPO_CHECKPTS}/$module -m \52 "Created directory structure for ${module} --`whoami`"49 local module=$1 50 svn mkdir ${WORK_PATH}/$module 51 svn mkdir ${WORK_PATH}/${REPO_CHECKPTS}/$module 52 svn commit ${WORK_PATH}/${module} ${WORK_PATH}/${REPO_CHECKPTS}/$module -m \ 53 "Created directory structure for ${module} --`whoami`" 53 54 } 54 55 55 56 # Commits module $1 with message $2 56 57 function conf_commit { 57 local module=$158 local msg="$2"59 svn commit -F "$msg" ${WORK_PATH}/$module58 local module=$1 59 local msg="$2" 60 svn commit -F "$msg" ${WORK_PATH}/$module 60 61 } 61 62 62 63 # A way to utilize the svn status feature. 63 64 function conf_status { 64 svn status $*65 svn status $* 65 66 } 66 67 67 68 # Roll out the specified module, optionally at the specified checkpoint 68 # eg: conf_rollout MODULE [checkpoint]69 # eg: conf_rollout MODULE [checkpoint] 69 70 function conf_rollout { 70 local module="$1"71 if [ -z $2 ] ; then72 local moduledir="${WORK_PATH}/$module"73 else74 local moduledir="${WORK_PATH}/checkpoints/${module}/${2}"75 fi76 # This is a hack to work around NFS home dirs, for now:77 chmod o+rx ${WORK_PATH}78 79 for directory in `find $moduledir -type d | grep -v "\.svn"` ; do80 local livedir=`echo $directory | sed "s:$moduledir::"`81 livedir="${LIVE_ROOT}${livedir}"82 if [ ! -d $livedir ] ; then83 local owner=`conf_get_prop ${directory} owner`84 local group=`conf_get_prop ${directory} group`85 local mode=`conf_get_prop ${directory} mode`86 local opts="-d -o $owner -g $group -m $mode"87 local cmd="sudo install $opts $livedir"88 echo $cmd89 $cmd90 fi91 done92 for file in `find $moduledir -type f | grep -v "\.svn"` ; do93 local livefile=`echo "$file" | sed "s:$moduledir::"`94 local owner=`conf_get_prop ${file} owner`95 local group=`conf_get_prop ${file} group`96 local mode=`conf_get_prop ${file} mode`97 local opts="-Sp -o $owner -g $group -m $mode"98 local cmd="sudo install $opts $file ${LIVE_ROOT}$livefile"99 echo $cmd100 $cmd101 done102 # This is a hack to work around NFS home dirs, for now:103 chmod o-rx ${WORK_PATH}71 local module="$1" 72 if [ -z $2 ] ; then 73 local moduledir="${WORK_PATH}/$module" 74 else 75 local moduledir="${WORK_PATH}/checkpoints/${module}/${2}" 76 fi 77 # This is a hack to work around NFS home dirs, for now: 78 chmod o+rx ${WORK_PATH} 79 80 for directory in `find $moduledir -type d | grep -v "\.svn"` ; do 81 local livedir=`echo $directory | sed "s:$moduledir::"` 82 livedir="${LIVE_ROOT}${livedir}" 83 if [ ! -d $livedir ] ; then 84 local owner=`conf_get_prop ${directory} owner` 85 local group=`conf_get_prop ${directory} group` 86 local mode=`conf_get_prop ${directory} mode` 87 local opts="-d -o $owner -g $group -m $mode" 88 local cmd="sudo install $opts $livedir" 89 echo $cmd 90 $cmd 91 fi 92 done 93 for file in `find $moduledir -type f | grep -v "\.svn"` ; do 94 local livefile=`echo "$file" | sed "s:$moduledir::"` 95 local owner=`conf_get_prop ${file} owner` 96 local group=`conf_get_prop ${file} group` 97 local mode=`conf_get_prop ${file} mode` 98 local opts="-Sp -o $owner -g $group -m $mode" 99 local cmd="sudo install $opts $file ${LIVE_ROOT}$livefile" 100 echo $cmd 101 $cmd 102 done 103 # This is a hack to work around NFS home dirs, for now: 104 chmod o-rx ${WORK_PATH} 104 105 } 105 106 106 107 function conf_install { 107 local module="$1"108 shift109 local file=`abspath $1`110 shift111 local moduledir="${WORK_PATH}/$module"112 local livefile=`echo "$file" | sed -E "s:${WORK_PATH}/[^/]+::"`113 local pathmodule=`echo "$file" | sed -E "s:${WORK_PATH}/([^/]+).*:\1:"`114 local suffix115 livefile=`echo "$livefile" | sed -E "s:-${pathmodule}$::"`116 if [[ $SINGULARITIES =~ $livefile ]] ; then117 suffix="-${module}"118 fi119 livefile="${livefile}${suffix}"120 121 122 # See if it even exists123 file="${moduledir}${livefile}"124 if [ ! -f $file ] ; then125 return 0126 fi127 128 # If we got here, figure it out129 local owner=`conf_get_prop ${file} owner`130 local group=`conf_get_prop ${file} group`131 local mode=`conf_get_prop ${file} mode`132 local opts="-Sp -o $owner -g $group -m $mode"133 local cmd="sudo install $opts $file ${LIVE_ROOT}$livefile"134 135 chmod o+rx ${WORK_PATH}136 echo $cmd137 $cmd138 chmod o-rx ${WORK_PATH}139 140 if [ ! -z $1 ] ; then141 conf_install $module $*142 fi108 local module="$1" 109 shift 110 local file=`abspath $1` 111 shift 112 local moduledir="${WORK_PATH}/$module" 113 local livefile=`echo "$file" | sed -E "s:${WORK_PATH}/[^/]+::"` 114 local pathmodule=`echo "$file" | sed -E "s:${WORK_PATH}/([^/]+).*:\1:"` 115 local suffix 116 livefile=`echo "$livefile" | sed -E "s:-${pathmodule}$::"` 117 if [[ $SINGULARITIES =~ $livefile ]] ; then 118 suffix="-${module}" 119 fi 120 livefile="${livefile}${suffix}" 121 122 123 # See if it even exists 124 file="${moduledir}${livefile}" 125 if [ ! -f $file ] ; then 126 return 0 127 fi 128 129 # If we got here, figure it out 130 local owner=`conf_get_prop ${file} owner` 131 local group=`conf_get_prop ${file} group` 132 local mode=`conf_get_prop ${file} mode` 133 local opts="-Sp -o $owner -g $group -m $mode" 134 local cmd="sudo install $opts $file ${LIVE_ROOT}$livefile" 135 136 chmod o+rx ${WORK_PATH} 137 echo $cmd 138 $cmd 139 chmod o-rx ${WORK_PATH} 140 141 if [ ! -z $1 ] ; then 142 conf_install $module $* 143 fi 143 144 } 144 145 145 146 146 147 function conf_list { 147 local file=$1148 local module=`echo ${file#$WORK_PATH} | sed -E 's:/([^/]+)/.*:\1:'`149 local livefile=`echo ${file#$WORK_PATH} | sed -E 's:/([^/]+)/:/:'`150 local owner=`conf_get_prop ${file} owner`151 local group=`conf_get_prop ${file} group`152 local mode=`conf_get_prop ${file} mode`153 local comment=`conf_get_prop ${file} comment`154 echo -e "$mode\t$owner\t$group\t$comment\t\t$livefile"155 } 156 148 local file=$1 149 local module=`echo ${file#$WORK_PATH} | sed -E 's:/([^/]+)/.*:\1:'` 150 local livefile=`echo ${file#$WORK_PATH} | sed -E 's:/([^/]+)/:/:'` 151 local owner=`conf_get_prop ${file} owner` 152 local group=`conf_get_prop ${file} group` 153 local mode=`conf_get_prop ${file} mode` 154 local comment=`conf_get_prop ${file} comment` 155 echo -e "$mode\t$owner\t$group\t$comment\t\t$livefile" 156 } 157 157 158 158 159 159 160 # This function assembles the singularities: 160 161 function conf_assemble_sing { 161 local file=$1162 local livefile="${LIVE_ROOT}${file}"163 local tmpfile=`mktemp -t confman` || exit 1164 local owner group mode flag livepart msg165 for layer in $LAYERS ; do166 livepart="${LIVE_ROOT}${file}-${layer}"167 myfile="${WORK_PATH}/${layer}/${file}-${layer}"168 if [ -f $myfile -a -f $livepart ] ; then169 owner=`conf_get_prop ${myfile} owner`170 group=`conf_get_prop ${myfile} group`171 mode=`conf_get_prop${myfile} mode`172 comment=`conf_get_prop${myfile} comment`173 cat $livepart >> $tmpfile174 sudo rm $livepart175 flag=1176 fi177 done178 if [ ! -z $flag ] ; then179 local opts="-o $owner -g $group -m $mode"162 local file=$1 163 local livefile="${LIVE_ROOT}${file}" 164 local tmpfile=`mktemp -t confman` || exit 1 165 local owner group mode flag livepart msg 166 for layer in $LAYERS ; do 167 livepart="${LIVE_ROOT}${file}-${layer}" 168 myfile="${WORK_PATH}/${layer}/${file}-${layer}" 169 if [ -f $myfile -a -f $livepart ] ; then 170 owner=`conf_get_prop ${myfile} owner` 171 group=`conf_get_prop ${myfile} group` 172 mode=`conf_get_prop ${myfile} mode` 173 comment=`conf_get_prop ${myfile} comment` 174 cat $livepart >> $tmpfile 175 sudo rm $livepart 176 flag=1 177 fi 178 done 179 if [ ! -z $flag ] ; then 180 local opts="-o $owner -g $group -m $mode" 180 181 local cmd="sudo install $opts $tmpfile $livefile" 181 echo $cmd182 $cmd183 fi184 rm -f $tmpfile182 echo $cmd 183 $cmd 184 fi 185 rm -f $tmpfile 185 186 } 186 187 … … 188 189 # eg: conf_new_checkpoint MODULE NAME 189 190 function conf_new_checkpoint { 190 local module=$1191 local checkpoint=$2192 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}"193 local revision=`svn info ${WORK_PATH} | awk '/Last Changed Rev:/ {print $4}'`194 echo $revision > $chkpath195 svn add $chkpath196 local msg="Created a checkpoint, ${checkpoint} for ${module} --`whoami`"197 svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg"191 local module=$1 192 local checkpoint=$2 193 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 194 local revision=`svn info ${WORK_PATH} | awk '/Last Changed Rev:/ {print $4}'` 195 echo $revision > $chkpath 196 svn add $chkpath 197 local msg="Created a checkpoint, ${checkpoint} for ${module} --`whoami`" 198 svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg" 198 199 } 199 200 … … 201 202 # eg: conf_rm_checkpoint MODULE NAME 202 203 function conf_rm_checkpoint { 203 local module=$1204 local checkpoint=$2205 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}"206 svn rm ${chkpath}207 local msg="Removed the checkpoint ${checkpoint} from ${module} --`whoami`"208 svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg"204 local module=$1 205 local checkpoint=$2 206 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 207 svn rm ${chkpath} 208 local msg="Removed the checkpoint ${checkpoint} from ${module} --`whoami`" 209 svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg" 209 210 } 210 211 … … 212 213 # named checkpoint. eg: conf_rollback MODULE NAME 213 214 function conf_rollback { 214 local module=$1215 local checkpoint=$2216 local clock=$3217 local modpath="${WORK_PATH}/${module}"218 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}"219 local revision220 local date=`echo $checkpoint | sed -E 's:(....)(..)(..):\1-\2-\3:'`221 222 # Named checkpoint223 if [ -f "${chkpath}" ] ; then215 local module=$1 216 local checkpoint=$2 217 local clock=$3 218 local modpath="${WORK_PATH}/${module}" 219 local chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 220 local revision 221 local date=`echo $checkpoint | sed -E 's:(....)(..)(..):\1-\2-\3:'` 222 223 # Named checkpoint 224 if [ -f "${chkpath}" ] ; then 224 225 revision=`cat $chkpath` 225 elif [ -z $clock ] ; then # Time checkpoint226 elif [ -z $clock ] ; then # Time checkpoint 226 227 revision="{${date}}" 227 else228 else 228 229 clock=`echo $clock | sed -E 's#(..)(..)#\1:\2#'` 229 230 revision="{${date}T${clock}}" 230 fi231 232 svn update --revision $revision $modpath231 fi 232 233 svn update --revision $revision $modpath 233 234 } 234 235 235 236 # This function will print the value of the specified property to STDOUT 236 237 function conf_get_prop { 237 local file=$1238 local prop=$2239 svn propget "confman:${prop}" ${file}238 local file=$1 239 local prop=$2 240 svn propget "confman:${prop}" ${file} 240 241 } 241 242 242 243 # This function will set the value of the specified property. 243 244 function conf_set_prop { 244 local file=$1245 local prop=$2246 local value=$3247 svn propset "confman:${prop}" "${value}" ${file}245 local file=$1 246 local prop=$2 247 local value=$3 248 svn propset "confman:${prop}" "${value}" ${file} 248 249 } 249 250 250 251 function conf_gen_file { 251 local module=$1252 local file=$2253 local owner=$3254 local group=$4255 local mode=$5256 local comment="$6"257 local usefile=$7258 local myfile="${WORK_PATH}/${module}${file}"259 local warning="${comment} ${CONF_WARNING}"260 local morewarn="${comment} Managed under ${module} module."261 local revision="${comment} \$Id\$"262 echo $file263 264 if [ -z $usefile ] ; then265 echo -e "${warning}\n${morewarn}\n${revision}\n" > $myfile266 elif head -n 1 ${usefile} | grep '^#!' >/dev/null ; then267 awk "{if (NR==2)268 print \"\\n${warning}\\n${morewarn}\\n${revision}\\n\"\$0;269 else print \$0 }" ${usefile} > $myfile270 else271 echo -e "${warning}\n${morewarn}\n${revision}\n" > $myfile272 cat ${usefile} >> $myfile273 fi274 275 svn add $myfile276 svn ps svn:keywords "Id" $myfile277 conf_set_prop $myfile owner $owner278 conf_set_prop $myfile group $group279 conf_set_prop $myfile mode$mode280 conf_set_prop $myfile comment "$comment"252 local module=$1 253 local file=$2 254 local owner=$3 255 local group=$4 256 local mode=$5 257 local comment="$6" 258 local usefile=$7 259 local myfile="${WORK_PATH}/${module}${file}" 260 local warning="${comment} ${CONF_WARNING}" 261 local morewarn="${comment} Managed under ${module} module." 262 local revision="${comment} \$Id\$" 263 echo $file 264 265 if [ -z $usefile ] ; then 266 echo -e "${warning}\n${morewarn}\n${revision}\n" > $myfile 267 elif head -n 1 ${usefile} | grep '^#!' >/dev/null ; then 268 awk "{if (NR==2) 269 print \"\\n${warning}\\n${morewarn}\\n${revision}\\n\"\$0; 270 else print \$0 }" ${usefile} > $myfile 271 else 272 echo -e "${warning}\n${morewarn}\n${revision}\n" > $myfile 273 cat ${usefile} >> $myfile 274 fi 275 276 svn add $myfile 277 svn ps svn:keywords "Id" $myfile 278 conf_set_prop $myfile owner $owner 279 conf_set_prop $myfile group $group 280 conf_set_prop $myfile mode $mode 281 conf_set_prop $myfile comment "$comment" 281 282 } 282 283 283 284 function conf_rm_file { 284 svn rm $*285 svn rm $* 285 286 } 286 287 287 288 function conf_mkdir { 288 local directory=$1289 local owner=$2290 local group=$3291 local mode=$4292 local workdir="/"293 local directories=`echo "$directory" | sed 's:/: :g'`294 local dir295 296 for dir in $directories ; do297 workdir="${workdir}/${dir}"298 if [ ! -d ${workdir} ] ; then299 echo svn mkdir ${workdir}300 svn mkdir ${workdir}301 conf_set_prop $workdir owner $owner302 conf_set_prop $workdir group $group303 conf_set_prop $workdir mode $mode304 conf_set_prop $workdir comment "dir"305 fi306 done289 local directory=$1 290 local owner=$2 291 local group=$3 292 local mode=$4 293 local workdir="/" 294 local directories=`echo "$directory" | sed 's:/: :g'` 295 local dir 296 297 for dir in $directories ; do 298 workdir="${workdir}/${dir}" 299 if [ ! -d ${workdir} ] ; then 300 echo svn mkdir ${workdir} 301 svn mkdir ${workdir} 302 conf_set_prop $workdir owner $owner 303 conf_set_prop $workdir group $group 304 conf_set_prop $workdir mode $mode 305 conf_set_prop $workdir comment "dir" 306 fi 307 done 307 308 } 308 309 309 310 function conf_rmmod { 310 local module=$1 311 svn rm ${WORK_PATH}/${module} 312 svn rm ${WORK_PATH}/${REPO_CHECKPTS}/${module} 311 local module=$1 312 svn rm ${WORK_PATH}/${module} 313 svn rm ${WORK_PATH}/${REPO_CHECKPTS}/${module} 314 } 315 316 function conf_rename { 317 local oldmod=$1 318 local newmod=$2 319 local file 320 321 # First, we perform the easy operations 322 svn mv ${WORK_PATH}/${oldmod} ${WORK_PATH}/${newmod} 323 svn mv ${WORK_PATH}/${REPO_CHECKPTS}/${oldmod} \ 324 ${WORK_PATH}/${REPO_CHECKPTS}/${newmod} 325 326 svn commit -m "Renaming ${oldmod} to ${newmod}, phase 1." \ 327 ${WORK_PATH}/{,${REPO_CHECKPTS}}/{${oldmod},${newmod}} 328 329 # Next, we have to rename any singularities 330 for file in ${SINGULARITIES} ; do 331 if [ -f "${WORK_PATH}/${newmod}${file}-${oldmod}" ] ; then 332 svn mv ${WORK_PATH}/${newmod}${file}-${oldmod} \ 333 ${WORK_PATH}/${newmod}${file}-${newmod} 334 fi 335 done 336 337 svn commit -m "Renaming ${oldmod} to ${newmod}, phase 2." \ 338 ${WORK_PATH}/${newmod} 339 340 # Now, we have to go fix all the confman headers in all the files... 341 find ${WORK_PATH}/${newmod} -type f -not -path '*/.svn/*' -exec \ 342 gsed -i -r "s/^(# Managed under )${oldmod}( module)/\1${newmod}\2/" \ 343 {} \; 344 345 svn commit -m "Renaming ${oldmod} to ${newmod}, complete." \ 346 ${WORK_PATH}/${newmod} 313 347 } 314 348 315 349 function conf_mv { 316 local oldname=$1317 local newname=$2318 svn mv $oldname $newname350 local oldname=$1 351 local newname=$2 352 svn mv $oldname $newname 319 353 } 320 354 321 355 function conf_cp { 322 local oldname=$1323 local newname=$2324 svn cp $oldname $newname356 local oldname=$1 357 local newname=$2 358 svn cp $oldname $newname 325 359 } 326 360 327 361 function conf_diff { 328 svn diff $*362 svn diff $* 329 363 } 330 364 331 365 function conf_log { 332 svn log $*366 svn log $* 333 367 } 334 368 335 369 function conf_cleanexit { 336 echo "Abort, Abort! Patience is a virtue." >&2337 rm -f /tmp/confman*338 339 # And in case we got an interrupt during a rollout, we still want the340 # permissions here to be in a consistent state.341 chmod 700 ${WORK_PATH}342 343 # And this clears any locks we may have created on our working copy:344 svn cleanup ${WORK_PATH}345 echo "All clean. Terminating." >&2346 347 if [ -z $1 ] ; then348 exit 1349 else370 echo "Abort, Abort! Patience is a virtue." >&2 371 rm -f /tmp/confman* 372 373 # And in case we got an interrupt during a rollout, we still want the 374 # permissions here to be in a consistent state. 375 chmod 700 ${WORK_PATH} 376 377 # And this clears any locks we may have created on our working copy: 378 svn cleanup ${WORK_PATH} 379 echo "All clean. Terminating." >&2 380 381 if [ -z $1 ] ; then 382 exit 1 383 else 350 384 exit $1 351 fi 352 353 } 354 385 fi 386 387 } 388 389 # vim:ts=4 390
Note: See TracChangeset
for help on using the changeset viewer.
