class="22224">
--------------------------------------------------------------------------------
4.;Shell;Scripts;
下面的;scripts;是基本;CVS;命令的集合,而且是;Korn;shell;的;scripts;。你可以把他轉成;perl;或者;bash。你可以自己修改成你想要的樣子。這些只是運用基本;CVS;命令但有些特殊的花樣加在裡面。例如,;sedit;這個;script;提供了檔案鎖住的功能使得其他人知道有某人正在修改這個檔案,當然你也可以直接使用;CVS;命令而不用這些;scripts;,這些;scripts;只是在展示;CVS;是多麽的有彈性。;
把這些;scripts;復制到;/usr/local/bin;下,並且此目錄應該在你的;PATH;環境變數中。;
sget;[-r;revision_number];
要從;CVS;獲得一個唯讀檔案或整個唯讀目錄,請按;sget;
sedit;[-r;revision_number];要修改一個一個程式碼時,這個;scripts;會做檔案鎖住的動作,因此沒有別人可以登出這個檔案了。當然你可以改變這個;script;成你想要的功能;-;例如不鎖住,只出現警告訊息,或者相反的,非常嚴謹的鎖檔案。請按;sedit;
scommit;[-r;revision_number];要交出某個你修改的檔案或整個目錄。;把你的改變交給;CVS。請按;scommit;
supdate;要藉由從;CVS;得到最新的檔案來update;一個檔案或整個目錄。請按;supdate;
sunlock;[-r;revision_number];要把因為用;sedit;後的檔案鎖關掉。這會釋放檔案鎖(Release;File;Lock)。請按;sunlock;
slist;要看目前正被你修改的檔案列表。做;'ls;-l;|;grep;|;...';命令,請按;slist;
sinfo;要得到一個檔案的改版資訊。;請按;sinfo;
slog;要得到一個;CVS;檔案改版的歷史紀錄,請按;slog;
sdif;
sdif;-r;rev1;-r;rev2;要得到你的檔案與;CVS;櫃子裡的檔案不同的地方在哪裡。請按;sdif;
注意:;sdif;只有一個;'f';,因為這裡已經有一個;unix;命令叫;'sdiff'。;
sadd;要新增一個檔案到;CVS;櫃子裡。請按;sadd;
sdelete;要從;CVS;櫃子裡清掉一個檔案。請按;sdelete;
sfreeze;要凍結原始碼;(freeze;codes);,這是將要發行;(release);整個原始碼目錄樹。請按;sfreeze;
saddtree;要新增一個目錄樹到;CVS;。請按;saddtree;
例如;:;
--------------------------------------------------------------------------------
cd;$HOME;;
sfreeze;REVISION_1_0;;srctree
--------------------------------------------------------------------------------
這將會凍結原始碼,並貼上一個標簽;REVISION_1_0;,如此一來你就可以稍後用版本名字登出整個目錄樹。;
******************************************************
4.1;sget;
注意;:;Korn;shell;/bin/ksh;在你從Linux;CD-ROM;安裝;pdksh*.rpm;時就會產生;
請把他存成一般文字檔並改變存取權限;chmod;a+rx;
--------------------------------------------------------------------------------
#!/bin/ksh
#;CVS;program;sget
#;Program;to;check;out;the;file;from;CVS;read-only
cmdname=`basename;$0`
Usage()
{
print;"nUsage:;$cmdname;[-r;revision_number/symbolic_tag_name];"
print;"The;options;-r;are;optional;"
print;"For;example;-;"
print;";$cmdname;-r;1.1;foo.cpp"
print;";$cmdname;foo.cpp;"
print;";$cmdname;some_directory;"
print;"Extract;by;symbolic;revision;tag;like;-;"
print;";$cmdname;-r;REVISION_1;some_directory;"
print;";"
exit
}
#;Command;getopt;will;not;supported;in;next;major;release.;
#;Use;getopts;instead.;
while;getopts;r:;ii
do
case;$ii;in
r);FLAG1=$ii;;OARG1="$OPTARG"
?);Usage;;exit;2
esac
done
shift;`;expr;$OPTIND;-;1;`
#echo;FLAG1;=;$FLAG1;,;OARG1;=;$OARG1
if;[;$#;-lt;1;];;then
Usage
fi
bkextn=sget_bak
hme=`;echo;$HOME;|;cut;-f1;-d';';;`
if;[;"$hme";=;"";];;then
print;"nError:;$HOME;is;not;set!!n"
exit
fi
#;Check;if;file;already;exists....
if;[;-f;$1;];;then
user_perms=";"
group_perms=";"
other_perms=";"
user_perms=`ls;-l;$1;|;awk;'{print;$1;}';|;cut;-b3-3;`
group_perms=`ls;-l;$1;|;awk;'{print;$1;}';|;cut;-b6-6;`
other_perms=`ls;-l;$1;|;awk;'{print;$1;}';|;cut;-b9-9;`
if;[;"$user_perms";=;"w";-o;"$group_perms";=;"w"
-o;"$other_perms";=;"w";];;then
print;"nError:;The;file;is;writable.;Aborting;$cmdname;......"
print;";;;;;;;You;should;either;backup,;scommit;or;delete;the;file;and"
print;";;;;;;;try;$cmdname;againn"
exit
fi
fi
cur_dir=`pwd`
#echo;$cur_dir
len=${#hme}
len=$(($len;+;2))
#echo;$len
subdir=`;echo;$cur_dir;|;cut;-b;$len-2000;`
#echo;$subdir
if;[;"$subdir";=;"";];;then
fdname=$1
else
fdname=$subdir"/"$1
fi
#;Move;the;file
touch;$1;2>/dev/null
mv;-f;$1;$1.$bkextn
#;Create;subshell
(
cd;$hme
#echo;$fdname
#;Use;-A;option;to;clear;all;sticky;flags
if;[;"$FLAG1";=;"";];;then
cvs;-r;checkout;-A;$fdname
else
cvs;-r;checkout;-A;-$FLAG1;$OARG1;$fdname
fi
)
#pwd
if;[;-f;$1;];;then
print;"nREAD-ONLY;copy;of;the;file;$fdname;obtained."
print;"Done;$cmdname"
#print;"nTip;(Usage):;$cmdname;n"
fi
--------------------------------------------------------------------------------
4.2;sedit;
注意;:;Korn;shell;/bin/ksh;在你從Linux;CD-ROM;安裝;pdksh*.rpm;時就會產生;
請把他存成一般文字檔並改變存取權限;chmod;a+rx;
--------------------------------------------------------------------------------
#!/bin/ksh
#;CVS;program;sedit
#;Program;to;check;out;the;file;from;CVS;read/write;mode;with;locking
cmdname=`basename;$0`
Usage()
{
#;;;;;;;print;"nUsage:;$cmdname;[-r;revision_number];[-F];"
#;;;;;;;print;"The;options;-r,;-F;are;optional;"
#;;;;;;;print;"The;option;-F;is;FORCE;edit;even;if;file;is;"
#;;;;;;;print;"locked;by;another;developer"
print;"nUsage:;$cmdname;[-r;revision_number];"
print;"The;options;-r;are;optional;"
print;"For;example;-;"
print;";$cmdname;-r;1.1;foo.cpp"
print;";$cmdname;foo.cpp;"
#;;;;;;;print;";$cmdname;-F;foo.cpp;"
print;";"
}
#;Command;getopt;will;not;supported;in;next;major;release.;
#;Use;getopts;instead.;
#while;getopts;r:F;ii
while;getopts;r:;ii
do
case;$ii;in
r);FLAG1=$ii;;OARG1="$OPTARG"
#;;;;;;;F);FLAG2=$ii;;OARG2="$OPTARG"
?);Usage;;exit;2
esac
done
shift;`;expr;$OPTIND;-;1;`
#echo;FLAG1;=;$FLAG1;,;OARG1;=;$OARG1
if;[;$#;-lt;1;];;then
Usage
exit
fi
hme=`;echo;$HOME;|;cut;-f1;-d';';;`
if;[;"$hme";=;"";];;then
print;"nError:;$HOME;is;not;set!!n"
exit
fi
bkextn=sedit_bak
cur_dir=`pwd`
#echo;$cur_dir
len=${#hme}
len=$(($len;+;2))
#echo;$len
subdir=`;echo;$cur_dir;|;cut;-b;$len-2000;`
#echo;$subdir
if;[;"$subdir";=;"";];;then
fdname=$1
else
fdname=$subdir"/"$1
fi
#;If;file;is;already;checked;out;by;another;developer....
cvs_root=`;echo;$CVSROOT;|;cut;-f1;-d';';;`
if;[;"$cvs_root";=;"";];;then
print;"nError:;$CVSROOT;is;not;set!!n"
exit
fi
cldir=$CVSROOT/$subdir/Locks
mkdir;$cldir;2>/dev/null
rcsfile=$CVSROOT/$subdir/$1,v
#echo;$rcsfile
if;[;!;-e;$rcsfile;];;then
print;"nError:;File;$1;does;not;exist;in;CVS;repository!!n"
exit
fi
#;Get;the;tip;revision;number;of;the;file....
#;Use;tmpfile;as;the;arg;cannot;be;set;inside;the;sub-shell
tmpfile=$hme/sedit-lock.tmp
rm;-f;$tmpfile;2>/dev/null
if;[;"$FLAG1";=;"";];;then
(
cd;$hme
cvs;log;$fdname;|;head;-6;|;grep;head:;|;awk;'{print;$2}';>;$tmpfile;
)
OARG1=`cat;$tmpfile`
rm;-f;$tmpfile;2>/dev/null
fi
lockfile=$cldir/$1-$OARG1
#if;[;-e;$lockfile;-a;"$FLAG2";=;"";];;then
if;[;-e;$lockfile;];;then
print;"nError:;File;$1;Revision;$OARG1;