Skip to content

Commit

Permalink
Merge pull request nightscout#27 from Navid200/TestMethod_PR
Browse files Browse the repository at this point in the history
Test method
  • Loading branch information
jamorham committed Dec 2, 2022
2 parents 9ff9649 + 7bd20d5 commit 71fff87
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 115 deletions.
20 changes: 3 additions & 17 deletions NS_Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ echo "Cannot continue.."
exit 5
fi

Test=0
#Test=1 ################ This line must be commented out before submitting a PR. ##########################

clear
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\
Some required packages will be installed now. It will take about 15 minutes to complete. This terminal needs to be kept open. Press enter to proceed.\n\n\
Expand Down Expand Up @@ -61,20 +58,9 @@ sudo apt -y autoremove
cd /srv

echo "Installing Nightscout"

if [ $Test -lt 1 ] # We are not testing.
then

sudo git clone https://github.com/jamorham/nightscout-vps.git
cd nightscout-vps
sudo git checkout vps-1
else # We are testing.

sudo git clone https://github.com/Navid200/cgm-remote-monitor.git
cd cgm-remote-monitor
sudo git checkout Navid_2022_11_16_Test
fi
sudo git pull
cd "$(< repo)"
sudo git reset --hard # delete any local edits.
sudo git pull # Update database from remote.

sudo npm install
sudo npm run generate-keys
Expand Down
36 changes: 2 additions & 34 deletions NS_Install2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ You need to complete installation phase 1 first." 9 50
exit
fi

Test=0
#Test=1 ########################## This line must be commented out before submitting a PR. ###################

if [ "`id -u`" != "0" ]
then
echo "Script needs root - use sudo bash NS_Install2.sh"
Expand All @@ -38,7 +35,6 @@ echo "Nginx config already patched"
fi

sudo service nginx start
# sudo certbot --nginx -d "$hostname" --redirect # We are doing this in ConfigureFreedns.sh

sudo systemctl daemon-reload
sudo systemctl start mongodb
Expand All @@ -62,9 +58,6 @@ EOF

fi

if [ $Test -lt 1 ] # If we are not testing.
then

cat > /etc/nightscout-start.sh << "EOF"
#!/bin/sh
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Expand All @@ -74,7 +67,8 @@ export MONGO_CONNECTION="mongodb://username:password@localhost:27017/Nightscout"
export INSECURE_USE_HTTP=true
export HOSTNAME="127.0.0.1"
export PORT="1337"
cd /srv/nightscout-vps
cd /srv
cd "$(< repo)"
while [ "`netstat -lnt | grep 27017 | grep -v grep`" = "" ]
do
echo "Waiting for mongo to start"
Expand All @@ -88,32 +82,6 @@ sleep 30
done
EOF

else # We are testing.
cat > /etc/nightscout-start.sh << "EOF"
#!/bin/sh
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
. /etc/nsconfig
export MONGO_COLLECTION="entries"
export MONGO_CONNECTION="mongodb://username:password@localhost:27017/Nightscout"
export INSECURE_USE_HTTP=true
export HOSTNAME="127.0.0.1"
export PORT="1337"
cd /srv/cgm-remote-monitor
while [ "`netstat -lnt | grep 27017 | grep -v grep`" = "" ]
do
echo "Waiting for mongo to start"
sleep 5
done
sleep 5
while [ 1 ]
do
node server.js
sleep 30
done
EOF

fi

cs=`grep 'API_SECRET=' /etc/nsconfig | head -1 | cut -f2 -d'"'`

echo "Current API secret is: $cs"
Expand Down
26 changes: 22 additions & 4 deletions Status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,40 @@ then
http="\Zb\Z1Closed\Zn"
fi


mongo="$(mongod --version | sed -n 1p)"
ns="$(ps -ef | grep SCREEN | grep root | fold --width=40 | sed -n 1p)"

uname="$(< /srv/username)"
if [ ! "$(< /srv/username)" = "jamorham" ]
then
uname="\Zb\Z1$(< /srv/username)\Zn"
fi

repo="$(< /srv/repo)"
if [ ! "$(< /srv/repo)" = "nightscout-vps" ]
then
repo="\Zb\Z1$(< /srv/repo)\Zn"
fi

branch="$(< /srv/brnch)"
if [ ! "$(< /srv/brnch)" = "vps-1" ]
then
branch="\Zb\Z1$(< /srv/brnch)\Zn"
fi


dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\
\Zb Status \Zn\n\n\
\ZbVirtual Machine\Zn\n\
Zone: "$Zone" \n\
RAM: $Ramsize \n\
Disk type: "$disk" \n\
Disk size: $disksz $DiskUsedPercent used \n\
Ubuntu: $ubuntu \n\
HTTP & HTTPS: $http \n\n\
HTTP & HTTPS: $http \n\
------------------------------------------ \n\
/$uname/$repo/$branch\n\
Swap: $swap \n\
Mongo: $mongo \n\
NS proc: $ns \n\
" 21 50
" 22 50

73 changes: 42 additions & 31 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

Test=0
# Uncomment the following line for testing.
#Test=1 ###################################### This line must be commented out before submitting a PR. ##########################################
# curl https://github.com/Navid200/cgm-remote-monitor/Navid_2022_11_16_Test/bootstrap.sh | bash <--- Only tested this way
# curl https://github.com/Navid200/cgm-remote-monitor/TestMethod/bootstrap.sh | bash

echo
echo "Bootstrapping the menu - Navid200"
echo "Bootstrapping the installation files - Navid200"
echo

if [ ! -z "$(ls /srv)" ]
then
clear
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\
The script you are running, \"bootstrap\", is meant to initiate an installtion. However, the file system does not seem to be empty.\n\n\
If you already have an installtion on this machine and proceed by pressing enter, it will be modified. If that's not your intention, please press escape to abort." 15 50
if [ $? -eq 255 ]
then
clear
exit
fi
fi
clear

sudo apt-get update
sudo apt-get install dialog
ubversion="$(cat /etc/issue | awk '{print $2}')"
Expand All @@ -26,41 +36,42 @@ sudo apt-get install -y git python gcc g++ make
sudo apt-get -y install netcat

cd /
if [ ! -s xDrip ] # Create the xDrip directory if it does not exist.
then
sudo rm -rf xDrip
sudo mkdir xDrip
fi
cd xDrip
if [ ! -s scripts ]
then
sudo mkdir scripts
fi

cd /tmp
if [ ./update_scripts.sh ]
then
sudo rm update_scripts.sh
fi
rm -fr nightscout-vps

if [ $Test -gt 0 ]
then
wget https://github.com/Navid200/cgm-remote-monitor/Navid_2022_11_16_Test/update_scripts.sh # Test
else
git clone https://github.com/jamorham/nightscout-vps.git nightscout-vps
cd nightscout-vps
git checkout vps-1

fi
cd /srv
sudo rm -rf *
sudo git clone https://github.com/jamorham/nightscout-vps.git # ✅✅✅✅✅ Main - Uncomment before PR.
#sudo git clone https://github.com/Navid200/cgm-remote-monitor.git # ⛔⛔⛔⛔⛔ For test - Comment out before PR.

ls > /tmp/repo
sudo mv -f /tmp/repo . # The repository name is now in /srv/repo
cd "$(< repo)"
sudo git checkout vps-1 # ✅✅✅✅✅ Main - Uncomment before PR.
#sudo git checkout TestMethod # ⛔⛔⛔⛔⛔ For test - Comment out before PR.

sudo git branch > /tmp/branch
grep "*" /tmp/branch | awk '{print $2}' > /tmp/brnch
sudo mv -f /tmp/brnch ../. # The branch name is now in /srv/brnch

sudo git remote -v > /tmp/username
grep "fetch" /tmp/username | awk '{print $2}' >/tmp/username2
FLine=$(</tmp/username2)
IFS='/'
read -a split <<< $FLine
echo ${split[3]} > /tmp/username
sudo mv -f /tmp/username ../.

if [ ! -s update_scripts.sh ]
then
echo "UNABLE TO DOWNLOAD update_scripts SCRIPT! - cannot continue - please try again!"
exit 5
fi

sudo chmod 755 update_scripts.sh
sudo mv -f update_scripts.sh /xDrip/scripts
sudo chmod 755 *.sh
sudo cp -f update_scripts.sh /xDrip/scripts

# Updating the scripts
cat > /tmp/nodialog_update_scripts << EOF
Expand Down Expand Up @@ -98,4 +109,4 @@ Please take a note, delete the virtual machine, and create a new one. For more
/xDrip/scripts/Status.sh
clear
/xDrip/scripts/menu.sh < /dev/tty

6 changes: 6 additions & 0 deletions menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ sudo /xDrip/scripts/clone_nightscout.sh
;;

7)
cd /srv
cd "$(< repo)" # Go to the local database
sudo git reset --hard # delete any local edits.
sudo git pull # Update database from remote.
sudo chmod 755 update_scripts.sh
sudo cp -f update_scripts.sh /xDrip/scripts/.
clear
sudo /xDrip/scripts/update_scripts.sh
;;
Expand Down
55 changes: 26 additions & 29 deletions update_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
#!/bin/bash

# This should never be called before first being updated to the latest remote release.
# Currently, only bootstrap and menu call this. Both update this file before calling it.
# If you decide to call this anywhere else, make sure to update the local copy before calling it.

echo
echo "Fetch the latest scripts from GitHub - Navid200"
echo

Test=0
# Comment out the next line before submission.
#Test=1 ########################### This line must be commented out before submitting a PR #########

cd /tmp

if [ $Test -gt 0 ] # Are we testing?
then
if [ -s ./cgm-remote-monitor ]
if [ ! -s /srv/repo ] # Create the file containing the repository name if nonexistent.
then
sudo rm -r cgm-remote-monitor
cat > /srv/repo << EOF
nightscout-vps
EOF
fi
sudo git clone https://github.com/Navid200/cgm-remote-monitor.git # Test
cd cgm-remote-monitor
sudo git checkout Navid_2022_11_16_Test
else # If we are not testing
if [ -s ./nightscout-vps ]
if [ ! -s /srv/brnch ] # Create the file containing the branch name if nonexistent.
then
sudo rm -r nightscout-vps
cat > /srv/brnch << EOF
vps-1
EOF
fi
sudo git clone https://github.com/jamorham/nightscout-vps.git # Main
cd nightscout-vps
sudo git checkout vps-1
if [ ! -s /srv/username ] # Create the file containing the user name if nonexistent.
then
cat > /srv/username << EOF
jamorham
EOF
fi

sudo git pull
cd /srv
cd "$(< repo)"
sudo git reset --hard # delete any local edits.
sudo git pull # Update database from remote.

sudo chmod 755 *.sh # Change premissions to allow execution by all.
rm -f /xDrip/scripts/*.sh # Remove the existing sh files
sudo mv -f *.sh /xDrip/scripts # Overwrite the scripts in the scripts directory with the new ones.
rm -rf /xDrip/ConfigServer # Remove the existing ConfigServer directory
sudo mv ConfigServer /xDrip/.
sudo rm -f /xDrip/scripts/*.sh # Remove the existing sh files
sudo cp *.sh /xDrip/scripts # Overwrite the scripts in the scripts directory with the new ones.
sudo rm -rf /xDrip/ConfigServer # Remove the existing ConfigServer directory
sudo cp -r ConfigServer /xDrip/.
cd ..
sudo rm -rf nightscout-vps
sudo rm -rf cgm-remote-monitor

# Update Configserver


if [ ! -s /tmp/nodialog_update_scripts ]
then
Expand Down

0 comments on commit 71fff87

Please sign in to comment.