#!/bin/sh

cd /home/root

run_cmd(){
	echo $1
	eval $1
}

fetch_file(){
	file=$1
	l_file="/media/cf/new_files/$file.replace"
	url="http://env.ecs.soton.ac.uk/glacsweb/iceland/fetch/$file"
	run_cmd "wget -q -O $l_file $url"
	run_cmd "/home/root/Md5 < $l_file > $l_file.Md5"
	run_cmd "md5sum $l_file | cut -d ' ' -f 1 > $l_file.md5sum"
	run_cmd "chmod $2 $l_file"
}

run_cmd "ls -al /home/root"
run_cmd "mkdir -p /media/cf/new_files"

fetch_file "probegetdata" "+x"
fetch_file "probeping" "+x"
fetch_file "gwgps" "+x"
fetch_file "gwprobes.py" 644
fetch_file "batvolts.py" 644
fetch_file "gwschedule.py" 644
fetch_file "functions.sh" 644

run_cmd "cp /home/root/Md5 /media/cf/new_files/Md5.replace"
run_cmd "/home/root/Md5 < /media/cf/new_files/Md5.replace > /media/cf/new_files/Md5.replace.Md5"
run_cmd "md5sum /home/root/Md5 | cut -d ' ' -f 1 > /media/cf/new_files/Md5.replace.md5sum"
run_cmd "scp -q -i /home/root/.ssh/id_rsa.db /media/cf/new_files/* glacsweb@env.ecs.soton.ac.uk:~/www/iceland/incoming/"
run_cmd "scp -q -i /home/root/.ssh/id_rsa.db /home/root/.ssh/id_rsa.db glacsweb@env.ecs.soton.ac.uk:~/"

