s4

changeset 786:809caeb20758 feature-world

Migration caller set arguments beforehand
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 13 Jun 2020 13:19:07 +0900
parents 1f310d682c07
children c5b61d23052b
files s4-funcs.sh s4-migrate.sh
diffstat 2 files changed, 15 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Sat Jun 13 13:16:24 2020 +0900
     1.2 +++ b/s4-funcs.sh	Sat Jun 13 13:19:07 2020 +0900
     1.3 @@ -11,6 +11,9 @@
     1.4        echo S4WORLD=$S4WORLD >&2
     1.5        worldconf=s4-config-${S4WORLD}.sh
     1.6        ;;
     1.7 +    *)
     1.8 +      worldconf=s4-config.sh
     1.9 +      ;;
    1.10    esac
    1.11  
    1.12    echo worldconf=$worldconf >&2
    1.13 @@ -99,7 +102,8 @@
    1.14      worldlistfile=cache/worldlist
    1.15      worldoptionfile=cache/worldoption
    1.16      if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \
    1.17 -	   -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh ]
    1.18 +	   -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh \
    1.19 +	   -o s4-funcs.sh -nt $worldoptionfile ]
    1.20      then
    1.21        echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out
    1.22        cat <<-EOF > $worldlistfile
    1.23 @@ -120,12 +124,9 @@
    1.24  	    <option title="$d" value="$conf">$name</option>
    1.25  		EOF
    1.26  	}
    1.27 -	if [ -n "$S4MASTERDB" ]; then
    1.28 -	  echo "<option value=\"s4-config.sh\">Base</option>" \
    1.29 -	       >> $worldoptionfile
    1.30 -	fi
    1.31        done
    1.32        if [ -s "$worldoptionfile" ]; then
    1.33 +	echo "<option value=\"s4-config.sh\">Base</option>" >> $worldoptionfile
    1.34  	echo "</table>$nl</div>" >> $worldlistfile
    1.35        else
    1.36  	true > $worldoptionfile; true > $worldlistfile	# Remove contents
    1.37 @@ -1968,8 +1969,9 @@
    1.38    _m4 -D_TITLE_="移住操作" -D_BODYCLASS_="" $layout/html.m4.html
    1.39    echo "移住操作" | html h1
    1.40    echo '<pre>'
    1.41 -  # err  ./s4-migrate.sh "$srcconf" "$destconf" "$rowid"
    1.42 -  . ./s4-migrate.sh "$srcconf" "$destconf" "$rowid"
    1.43 +  set -- "$srcconf" "$destconf" "$rowid"
    1.44 +  err  ./s4-migrate.sh "$srcconf" "$destconf" "$rowid"
    1.45 +  . ./s4-migrate.sh		# Dot(.) sourcing might not pass arguments
    1.46    rc=$?
    1.47    echo "</pre>"
    1.48    if [ $rc -eq 0 ]; then
     2.1 --- a/s4-migrate.sh	Sat Jun 13 13:16:24 2020 +0900
     2.2 +++ b/s4-migrate.sh	Sat Jun 13 13:19:07 2020 +0900
     2.3 @@ -13,7 +13,7 @@
     2.4  esac
     2.5  htmlworld=`echo "$world"|htmlescape`
     2.6  
     2.7 -err "--- Migration Started at `date` ---"
     2.8 +err "--- Migration Started with \$1=$1 \$2=$2 at `date` ---"
     2.9  err srcdb=$srcdb dstdb=$dstdb
    2.10  err URL=$URL
    2.11  err dstURL=$dsturl
    2.12 @@ -93,6 +93,7 @@
    2.13  	      	     WHERE key='owner' AND val=$qgrp);
    2.14  	EOF
    2.15      )
    2.16 +  err d2="$d2"
    2.17    # article
    2.18    d3=$(query <<-EOF
    2.19  	SELECT * FROM main.article
    2.20 @@ -106,6 +107,7 @@
    2.21  	WHERE blogid IN ($blogs);
    2.22  	EOF
    2.23         )
    2.24 +  err d3="$d3"
    2.25    if [ -z "$d1$d2$d3" ]; then
    2.26      echo "Copying done, rewriting article links..."
    2.27      echo "Old URL: $URL"
    2.28 @@ -120,14 +122,14 @@
    2.29  	EOF
    2.30      # Create blog-rowid conversion table
    2.31      sedfile=$tmpd/arttrans.sed
    2.32 -    sedfile=tmp/arttrans.sed
    2.33 +    # sedfile=tmp/arttrans.sed
    2.34      query <<-EOF > $sedfile
    2.35  	WITH arttrans AS (
    2.36  	  SELECT s.rowid srcrid, d.rowid dstrid
    2.37  	  FROM main.article s JOIN dst.article d ON s.id=d.id
    2.38  	  WHERE s.id in (SELECT id
    2.39  	  	     	 FROM article WHERE blogid IN ($blogs))
    2.40 -	) SELECT printf("/^>/s/\#%s\([^0-9]*\)/\#%s\1/g", srcrid, dstrid)
    2.41 +	) SELECT printf("/^>/s/\#%s($|[ ,\#])/\#%s\1/g", srcrid, dstrid)
    2.42  	  FROM arttrans;
    2.43  	EOF
    2.44      query <<-EOF > $tmpd/repl.art.rowid
    2.45 @@ -138,7 +140,7 @@
    2.46      sql=$tmpd/update.sql
    2.47      for arid in `cat $tmpd/repl.art.rowid`; do
    2.48        newval=`query "SELECT hex(val) FROM dst.article_s WHERE rowid=$arid;" \
    2.49 -              | unhexize | sed -f "$sedfile" | hexize`
    2.50 +              | unhexize | sed -Ef "$sedfile" | hexize`
    2.51        echo "UPDATE dst.article_s SET val=X'$newval' WHERE rowid=$arid;" >>$sql
    2.52      done
    2.53      # Rewrite blog-links in the group