#!/bin/bash # bash version of desired functionality for drush - see http://drupal.org/node/434944 # autor: Vladimir Radulovski (rsvelko) - http://segments.at # version 1.0 # - fixed current version detection projects=$@ # drupal, cck, zen ... # if in a Drupal dir if [[ -d ./sites/all/modules ]] then : else echo "not in drupal dir. Exiting..."; exit fi if [[ -z $projects ]] then projects="drupal" fi ############# Requirements # This script requires that you have drush/link to drush in your $PATH if [[ -z `which drush` ]] then echo "drush not found in PATH! Exiting..."; exit 2 fi ############ funcs function __dru_rm_from_both_core_dirs { echo rm -dr $orig/$1 $new/$1 && echo "OK: Done a : rm -dr $orig/$1 $new/$1" } function __dru_cp_from_curr_to_both_core_dirs { echo for dest in $orig $new do for src in "$@" do if [[ -e "$curr/$src" ]] # -e checks for both files and dirs then cp -pr "$curr/$src" "$dest/" && echo "OK: Done a: cp -pr '$curr/$src' '$dest/'" fi done done echo " OK: So, now the current core is ready for diffing and the latest core is almost ready to go live." } function __dru_get_the_latest_stable_project_version { drush info $proj | grep "$proj" | awk '{print $2}' | grep -v "\-rc" | grep -v "\-alpha" | grep -v "\-beta" | grep -v "\-dev" | head -1 } function __dru_get_the_current_project_version { local curr_v output if [[ $proj == "drupal" ]] then # drupal # Drupal version from CHANGELOG.txt of the site we update if [[ -f CHANGELOG.txt ]] then curr_v=`cat CHANGELOG.txt | grep "^Drupal" | sed 's/\,.*$//' | sed 's/Drupal\ //' | head -1` fi if [[ -z $curr_v ]] # can be empty (-z) either because CHANGELOG.txt missing or corrupt then echo "Unable to get Drupal site version. Maybe you are not in its root dir?. Exiting..."; exit 1; fi echo "$curr_v" else # some contrib proj output=`find sites/all/${proj_type}s/$proj/ -name "*\.info*" -exec grep 'version = ' '{}' \;` echo "$output" | head -1 | tr -d '"' | sed 's/version = //' fi } ###################################################################3 for proj in $projects do ########### determine versions echo "All releases for $proj:" drush info $proj proj_type_suggestion="module" if [[ $proj != "drupal" ]] then echo -n " Project '$proj' has type ( write module or theme ) ? [$proj_type_suggestion]: " read proj_type #"$(__dru_get_curr_project_version $proj)" if [[ $proj_type == "" ]] then proj_type=$proj_type_suggestion fi fi #echo $proj_type; exit new_v_suggestion=$(__dru_get_the_latest_stable_project_version) curr_v_suggestion=$(__dru_get_the_current_project_version) echo -n " Current version of project '$proj' ( suggestion guessed by parsing sites/all/${proj_type}s/$proj/*.info or CHANGELOG.txt for drupal core ) [$curr_v_suggestion]: " read curr_v #"$(__dru_get_curr_project_version $proj)" if [[ $curr_v == "" ]] then curr_v=$curr_v_suggestion fi echo -n "Enter latest version of project '$proj' [$new_v_suggestion]: " read new_v #"$(__dru_get_curr_project_version $proj)" if [[ $new_v == "" ]] then new_v=$new_v_suggestion fi #echo "curr=$curr_v | new=$new_v" ############### download orig and new drupal_updates_dir="/tmp/drupal_updates_${proj}_"`date +'%F %T' | tr ' ' '_' | tr ':' '-'` echo "OK: Removing $drupal_updates_dir - it is timestamped but just in case..." rm -fdr $drupal_updates_dir && echo "OK: Removed. Creating it again." mkdir $drupal_updates_dir if [[ $proj == "drupal" ]] then curr=`pwd` # dir of curr site else curr=`pwd`/sites/all/$proj_type/$proj fi orig=$drupal_updates_dir/${proj}-$curr_v new=$drupal_updates_dir/${proj}-$new_v #pwd # We have 3 dirs in this show - current site, drupal core with the same version and latest drupal core echo " OK: Your project is at : $curr OK: Freshly dl-ed project with the same version is at : $orig OK: Freshly dl-ed project with the LATEST version is at : $new OK: the working directory (a.k.a. '.') is : `pwd` " #################### if proj=core auto-resolve the sites diff, as well as the backup and cache dirs drush dl --destination=$drupal_updates_dir ${proj}-$curr_v; if [[ $proj != "drupal" ]] then mv $drupal_updates_dir/$proj $drupal_updates_dir/${proj}-$curr_v fi drush dl --destination=$drupal_updates_dir ${proj}-$new_v; if [[ $proj != "drupal" ]] then mv $drupal_updates_dir/$proj $drupal_updates_dir/${proj}-$new_v fi #__dru_rm_from_both_core_dirs sites && echo "OK: removed sites from untouched core versions cause we will put our live site's 'sites' dir there" #__dru_cp_from_curr_to_both_core_dirs sites backup cache ################## now do an interactive diff reolution - some things deleted, others copied , others left alone = hacks left to reside in the new version ######## the last diff should be NULL = dirs match exactly diff_type_suggestion="s" echo " s: the normal shell diff g: graphical with kdiff3" echo -n "What kind of diff do you want? [$diff_type_suggestion]: " read diff_type if [[ $diff_type == "" ]] then diff_type=$diff_type_suggestion fi if [[ $diff_type == "g" ]] then kdiff3 $orig $curr $new # orig is the base cause evolution is like orig->curr and orig->new else diff_command="diff -qr $curr $orig" diff_output=`$diff_command` echo " diff command: $diff_command diff output: ------ begin -------- $diff_output ------ end -------- " fi done # end of "proj in $projects"