#!/bin/bash # >> 0.3 # added file/dir permission tracking # added hint for failed file merges # added hint for failed patches echo<
wpmine="/home/user/www/numerodix/blog" version_file="${wpmine}/wp-includes/version.php" wordpress_baseurl="http://wordpress.org" temp_path="/home/user/t" ### echo -e "Pausing 10 seconds... (Ctrl+C to abort)\007" sleep 10 msg() { fill=$(for i in $(seq 1 $((76 - ${#1}))); do echo -n " "; done) echo< $temp_path/files-$ref-ref ) && ( cd $wpmine && find . -type f | sed "s|\./||g" | sort > $temp_path/files-$ref-mine ) && diff $temp_path/files-$ref-ref $temp_path/files-$ref-mine > $temp_path/diff if [[ $? < 2 ]]; then echo "diff written to $temp_path/diff" else echo "failed"; exit 1 fi msg "Recording my file/dir permissions..." cd $wpmine && \ find . -exec ls -ld --time-style=+%s {} \; | sed "s|\./||g" | sort -k 7 \ > $temp_path/files-$ref-mine.perms if [[ $? == 0 ]]; then echo "written to $temp_path/files-$ref-mine.perms" else echo "failed"; exit 1 fi msg "Listing files added/removed... " ( cat $temp_path/diff | grep "^>" | awk '{ print $2 }' > $temp_path/only_mine ) && ( cat $temp_path/diff | grep "^<" | awk '{ print $2 }' > $temp_path/only_ref ) && ( cat $temp_path/only_mine > $temp_path/not_common ) && ( cat $temp_path/only_ref >> $temp_path/not_common ) if [[ $? == 0 ]]; then echo "mine only files written to $temp_path/only_mine" echo "ref only files written to $temp_path/only_ref" else echo "failed"; exit 1 fi msg "Listing files changed... " [ -f $temp_path/changed ] && rm $temp_path/changed && touch $temp_path/changed for i in $(cat $temp_path/files-$ref-ref); do if ! grep -x $i $temp_path/not_common >/dev/null; then if ! diff -q $temp_path/wordpress-$ref/$i $wpmine/$i >/dev/null; then echo $i >> $temp_path/changed fi fi done if [[ $(wc -l < $temp_path/changed) == "0" ]]; then echo "No changes detected" else echo "Files changed written to $temp_path/changed" fi msg "Writing individual diffs... " [ -d $temp_path/diffs ] && rm -rf $temp_path/diffs mkdir -p $temp_path/diffs for i in $(cat $temp_path/changed); do e=$( echo $i | sed "s|\./||g" | tr "/" "." ) diff -u $temp_path/wordpress-$ref/$i $wpmine/$i > $temp_path/diffs/$e done ds=$(ls $temp_path/diffs | wc -l) echo "$ds diffs in $temp_path/diffs" msg "Fetching latest version... " [ -f $temp_path/latest.tar.gz ] && rm $temp_path/latest.tar.gz if wget -q -P $temp_path $wordpress_baseurl/latest.tar.gz; then echo "downloaded to $temp_path" else echo "could not fetch $wordpress_baseurl/latest.tar.gz"; exit 1 fi msg "Unpacking latest version... " [ -d $temp_path/wordpress-latest ] && rm -rf $temp_path/wordpress-latest if (cd $temp_path && tar zxf latest.tar.gz && mv wordpress wordpress-latest); then echo "unpacked to $temp_path/wordpress-latest" else echo "failed"; exit 1 fi wplatest="$temp_path/wordpress-latest" msg "Trying to patch diffs... " post=$(echo $wpmine | tr -d "/") patch_level=$(( ${#wpmine} - ${#post} )) [ -f $temp_path/patches.failed ] && rm $temp_path/patches.failed for i in $(ls $temp_path/diffs); do cd $wplatest && patch -p$patch_level < $temp_path/diffs/$i if [[ $? != 0 ]]; then echo $temp_path/diffs/$i >> $temp_path/patches.failed fi done msg "Merging in my files... " [ -f $temp_path/file-merge.failed ] && rm $temp_path/file-merge.failed for i in $(cat $temp_path/only_mine); do d=$(dirname $wplatest/$i) mkdir -p $d if [ -e $wplatest/$i ]; then ( echo "file already exists: $i"; echo $i >> $temp_path/file-merge.failed ) else ( echo "merging: $i" && cp -a $wpmine/$i $wplatest/$i ) fi done msg "Merging file/dir permissions..." while read line; do f=$(echo $line | awk '{ print $7 }') p=$(echo $line | awk '{ print $1 }'); p=${p:1:9} u=$(echo ${p:0:3} | tr -d '-') g=$(echo ${p:3:3} | tr -d '-') o=$(echo ${p:6:3} | tr -d '-') if [ -e $wplatest/$f ]; then echo "setting: $p $f" chmod u=$u $wplatest/$f chmod g=$g $wplatest/$f chmod o=$o $wplatest/$f fi done < $temp_path/files-$ref-mine.perms msg "Removing files I deleted... " for i in $(cat $temp_path/only_ref); do [ -f $wplatest/$i ] && (echo "removing: $i" && rm $wplatest/$i) done msg "Complete" [ -f $temp_path/patches.failed ] && echo "Some of my patches failed to apply, listed in $temp_path/patches.failed" [ -f $temp_path/file-merge.failed ] && echo "Some of my files failed to merge, listed in $temp_path/file-merge.failed" echo<