Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions overlay/etc/cron.d/asigra-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/sh

#TODO
# - remove the empty lines in INDEX.n

UPDATE="https://asigra-f611.kxcdn.com/14.1"
FILE=INDEX.prev
DLDIR=download
IP=`cat /root/dhcpip`

# Check for if prev index exist if not create
if [ -f "$FILE" ]; then
else
touch $FILE
fi

# Check for DLDIR
if [ -f "$DLDIR" ]; then
else
mkdir $DLDIR
fi

#fetch index
curl $UPDATE/INDEX > INDEX
if [ "$?" -gt 0 ]
then
echo "Error downloading INDEX"
exit 1
fi

#compare if a new file is there
diff -ruN INDEX.prev INDEX > INDEX.n

#cut all unneded stuff out
cut -d: -f4- INDEX.n > INDEX.new

#We need prev. index to compare
mv INDEX INDEX.prev

#When INDEX.new is empty we dont need to do anything
if [ ! -s "INDEX.new" ] ; then return 0 ; fi


#Get all files from the new index
#Curl explaintion: we will retry 5 times or a maximum of 40 seconds with a connection timeout of 5 seconds, and no exponential backoff policy
for i in $(cat INDEX.new)
do
cd $DLDIR && { curl \
-O $UPDATE/$i \
--fail-early \
--connect-timeout 5 \
--max-time 300 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

300 seconds is enough to download 3.6GiB?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thats always dependents on network and location (home or dc), do you think 1200 sec (20 min) would be a good time ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try 2 hours. 10mbit/s connections are still popular around the world.

--retry 5 \
--retry-delay 0 \
--retry-max-time 40 ;\
cd -; }
if [ "$?" -ne 0 ]
then
echo "Error downloading distfiles"
exit
fi
done

#DS-Update
for dsup in download/Update*.zip
do
if [ -f "$dsup" ]; then
unzip $DLDIR/DS-System_*.zip -d $PWD/$DLDIR
fi
done


#DS-System hotfix
for dssys in $DLDIR/DS-System_*.zip
do
if [ -f "$dssys" ]; then

unzip $DLDIR/DS-System_*.zip -d $PWD/$DLDIR
pkg add $DLDIR/DS-System_*/dssystem-*.txz
fi
done

#Webinterface hotfix
for dsop in $DLDIR/DS-Operator_FreeBSD*
do
if [ -f "$dsop" ]; then

#extract the web stuff to the right dir
unzip -o $DLDIR/DS-Operator*.zip -d /usr/local/www/asigra

#make sure we have the right IP after the upgrade
sed -i.bak -E "s|codebase=\"(.+)\"|codebase=\"http://$IP/asigra/\"|" /usr/local/www/asigra/DSOP.jnlp
rm -f /usr/local/www/asigra/DSOP.jnlp.bak
fi
done

#Cleanup
rm -rf $DLDIR

#Restart services
# workaround for broken rc.d script
pkill dssystem_dc
sleep 15;
/usr/local/etc/rc.d/dssystem start