#!/bin/bash # Copyright (C) 2004 by Nathan (Acorn) Pooley # # do_bak # #@DOC@ script for backing up all gadget related files # # # names and directories # basename=ju_gadget dst_top=~acorn/Projects/ju_gadget_bak src_top=~acorn/Projects/ju_gadget2 if [[ ! -d $src_top ]] ; then echo "Could not find top source dir: $src_top" echo "Aborting" exit 1 fi cd "$src_top" got_warn=0 # # source subdirs # unset src_list src_list[0]="." # # source files from top dir # unset top_src_list top_src_cnt=0 _add_topfile() { file="$*" if [[ $file != /* && $file != ./* ]] ; then file="./$file" fi if [[ -f $file ]] ; then found=0 for i in "${top_src_list[@]}" do if [[ $i = $file ]] ; then found=1 break fi done if (( found == 0 )) ; then top_src_list[$top_src_cnt]="$file" (( top_src_cnt = top_src_cnt + 1 )) fi else echo "WARNING: File '$file' not found" got_warn=1 fi } # # files at top level to include # for i in [Mm]akef* *.asm *.inc *.txt *.stxt *.str *.sstr *.html do_* gg *.c *.mcp *.mcw *.Fsti *.Psti do _add_topfile "$i" done # # locate source dirs # for i in "${src_list[@]}" do src="$i" if [[ ! -d $src ]] ; then echo "Could not find directory '$src'" echo "Aborting" exit 1 fi done # # parse date # dt=`date | sed -n -e 's|[^ ]* \([a-zA-Z]\{3\}\) *\([0-9]\{1,2\}\) [^ ]* \+\([0-9]\{4\}\).*|\3_\1_\2|p'` dt=`echo "$dt" | sed \ -e 's|_\([0-9]\)$|_0\1|' \ -e 's|Jan|01&|' \ -e 's|Feb|02&|' \ -e 's|Mar|03&|' \ -e 's|Apr|04&|' \ -e 's|May|05&|' \ -e 's|Jun|06&|' \ -e 's|Jul|07&|' \ -e 's|Aug|08&|' \ -e 's|Sep|09&|' \ -e 's|Oct|10&|' \ -e 's|Nov|11&|' \ -e 's|Dec|12&|'` if [[ -z $dt || $dt = *' '* ]] ; then echo "Could not parse date '`date`' ===> '$dt'" echo "Aborting" exit 1 fi # # find unused destination directory # dst_main="$dst_top/${basename}_${dt}_" dst_dir="" old_num="`\ls -d ${dst_main}* | \ tail -1 | \ sed -n -e 's|.*_\([0-9]\{3\}\)$|\1|p'`" cnt=0 if [[ -n $old_num ]] ; then (( cnt = old_num - 1 )) if (( cnt < 0 )) ; then cnt=0 fi fi while (( 1 )) do (( cnt = cnt + 1 )) if (( cnt > 99 )) ; then echo "Could not find unused dest dir with name " echo " '$dst_main'" echo "Aborting" exit 1 fi if (( cnt < 10 )) ; then dst_dir="${dst_main}00${cnt}" elif (( cnt < 100 )) ; then dst_dir="${dst_main}0${cnt}" else dst_dir="${dst_main}${cnt}" fi if [[ -a $dst_dir ]] ; then echo "EXISTS: $dst_dir" else break fi done ver_name="${dst_dir#${dst_top}/}" echo "USING: $dst_dir" if [[ -z $dst_dir || -a $dst_dir ]] ; then echo "$dst_dir EXISTS!" echo "Aborting" exit 1 fi mkdir -p "$dst_dir" if [[ ! -d $dst_dir ]] ; then echo "Could not create dir $dst_dir" echo "Aborting" exit 1 fi #### #### copy list of files #### $1 is dest dir #### stdin is file list #### ###_do_copy() ###{ ### while read fn ### do ### if [[ ! -a $fn ]] ; then ### echo "$fn does not exist" ### else ### if [[ -d $fn ]] ; then ### echo "$fn is a directory - skipping" ### else ### dd="${fn%/*}" ### if [[ -n $dd && $dd != $fn ]] ; then ### echo "Creating dir '$1/$dd'" ### mkdir -p "$1/$dd" ### fi ### cp -v -i "$fn" "$1" ### fi ### fi ### done ###} ### _get_msg() { while read line do if [[ $line = [tT][aA][gG]* ]] ; then echo "$line" > "$dst_dir/TAG" fi if [[ $line = '.' ]] ; then break fi echo "$line" done } # # get message # echo "Enter message (end with single . on line):" echo "To add a tag include a line: (<tag_name> should be alpha-numeric and _)" echo "tag <tag_name>" _get_msg > "$dst_dir/README" if [[ ! -s $dst_dir/README ]] ; then echo "ERROR:" echo "ERROR:" echo "ERROR: no message received!" echo "ERROR:" echo "ERROR:" fi # # create tag if requested # if [[ -f $dst_dir/TAG ]] ; then read tagtag tagname junk < $dst_dir/TAG if [[ -z $tagname ]] ; then echo "ERROR:" echo "ERROR:" echo "ERROR: tagname error - no tag created" echo "ERROR:" echo "ERROR:" else tagfile="$dst_top/Tag_${ver_name}_is_${tagname}" echo "Creating tag '$tagfile'" cp "$dst_dir/README" "$tagfile" fi fi # # create dirs & file list # fl="$dst_dir/backup_file_list_2" touch "$fl" echo "Creating file list $fl" for i in "${top_src_list[@]}" do if [[ -a $i ]] ; then echo "$i" >> "$fl" else echo "$i does not exist!" fi done for i in "${src_list[@]}" do find "$i" -name '*.asm' >> "$fl" find "$i" -name '*.inc' >> "$fl" find "$i" -name '*.txt' >> "$fl" find "$i" -name '*.c' >> "$fl" find "$i" -name '*.h' >> "$fl" find "$i" -name '*.cpp' >> "$fl" find "$i" -name '*.s' >> "$fl" find "$i" -name '*.S' >> "$fl" find "$i" -name '*.vsm' >> "$fl" find "$i" -name '*.dsp' >> "$fl" find "$i" -name 'make*' >> "$fl" find "$i" -name 'Make*' >> "$fl" done sort -u < "$fl" > "${fl}_tmp" mv "${fl}_tmp" "$fl" fl2="$fl" fl="${fl%_2}" grep -v '\<Makedepend_' "$fl2" > "$fl" \rm -f "$fl2" echo "Files in list: `cat $fl | wc -l`" tarfile="$dst_dir/ju_gadget_bak.tgz" echo "Creating tar file $tarfile" tar czf "$tarfile" -T "$fl" echo "Done" |
This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to DRUID Development page
Go to DRUID page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 18:14:15 2004