Version Control System VCS Unix Shell Script Rmit Uevcs
-
Upload
lanka-bogoda -
Category
Documents
-
view
232 -
download
0
Transcript of Version Control System VCS Unix Shell Script Rmit Uevcs
-
8/6/2019 Version Control System VCS Unix Shell Script Rmit Uevcs
1/3
#!/bin/sh# Name : Lanka Bogoda# Std No : S3224908# This shell script is written by Lanka Bogoda as an assignment for Unix for system adminstrators in the# Computing and Information Systems Engineering school of RMIT University.The script intend for version control system.# the syntex for the command is "./uevcs [command] [flags] " and it is elaborated at the end of this# script as a response to help argument at the command line.# Date created 04-05-2010# PRINTF=/usr/bin/printf## Important : This script was initially written on Fedora 9 and later changed the codes to meet Yallara (Solaris) requirement.
# This was as a ressults of slow response time with Yallara and I observed that this is not a good way of writing scripts.# It is required to refine the script furthermore to obtain the expected resuts of the assignment.##-------------------------------------------Begining of the script--------------------------------------## if the no of arguments are less than 2 exit and show the usageif [ $# -lt 2 ]; then
echo "Usage: basename $0`Command flag filename" >&2exit 1ficase $1 in
add) # A new rivision control log file is added to the repository --"if [ $# -lt 3 ] && [ "$flag" = "-r" ] || [ "$flag" = "-vr" ] || [ "$flag" = "-rv" ] || [ "$flag" = "-v" ]# if the no of arguments are less than 3 and files names are not passed at the command line show the usagethen
echo "Usage: basename $0`Command flag filename" >&2elif [ "$flag" = "-r" ] || [ "$flag" = "-vr" ] || [ "$flag" = "-rv" ] || [ "$flag" = "-v" ]# if the flags are passed at the command line go to add function#then file_name=$3
flag=$2two=2 #leave first 2 arguments for recursive operationNo_of_args=$# No_of_files= expr $No_of_args - $two` #no of files to be added to repository#
#test the presence of .uevcs directory[ -d .uevcs ]#if .uevcs is not present make it[ $? != 0 ] && mkdir .uevcscd .uevcsMYDATE=`date +%F" "%T ` # formatting date to 2011-04-24 17:56:11set -x#------------addition of multiple directories and files recursively ----------------------- -if [ "$flag" = "-r" ] || [ "$flag" = "-vr" ] || [ "$flag" = "-rv" ]# check all possibilties of -r flag
thenuntil [ $No_of_files -eq 0 ] # runs until all the filenames becomes 0do
mkdir $file_namem
cd $file_nameecho "- $MYDATE Lanka Bogoda - " > History.logtouch $file_nameecho "-- $file_name is added to repository on $MYDATE --" >> History.logecho "-- A new file $file_name and a history.log file added to the repository --"e
$No_of_files= expr $No_of_args - 1`shift # shift one position back to predecerssor variable to read the next file namedoned
else#-------------addition of a single file ------------------------------------
touch $file_nameecho "- $MYDATE Lanka Bogoda - " > History.log # Heading of the newly added fileecho "-- $file_name is added to repository on $MYDATE --" >> History.logecho "-- A new file $file_name and a history.log file added to the repository --"
fif
else# if the flags are not passed at the command line go to add a single file function
file_name=$2touch $file_nameecho "- $MYDATE Lanka Bogoda - " > History.log # Heading of the newly added fileecho "-- $file_name is added to repository on $MYDATE --" >> History.logecho "-- A new file $file_name and a history.log file added to the repository --"e
fi;;;
get)file_name=$3cd .uevcspatch -p1 $file_name diff.logecho "-- $file_name has been pacthed with diff file --/n"
;;;
delete)
-
8/6/2019 Version Control System VCS Unix Shell Script Rmit Uevcs
2/3
file_name=$3cd .uevcsMYDATE=`date +%F" "%T ` # formatting date to 2011-04-24 17:56:11find $file_name | xargs tar -cvf $file_name$(date +%d-%m-%Y).tar | xargs rmecho "- $MYDATE Lanka Bogoda - " > History.log # Heading of the newly added fileecho "-- $file_name is deleted from the repository on $MYDATE --" >> History.logfind -name '*.tar' -mtime -30 -ok rm # giving an option to delete old file after 30 daysecho "-- new file $file_name is no longerand a history.log file added to the repository --"
;;;
update) echo "-- update files to the repository --"
file_name=$3ffile_name2=$4#test the presence of .uevcs directory[ -d .uevcs ]# go to .uevcs directorycd .uevcsMYDATE=`date +%F" "%T `#-------read user information -----------------echo "$MYDATE Lanka Bogoda "echo "Please enter the following details:"echo "\n "echo "First Name: "read fnameecho "\n "echo "Last Name : "read lnameecho "\n "echo "Email : "read email
echo "------- $MYDATE ----------" >> History.logecho "reviewed by: $fname $lname " >> History.log;diff $file_name $file_name2 > diff.log # difference of files are stored in diff.log
echo "Enter bug description (when finished type ctrl-D):\n "echo "Bug description:" >> History.logcat >> History.logcat >> History.logecho "\n" >> History.logecho "--------------------------------------" >> History.logecho "Enter fix description (when finished type ctrl-D):\n "echo "fix for the bug:" >> History.logcat >> History.logecho "\n" >> History.logecho "\n" >> History.log(
echo "\n"echo "Editing history as of $MYDATE in the database:\n\n"cat History.log
))
;;;
move)file_name=$3ffile_name2=$4
cd .uevcscp $file_name $file_name2 # copy or move file from one location to otherecho "-- $file_name has been moved to $file_name2 --"e
;;;
show)cd .uevcscat < History.log | more # show history.log file page by pagecd ..
;;
help)
echo "./uevcs (1) User Commands\n\n"e
echo "NAME \n\n"\
echo " uevcs - ue Versions System \n\n"e
echo "SYNOPSIS \n"echo "echo uecvs [ command ] [ flags ] [ command_args ] \n\n"e
echo "NOTE \n"echo " This manpage is a summary of some of the features of uecvs.\n\n"e
echo "Structure \n"echo " Overall structure of uevcs commands\n\n"
echo " ./uevcs [command] [flags] \n\n"
-
8/6/2019 Version Control System VCS Unix Shell Script Rmit Uevcs
3/3
e
echo " uecvs\n\n"e
echo " The name of the uecvs program.\n\n"e
echo " command\n\n"e
echo " add - add new files to the repository.\n"echo " get - get files from the repository.\n"echo " delete - delete files from the repository.\n"echo " update - update current files to the repository.\n"
echo " move - move or rename a file to another directory.\n"echo " show - show the change history for file.\n"echo " help - show a help screen.\n\n"h
echo " flag\n\n"f
echo " -v - verbose\n"echo " -r - recursive\n"
echo " command_args\n"echo " Fi le or mult iple fi les"
;;;
*) echo " `basename $0`: This is not valid command" >&2exit 1;;
esaceeee