| Ithaca Free Software GNU Linux http://ithacafreesoftware.org/forum/ |
|
| Shell script: Mimic Dreamweaver's check-in and check-out http://ithacafreesoftware.org/forum/viewtopic.php?f=7&t=63 |
Page 1 of 1 |
| Author: | mitch [ Tue Sep 05, 2006 4:39 pm ] |
| Post subject: | Shell script: Mimic Dreamweaver's check-in and check-out |
Here is a collection of shell scripts that I use to work with my co-workers who still use Dreamweaver. These scripts allow me to check in, check out, get, and put files in Dreamweaver fashion, as well as some handy scripts to view all files that have been checked out, and by whom. The scripts transfer files by way of rsync and sftp. For these scripts to work, you must have Public Key authentication set up between your workstation and your Web server. Details on how to do this can be found here, or by searching the Web for "ssh authorized_keys". Some simple instructions are given in the comments of the main configuration script below. Alternatively, you can substitute plain old "ftp" for "sftp" if your server has regular ftp running. You would then need to modify the scripts to send your username and password over the network in clear text (not recommended). |
|
| Author: | mitch [ Thu Nov 09, 2006 11:12 am ] |
| Post subject: | Common configuration file: dw_conf.sh |
Here's the common configuration file, dw_conf.sh Code: # this file is intended to be included in various other scripts used
# for moving files between localhost and a web server # For these scripts to function, you must generate an ssh key on the client # with the "ssh-keygen -t rsa" command, which will create a file in # ~/.ssh/id_rsa.pub # The contents of that file need to be appended to a ~/.ssh/authorized_keys file # on the server. Change the username in the appended key if the local and # remote user names are different. editor="vi" xfercmd="/usr/bin/rsync -lqr" local_web_root="/home/mitch/" local_working_dir=$PWD #echo local_working_dir: $local_working_dir; #strip off the local_web_root from the pwd to determine which site we're working in. temp_dir1=${local_working_dir/$local_web_root/} #echo temp_dir1: $temp_dir1; #extract the site (the next dir name) # this is a hack. if the $temp_dir1 has a slash and another dir name at the end, # strip them off and use the result as the site. Otherwise just use $temp_dir1 temp_site=`expr index "$temp_dir1" /` #echo temp_site: $temp_site; if [ $temp_site -gt 0 ] then site=${temp_dir1:0:$temp_site-1} else site=$temp_dir1; fi # set the local base directory to which the working directory will be relative local_base_dir=$local_web_root$site case $site in www.myweb.com) server="www.myweb.com" username="web" remote_base_dir="/home/web" local_working_dir=$PWD working_dir=${local_working_dir/$local_base_dir/} file=$1 lock_file="$file.LCK" lock_file_content="Webmaster (web)||webmaster@myweb.com" ;; www.anotherweb.com) server="www.anotherweb.com" username="bob" remote_base_dir="/home/bob/www.anotherweb.com" local_working_dir=$PWD working_dir=${local_working_dir/$local_base_dir/} file=$1 lock_file="$file.LCK" lock_file_content="Bob (bob)||bob@anotherweb.com" ;; *) echo "Unable to determine site parameters."; ;; esac |
|
| Author: | mitch [ Thu Nov 09, 2006 11:17 am ] |
| Post subject: | The "checkout" script |
This is the "checkout" script: Code: #!/bin/bash
# This script will create Macromedia Dreamweaver formatted "lock" files for any filenames passed in. # These .LCK files can then be transferred to the web server to show other DW users that you've checked # the files out. source ~/system/scripts/dw_conf.sh if [ -n $site ] # if we have valid site parameters then # check to see if the file has been locked (checked-out) by anyone else echo "Checking for an existing lock file..."; $xfercmd $username@$server:$remote_base_dir$working_dir/$lock_file . if [ -f "$lock_file" ] then temp=`cat $lock_file`; if [ "$temp" = "$lock_file_content" ] then echo "You already have this file checked-out!"; else echo "The file has been checked out by: $temp"; # remove the local lock file rm -f $lock_file; fi else # get the file only if it is not currently checked-out. $xfercmd $username@$server:$remote_base_dir$working_dir/$file . # create the local lock file. if [ -e "$lock_file" ] # see if the .LCK file exists then temp=`cat $lock_file`; echo "$lock_file exists: $temp"; else if [ -f "$file" ] then echo $lock_file_content > $lock_file; fi fi # put the lock file on the server. $xfercmd ./$lock_file $username@$server:$remote_base_dir$working_dir/ echo "$file has been checked-out successfully."; # open the file in an editor $editor $file fi else echo "no actions taken"; fi exit 0 |
|
| Author: | mitch [ Thu Nov 09, 2006 11:18 am ] |
| Post subject: | The "checkin" script |
Here's the "checkin" script: Code: #!/bin/bash
# This script will transfer a file from the localhost to a remote ftp server # and delete any related .LCK file. It is meant to be used in conjunction with # the dw_checkout.sh file source ~/system/scripts/dw_conf.sh if [ -n $site ] # if we have valid site parameters then # check for a local lock file if one is not found, then don't allow the check-in if [ -f "$lock_file" ] # see if the .LCK file exists then #remove the local lock file rm -f $lock_file sftp -b /dev/stdin $username@$server <<END_SCRIPT cd $remote_base_dir$working_dir put $file rm $lock_file quit END_SCRIPT echo "$file was checked in successfully."; else echo "$lock_file was not found. You don't seem to have this file checked out."; echo "The file was not checked in, as this could overwrite someone else's work."; fi else echo "no actions taken"; fi exit 0 |
|
| Author: | mitch [ Thu Nov 09, 2006 11:21 am ] |
| Post subject: | The "get" script |
Here is a useful "get" script that allows you to retrieve one or more files, in a recursive manner. usage examples: Code: $get myfile.php $get all (retrieves all updated files in all subdirectories) $get all delete (retrieves all files, and deletes local files not on the server) Here's the script: Code: #!/bin/bash
# get file(s) from the remote server source ~/system/scripts/dw_conf.sh if [ -n $site ] # if we have valid site parameters then if [ "$file" = "all" ] then $file = ""; if [ "$2" = "delete" ] then $xfercmd --delete $username@$server:$remote_base_dir$working_dir/ . else $xfercmd $username@$server:$remote_base_dir$working_dir/ . fi else $xfercmd $username@$server:$remote_base_dir$working_dir/$file . # $editor $file fi else echo "no actions taken"; fi exit 0 |
|
| Author: | mitch [ Thu Nov 09, 2006 11:34 am ] |
| Post subject: | The "put" script |
Here's the "put" script: Code: #!/bin/bash
# transfer a local file to a remote ftp server source ~/system/scripts/dw_conf.sh if [ -n $site ] # if we have valid site parameters then # don't allow the file to be "put" if it isn't checked out # (if the lock_file contents don't match lock_file_content) if [ -f "$lock_file" ] then temp=`cat $lock_file`; if [ "$temp" = "$lock_file_content" ] then $xfercmd ./$file $username@$server:$remote_base_dir$working_dir/ else echo "You don't have $file checked-out! You can't upload it!"; fi else echo "You don't have $file checked-out! You can't upload it!"; fi else echo "no actions taken"; fi exit 0 |
|
| Author: | mitch [ Thu Nov 09, 2006 11:40 am ] |
| Post subject: | A script to find all checked-out files |
This script is intended to be run on the Web server. It scans through your Web root directory recursively and looks for Dreamweaver's lock (*.LCK) files. The output is a report of who has which files checked out. Code: #!/bin/bash
# dw_checkout_report.sh # where do we want to look for files? webRoot=/home/web # search through all of the .LCK files and # create a list of email addresses contained in them # then, sort the list and remove any duplicates emailAddrList=$(find $webRoot -name '*.LCK' \ -exec grep -o '[0-9a-zA-Z]*\@[0-9a-zA-Z\.]*\.[a-zA-Z]*' {} \; | \ sort | uniq); # main loop for email in $emailAddrList do # for each e-mail address, get a list of .LCK files # that person is responsible for. # then use sed to indent the lines and remove extraneous info filelist=$(grep -H $email $(find $webRoot -name "*.LCK") | \ sed 's/^/ /; s/.LCK:.*$//'); echo "$email"; echo "$filelist"; done |
|
| Author: | mitch [ Thu Nov 09, 2006 11:47 am ] |
| Post subject: | A script to notify Dreamweaver users of checked-out files |
This script is intended to be scheduled to run on the Web server to periodically let Dreamweaver users know which files they have checked out. I set up my server to run the script every weekday morning by creating a directory (/etc/cron.weekdays) with a symlink to the 'notify' script. Adding this entry to my /etc/crontab makes the script execute every weekday morning at 4:52 AM: Code: 52 4 * * 1-5 root run-parts /etc/cron.weekdays Here's the script: Code: #!/bin/bash
# where do we want to look for files? webRoot=/home/web # search through all of the .LCK files and # create a list of email addresses contained in them # then, sort the list and remove any duplicates emailAddrList=$(find $webRoot -name '*.LCK' \ -exec grep -o '[0-9a-zA-Z]*\@[0-9a-zA-Z\.]*\.[a-zA-Z]*' {} \; | \ sort | uniq); # main loop for email in $emailAddrList do # for each e-mail address, get a list of .LCK files # that person is responsible for. # then use sed to indent the lines and remove extraneous info filelist=$(grep -H $email $(find $webRoot -name "*.LCK") | \ sed 's/^/ /; s/.LCK:.*$//'); # send the user a message: mail -s "Dreamweaver file status report" $email << END_MAIL Dear Gentle Dreamweaver User (a.k.a $email), It seems that you have the following files checked out on the www.example.com server: $filelist If you're not actively using these files, please check them back in so that others may work on them. This automated message will be sent out each weekday morning to anyone who has files checked out. If you don't want to commit your changes to any of the files listed, use Dreamweaver's "undo check out" function for those files. Thank you. END_MAIL done |
|
| Page 1 of 1 | All times are UTC - 4 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|