|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +########################################## |
| 4 | +# |
| 5 | +# Update configuration files for machinery |
| 6 | +# |
| 7 | + |
| 8 | +KERBEROS_CONFIG_DIR="/etc/opt/kerberosio/config" |
| 9 | +DATA_CONFIG_DIR="/data/machinery/config" |
| 10 | +TEMP_CONFIG_DIR="/tmp/config" |
| 11 | + |
| 12 | +# Copy files to tmp folder and overwrite data config files |
| 13 | + |
| 14 | +rm -rf $TEMP_CONFIG_DIR |
| 15 | +mkdir -p $TEMP_CONFIG_DIR |
| 16 | +cp -r $DATA_CONFIG_DIR/* $TEMP_CONFIG_DIR |
| 17 | +cp -r $KERBEROS_CONFIG_DIR/* $DATA_CONFIG_DIR |
| 18 | + |
| 19 | +# Loop over old config files and adjust new configuration |
| 20 | +# with previous values. |
| 21 | + |
| 22 | +for oldfile in $TEMP_CONFIG_DIR/* |
| 23 | +do |
| 24 | + for newfile in $DATA_CONFIG_DIR/* |
| 25 | + do |
| 26 | + if [ ${oldfile#$TEMP_CONFIG_DIR} == ${newfile#$DATA_CONFIG_DIR} ] |
| 27 | + then |
| 28 | + lineNumber=1 |
| 29 | + |
| 30 | + while read p |
| 31 | + do |
| 32 | + name=`echo $p | grep -E "\<(.*?)\>(.*?)<(.*?)\>" | cut -d ">" -f1 | cut -d "<" -f2 | cut -d " " -f1` |
| 33 | + value=`echo $p | grep -E "\<(.*?)\>(.*?)<(.*?)\>" | cut -d ">" -f2 | cut -d "<" -f1` |
| 34 | + |
| 35 | + if [ -n "$name" ] |
| 36 | + then |
| 37 | + #echo "looking for " $name " in " $newfile " with old value " $value |
| 38 | + |
| 39 | + while read -r line ; do |
| 40 | + number=`echo $line | cut -d ':' -f1` |
| 41 | + if [[ $lineNumber -le $number ]] |
| 42 | + then |
| 43 | + newvalue=`echo $line | sed -e "s/^$number:[ \t]*//"` |
| 44 | + if [[ "$p" != "$newvalue" ]] |
| 45 | + then |
| 46 | + sed $number"s#$newvalue#$p#" $newfile > $newfile"_" |
| 47 | + mv $newfile"_" $newfile |
| 48 | + fi |
| 49 | + lineNumber=$number |
| 50 | + break |
| 51 | + fi |
| 52 | + done <<< "$(grep -n "$name " $newfile)" |
| 53 | + fi |
| 54 | + |
| 55 | + done < $oldfile |
| 56 | + fi |
| 57 | + done |
| 58 | +done |
| 59 | + |
| 60 | +chmod -R 777 $DATA_CONFIG_DIR |
| 61 | + |
| 62 | +mkdir -p /data/machinery/h264 |
| 63 | +chmod -R 777 /data/machinery/h264 |
| 64 | + |
| 65 | +########################################## |
| 66 | +# |
| 67 | +# Update configuration files for web |
| 68 | +# |
| 69 | + |
| 70 | +cp -R /var/www/web/storage /data/web/ |
| 71 | +chmod -R 777 /data/web/storage |
| 72 | + |
| 73 | +cp -R /var/www/web/config /data/web/ |
| 74 | +mv /data/web/app/config/kerberos.php /data/web/config/kerberos.php |
| 75 | +chmod 777 /data/web/config/kerberos.php |
| 76 | + |
| 77 | +cp -R /var/www/web/bootstrap /data/web/ |
| 78 | +chmod -R 777 /data/web/bootstrap/cache |
| 79 | + |
| 80 | +rm -rf /data/web/app |
0 commit comments