You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
5.8 KiB
165 lines
5.8 KiB
10 years ago
|
#!/bin/bash
|
||
|
|
||
|
echo "----------------------------------------------------------------"
|
||
|
echo "| WSO2 IOT Sample "
|
||
|
echo "| RaspiAlarm "
|
||
|
echo "| ---------------- "
|
||
|
echo "| ....initializing startup-script "
|
||
|
echo "----------------------------------------------------------------"
|
||
|
|
||
9 years ago
|
#while true; do
|
||
|
# read -p "Do you wish to run 'apt-get update' and continue? [Yes/No] " yn
|
||
|
# case $yn in
|
||
|
# [Yy]* ) sudo apt-get update;
|
||
|
# break;;
|
||
|
# [Nn]* ) echo "Continuing without apt-get update...";
|
||
|
# break;;
|
||
|
# * ) echo "Please answer yes or no.";
|
||
|
# esac
|
||
|
#done
|
||
|
#
|
||
|
#if [ $? -ne 0 ]; then
|
||
|
# echo "apt-get update failed.... Some dependencies may not get installed"
|
||
|
# echo "If an already installed version of the package exists, try running:"
|
||
|
# echo "----------------------------------------------------------------"
|
||
|
# echo "sudo -i"
|
||
|
# echo "cd /var/lib/dpkg/info"
|
||
|
# echo "rm -rf wso2-raspi-alarm*"
|
||
|
# echo "dpkg --remove --force-remove-reinstreq wso2-raspi-alarm"
|
||
|
# echo "exit"
|
||
|
# echo "----------------------------------------------------------------"
|
||
|
# echo "Retry Installation...."
|
||
|
# break;
|
||
|
#fi
|
||
|
#
|
||
|
#echo "Installing 'gdebi' package..."
|
||
|
#sudo apt-get install gdebi # installation of gdebi
|
||
|
#
|
||
|
#
|
||
|
#if [ $? -ne 0 ]; then
|
||
|
# echo "gdebi installation failed.... dependencies will not be installed without gdebi"
|
||
|
# read -p "Do you wish to continue without gdebi? [Yes/No] " yn
|
||
|
# case $yn in
|
||
|
# [Yy]* ) echo "Continueing without gdebi.....";;
|
||
|
# [Nn]* ) echo "Try to resolve errors and re-run the script.";
|
||
|
# exit;;
|
||
|
# * ) exit;;
|
||
|
# esac
|
||
|
#fi
|
||
|
#
|
||
|
#
|
||
|
#for f in ./wso2-raspi-alarm_1.0_armhf.deb; do
|
||
|
# ## Check if the glob gets expanded to existing files.
|
||
|
# ## If not, f here will be exactly the pattern above
|
||
|
# ## and the exists test will evaluate to false.
|
||
|
# # [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit;
|
||
|
# if [ -e "$f" ]; then
|
||
|
# echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing now...."
|
||
|
# else
|
||
|
# echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path. \nExiting installation...";
|
||
|
# exit;
|
||
|
# fi
|
||
|
# ## This is all we needed to know, so we can break after the first iteration
|
||
|
# break
|
||
|
#done
|
||
|
#
|
||
|
#echo "Installing the 'wso2-raspi-alarm deb package'"
|
||
|
#sudo gdebi wso2-raspi-alarm_1.0_armhf.deb
|
||
|
#
|
||
|
#if [ $? -ne 0 ]; then
|
||
|
# echo "Installation Failed...."
|
||
|
# exit;
|
||
|
#fi
|
||
|
|
||
|
sudo killall -9 python
|
||
|
|
||
|
for f in ./RaspberryAgent.zip; do
|
||
|
## Check if the glob gets expanded to existing files.
|
||
|
## If not, f here will be exactly the pattern above
|
||
|
## and the exists test will evaluate to false.
|
||
|
# [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit;
|
||
|
if [ -e "$f" ]; then
|
||
|
echo "Agent files found......"
|
||
|
sudo rm -rf /usr/local/src/RaspberryAgent
|
||
|
sudo unzip RaspberryAgent.zip -d /usr/local/src/
|
||
|
else
|
||
|
echo "'RaspberryAgent.zip' file does not exist in current path. \nInstalling without upgrading agent...";
|
||
|
fi
|
||
|
## This is all we needed to know, so we can break after the first iteration
|
||
|
break
|
||
10 years ago
|
done
|
||
|
|
||
9 years ago
|
for f in /usr/local/src/RaspberryAgent/rc.local; do
|
||
10 years ago
|
## Check if the glob gets expanded to existing files.
|
||
|
## If not, f here will be exactly the pattern above
|
||
|
## and the exists test will evaluate to false.
|
||
|
if [ -e "$f" ]; then
|
||
9 years ago
|
echo "Copying boot script"
|
||
|
sudo mv /usr/local/src/RaspberryAgent/rc.local /etc/rc.local
|
||
|
sudo chmod +x /etc/rc.local
|
||
10 years ago
|
else
|
||
9 years ago
|
echo "Unable to set agent statup on boot";
|
||
10 years ago
|
fi
|
||
|
## This is all we needed to know, so we can break after the first iteration
|
||
|
break
|
||
|
done
|
||
|
|
||
|
for f in ./deviceConfigs.cfg; do
|
||
|
## Check if the glob gets expanded to existing files.
|
||
|
## If not, f here will be exactly the pattern above
|
||
|
## and the exists test will evaluate to false.
|
||
|
if [ -e "$f" ]; then
|
||
|
echo "Configuration file found......"
|
||
|
else
|
||
|
echo "'deviceConfigs.cfg' file does not exist in current path. \nExiting installation...";
|
||
|
exit;
|
||
|
fi
|
||
|
## This is all we needed to know, so we can break after the first iteration
|
||
|
break
|
||
|
done
|
||
|
|
||
9 years ago
|
echo "Altering Configuration file"
|
||
|
sed -i 's|[/,]||g' deviceConfigs.cfg
|
||
|
|
||
10 years ago
|
echo "Copying configurations file to /usr/local/src/RaspberryAgent"
|
||
|
sudo cp ./deviceConfigs.cfg /usr/local/src/RaspberryAgent/
|
||
|
|
||
|
if [ $? -ne 0 ]; then
|
||
|
echo "Copying configuration file failed...."
|
||
|
exit;
|
||
|
fi
|
||
|
|
||
|
while true; do
|
||
|
read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute) > " input
|
||
|
|
||
|
if [ $input -eq $input 2>/dev/null ]
|
||
|
then
|
||
|
echo "Setting data-push interval to $input seconds."
|
||
9 years ago
|
echo $input > /usr/local/src/RaspberryAgent/time-interval
|
||
10 years ago
|
break;
|
||
|
else
|
||
|
echo "Input needs to be an integer indicating the number seconds between successive data-pushes."
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
cd /usr/local/src/RaspberryAgent/
|
||
9 years ago
|
sudo chmod +x RaspberryStats.py
|
||
9 years ago
|
sudo nohup ./RaspberryStats.py -i $input </dev/null &
|
||
10 years ago
|
|
||
|
if [ $? -ne 0 ]; then
|
||
|
echo "Could not start the service..."
|
||
|
exit;
|
||
9 years ago
|
else
|
||
|
echo "Running the RaspberryAgent service...."
|
||
10 years ago
|
fi
|
||
|
|
||
|
echo "--------------------------------------------------------------------------"
|
||
|
echo "| Successfully Started "
|
||
|
echo "| -------------------------- "
|
||
9 years ago
|
echo "| cd to /usr/local/src/RaspberryAgent"
|
||
9 years ago
|
echo "| run 'sudo nohup ./RaspberryStats.py -i time </dev/null &'to start service manually."
|
||
9 years ago
|
echo "| Relapce time with the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute)"
|
||
10 years ago
|
echo "| Find logs at: /usr/local/src/RaspberryAgent/logs/RaspberryStats.log"
|
||
|
echo "---------------------------------------------------------------------------"
|
||
9 years ago
|
|