forked from kamba4/sunders
		
	
		
			
				
	
	
		
			71 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| exedir=$(cd `dirname "$0"`; pwd)
 | |
| 
 | |
| REPLICATE_URL=`grep "REPLICATE_URL" "$exedir/config.php"  | sed -e 's/.*http/http/' -e 's#...$##' `
 | |
| 
 | |
| if [ -e "/var/lock/update_camera" ]
 | |
| then
 | |
|   # Maybe an other update is running
 | |
|   otherPid=$(cat "/var/lock/update_camera")
 | |
|   count=$(ps $otherPid | grep -c `basename "$0"`)
 | |
| 
 | |
|   if [ $count -gt 0 ]
 | |
|   then
 | |
|     echo "$0 is running yet. Exiting." >&2
 | |
|     exit 1
 | |
|   fi
 | |
| fi
 | |
| 
 | |
| # OK. We can update the database...
 | |
| echo $$ >  "/var/lock/update_camera"
 | |
| 
 | |
| exeDir=$(cd `dirname "$0"`; pwd);
 | |
| cd "$exeDir"
 | |
| 
 | |
| if [ -e "state.txt" ]
 | |
| then
 | |
|   rm "state.txt"
 | |
| fi
 | |
| 
 | |
| #TODO get state from db
 | |
| # Read the last update timestamp
 | |
| # lastTimestamp=$(grep "^timestamp=" "lastState.txt" | cut -d'=' -f2-)
 | |
| # lastSeqNum=$(grep "^sequenceNumber=" "lastState.txt" | cut -d'=' -f2-)
 | |
| 
 | |
| lastSeqNum=$(php get_sync_state.php)
 | |
| 
 | |
| curl -L "$REPLICATE_URL/state.txt" -o state.txt 
 | |
| 
 | |
| newTimestamp=$(grep "^timestamp=" "state.txt" | cut -d'=' -f2-)
 | |
| newSeqNum=$(grep "^sequenceNumber=" "state.txt" | cut -d'=' -f2-)
 | |
| 
 | |
| if [ $newSeqNum -eq $lastSeqNum ]
 | |
| then
 | |
|   echo "No new file to be processed"
 | |
|   exit 1
 | |
| fi
 | |
| mkdir logs
 | |
| curSeqNum=$lastSeqNum
 | |
| curSeqNum=$(( $curSeqNum + 1 ))
 | |
| while [ $curSeqNum -lt $newSeqNum ]
 | |
| do
 | |
|   if [ -e /migrations/"${curSeqNum}_filtered.osc" ]
 | |
|   then
 | |
|   
 | |
| 
 | |
|   rm "change_file.osc"
 | |
|   cp /migrations/${curSeqNum}_filtered.osc change_file.osc
 | |
| 
 | |
|   php create_camera_update_statements.php $curSeqNum
 | |
|   rm /migrations/${curSeqNum}_filtered.osc
 | |
|   curSeqNum=$(( $curSeqNum + 1 ))
 | |
|   else
 | |
|   path=$(echo "$(printf "%09d" "$curSeqNum")" | sed -E "s#(...)(...)(...)#\1/\2/\3#")
 | |
|   url="${REPLICATE_URL}/${path}.osc.gz"
 | |
|   echo $url
 | |
|   curl -sL "$url" -o /migrations/"$curSeqNum.osc.gz" && gunzip /migrations/"$curSeqNum.osc.gz" && python filter_osc.py ${curSeqNum} && rm /migrations/${curSeqNum}.osc 
 | |
|   fi
 | |
| done
 | |
| 
 | |
| rm "/var/lock/update_camera"
 | 
