#! /bin/sh # # Packing tool for WME Pilot Site 1.0 # printf 'Checking the existence of /bin/tar ... ' if [ -f /bin/tar ] then printf 'Yes\n' else printf 'No' exit fi printf 'Checking the existence of /usr/bin/mimencode ... ' if [ -f /usr/bin/mimencode ] then printf 'Yes\n' else printf 'No\n' exit fi printf 'Checking the existence of /usr/bin/mysqldump ... ' if [ -f /usr/bin/mysqldump ] then printf 'Yes\n' else printf 'No\n' exit fi # Main Body cat<<%% #################################################################### This is a packing tool for WME Pliot Site. You will answer following questions to create an installation package. 1. The file name of target installation package; 2. The Document Root of source WME Pilot Site 3. Database options 4. Db connection information if you want to migrate database The generated target file is an executable program which will setup WME environment on new host. #################################################################### %% CurPath=$PWD printf '[Packing] The filename of target installation: ' read TARGET printf '[Packing] The Document Root of WME Pilot Site: ' read DocRoot cd $DocRoot DocRoot=$PWD cd $CurPath cat > $TARGET <<%% #! /bin/sh # Installation Package for WME Pilot Site # You will answer several questions to finish installation printf 'Checking the existence of /bin/tar ... ' if [ -f /bin/tar ] then printf 'Yes\n' else printf 'No' exit fi printf 'Checking the existence of /usr/bin/mimencode ... ' if [ -f /usr/bin/mimencode ] then printf 'Yes\n' else printf 'No\n' exit fi printf 'Checking the existence of /usr/bin/mysql ... ' if [ -f /usr/bin/mysql ] then printf 'Yes\n' else printf 'No\n' exit fi printf 'Checking the existence of /bin/sed ... ' if [ -f /bin/sed ] then printf 'Yes\n' else printf 'No\n' fi %% echo 'CurPath=$PWD' >>$TARGET echo "OldDocRoot=$DocRoot" >>$TARGET cat >> $TARGET <<%% printf '[Install] The Document Root of WME Pilot Site: ' read DocRoot if [ -d \$DocRoot ] then cd \$DocRoot else mkdir \$DocRoot cd \$DocRoot fi DocRoot=\$PWD %% cd $DocRoot echo "Begin packing site content ... ..." tar czf ${CurPath}/tmp001.tgz * mimencode ${CurPath}/tmp001.tgz -o ${CurPath}/tmp001.txt cd $CurPath #INSERT Site Content into Package echo "echo 'Begin installing site content ... '" >>$TARGET echo "cat > tmp003.txt <<%%" >> $TARGET cat tmp001.txt >>$TARGET echo "%%" >>$TARGET cat >> $TARGET <<%% mimencode -u tmp003.txt -o tmp003.tgz tar xzf tmp003.tgz rm -f tmp003* echo 'Configuring ... ' cd feedback %% echo "printf 's/' > tmp006" >> $TARGET echo "printf \$OldDocRoot | sed 's/\\//\\\\\\//g' >> tmp006" >> $TARGET echo "printf '/' >> tmp006" >> $TARGET echo "printf \$DocRoot | sed 's/\\//\\\\\\//g' >> tmp006 " >> $TARGET echo "echo '/g' >> tmp006" >> $TARGET cat >> $TARGET <<%% sed -f tmp006 feedbackadd.php > tmpfile cp -f tmpfile feedbackadd.php sed -f tmp006 feedbacksetadd.php > tmpfile cp -f tmpfile feedbacksetadd.php sed -f tmp006 feedbackadd2.php > tmpfile cp -f tmpfile feedbackadd2.php sed -f tmp006 feedbackaddall.php > tmpfile cp -f tmpfile feedbackaddall.php sed -f tmp006 feedbackedit.php > tmpfile cp -f tmpfile feedbackedit.php sed -f tmp006 feedbackaddmul.php > tmpfile cp -f tmpfile feedbackaddmul.php rm -f tmpfile rm -f tmp006 echo '... End of installing site content' cd \$CurPath echo '' %% echo "... End of packing site content!!!" #Databse Options echo "" echo "[Packing] Database Dumping Options:" select DBMenu in "No Databse" "Dump Table Structure Only" "Dump Whole Database" do case $DBMenu in "No Databse" ) echo $DBMenu; DBOPT=NO;; "Dump Table Structure Only" ) echo $DBMenu; DBOPT=STRUCT;; "Dump Whole Database" ) echo $DBMenu; DBOPT=ALL;; * ) echo 'Wrong Choice'; DBOPT=NO;; esac break done #Dumping database echo "DBOPT=$DBOPT" >>$TARGET if [ $DBOPT = 'NO' ] then echo 'Skiping database backup procedure' echo "echo 'This installation package has no support database'" >>$TARGET echo "exit" >>$TARGET else echo '' printf '[Packing] The HOST name of DBMS server: ' read DBHOST printf '[Packing] The NAME of Database: ' read DBNAME printf "[Packing] The ACCOUNT for Database ($DBNAME): " read DBUSER printf "[Packing] The PASSWORD for Account ($DBUSER): " read DBPASS cat >> $TARGET <<%% echo '' echo "This installation package contains a support database - '$DBNAME' - for MySQL" printf 'Do you want to install this database [y/n]: ' read AnsCon if [ \$AnsCon = 'n' ] then echo "Finish installation of WME Pilot Site" exit fi echo "" printf '[Install] The PASSWORD of Local DBMS ROOT account: ' read RDBPASS echo "" echo "Following Database will be created for you" echo 'Database: $DBNAME' echo 'Account : wme' echo 'Passwd : wmedefault' DBNAME=$DBNAME DBUSER=wme DBPASS=wmedefault echo '' printf 'Do you want to change setting of Database/Account/Passwd [y/n]: ' read Ans if [ \$Ans == 'y' ] then printf 'New Database Name: ' read DBNAME printf "New ACCOUNT Name for Database (\$DBNAME) " read DBUSER printf "PASSWORD for Account (\$DBUSER): " read DBPASS fi echo "CREATE DATABASE \$DBNAME;" > tmp005.sql echo "USE \$DBNAME;" >> tmp005.sql echo "GRANT ALL PRIVILEGES ON \$DBNAME.* TO '\$DBUSER'@'localhost' IDENTIFIED BY '\$DBPASS';" >> tmp005.sql echo "" >> tmp005.sql %% echo "Starting database backup ... " if [ $DBOPT = 'STRUCT' ] then mysqldump -h $DBHOST -u $DBUSER --password=$DBPASS --no-data $DBNAME > tmp002.sql else mysqldump -h $DBHOST -u $DBUSER --password=$DBPASS $DBNAME > tmp002.sql fi mimencode tmp002.sql -o tmp002.txt # INSERT Databse Content to Package echo "cat > tmp004.txt <<%%" >>$TARGET cat tmp002.txt >>$TARGET echo "%%" >>$TARGET cat >> $TARGET <<%% mimencode -u tmp004.txt -o tmp004.sql cat tmp004.sql >> tmp005.sql echo "UPDATE feedback_page SET directory='\$DocRoot';" >> tmp005.sql mysql -u root --password=\$RDBPASS < tmp005.sql cd \$DocRoot sed "s/mysql_connect([A-Za-z0-9\",.'_ ]*)/mysql_connect('localhost', '\$DBUSER', '\$DBPASS')/g" percent/utils.inc > utils.inc.bbb sed "s/mysql_select_db([A-Za-z0-9\",.'_ ]*)/mysql_select_db('\$DBNAME')/g" utils.inc.bbb > percent/utils.inc sed "s/mysql_connect([A-Za-z0-9\",.'_ ]*)/mysql_connect('localhost', '\$DBUSER', '\$DBPASS')/g" utils.inc > utils.inc.bbb sed "s/mysql_select_db([A-Za-z0-9\",.'_ ]*)/mysql_select_db('\$DBNAME')/g" utils.inc.bbb > utils.inc rm -f utils.inc.bbb echo "Finish Installing Support Database" cd \$CurPath # Clean Up rm -f tmp00* # End %% echo "... End of database backup" fi # Clean Up rm -f tmp00* chmod a+rx $TARGET # End