[myHD] PRE download Ubuntu env. (reduce QPKG install elapse time)

New total application manager for HD_Station
Post Reply
User avatar
philippe
Site Admin
Posts: 150
Joined: Mon Apr 16, 2018 3:10 pm
Has thanked: 2 times
Been thanked: 15 times

[myHD] PRE download Ubuntu env. (reduce QPKG install elapse time)

Post by philippe » Wed Oct 10, 2018 3:50 pm

Hi,

Please find in code section hereafter a shell script to pre-download Ubuntu environment to reduce elapse time during myHD QPKG installation
or prepare a switch to 1804 from 1604
myHD QPKG normal installation process is :
... start extracting myHD QPKG
... install
... start myHD.sh (the start-stop script) at end of the installation
... myHD.sh look in /share/Public/myHD_delivery if files are already present
... IF YES
... ... check that it's the last version (a short file to download
... .... if check is OK ... start continue without downloading Ubuntu 1604 or 1804 BUT using the version in the folder
... IF NO (files not present or check invalid)
... ... myHD.sh start downloading the files

At end (without error in myHD.sh) ... the QPKG install is considered as terminated (so you have to wait a long time (depend of your Internet access) before ending the QPKG install (in App. Center for ex.)

pre-downloading files permit to reduce drastically this time
... pre-download (long or not) use 1804 or 1604 to choice the environment
... create the file to select 1804 if you don't start by default with 1604
... install myHD QPKG
... start myHD.sh
... ... NO download
... end of myHD.sh
so short in time ... )

How-to use the shell script :
create a (linux) file where you want on QNAP and copy into the code hereafter
add execute bit for the shell (chmod a+x name_of_your_file)
execute the shell script with parameter : 1804 or 1604 (can be used also to prepare a switch Ubuntu version

Code: Select all

#!/bin/sh
NS_HOST="myHD"
UVER="1604"
BASE_URL="http://www.father-mande.ovh/Q/other/"
DIR_DELIVERY=/share/Public/${NS_HOST}_delivery

download_test(){
### now download if need ${FILE}
	if [ ! -e ${DIR_DELIVERY}/${FILE} ] ; then
		$WGET -O ${FILE} ${BASE_URL}/${FILE}
		### test if checksum is correct
		if [ "$(/bin/md5sum ${DIR_DELIVERY}/${FILE} | cut -f 1 -d " ")" = "$(cat ${DIR_DELIVERY}/$LIST | grep ${FILE} | cut -f 1 -d " ")" ] ; then
			echo "${FILE} is good and downloaded"
		else
			rm -f ${DIR_DELIVERY}/${FILE}
			$WGET -O ${FILE} ${BASE_URL}/${FILE}
			if [ $? -ne 0 ] ; then
				echo "Hum seems ${FILE} can't be downloaded "
				exit 1
			fi
		fi
	else
		### test checksum
		if [ "$(/bin/md5sum ${DIR_DELIVERY}/${FILE} | cut -f 1 -d " ")" = "$(cat ${DIR_DELIVERY}/$LIST | grep ${FILE} | cut -f 1 -d " ")" ] ; then
			echo "${FILE} is good and downloaded"
		else
			rm -f ${DIR_DELIVERY}/${FILE}
			$WGET -O ${FILE} ${BASE_URL}/${FILE}
			if [ $? -ne 0 ] ; then
				echo "Hum seems ${FILE} can't be downloaded "
				exit 1
			fi
		fi
	fi
}

if [ ! -z "${1}" ] ; then
	if [ "${1}" = "1604" -o "${1}" = "1804" ] ; then
		UVER=${1}
		LIST="delivery_${UVER}.list"
	else
		echo "First parameters MUST be Ubuntu version not : ${1}"
		exit 1
	fi
else
	echo "First parameters MUST be Ubuntu version supported by ${NS_HOST}"
	exit 1
fi
/usr/bin/which wget
if [ $? -ne 0 ] ; then
	echo "Hum wget is not present in the NAS ???"
	exit 1
fi 

WGET=$(/usr/bin/which wget)
PWD=$(pwd)

	if [ ! -e ${DIR_DELIVERY} ] ; then
		mkdir ${DIR_DELIVERY}
	fi
	cd ${DIR_DELIVERY}
	if [ ! -e ${DIR_DELIVERY}/$LIST ] ; then
		$WGET -O $LIST ${BASE_URL}/$LIST
		if [ $? -ne 0 ] ; then
			echo "Hm download error file : $LIST ... check or download manually"
			exit 1
		fi
	fi
	### verify if prelaoded the complete delivery_${UVER}.tgz
	DL_FULL="FALSE"
	FILE="${NS_HOST}_delivery_${UVER}.tgz"
	if [ -e ${DIR_DELIVERY}/${FILE} ] ; then
		if [ "$(/bin/md5sum ${DIR_DELIVERY}/${FILE} | cut -f 1 -d " ")" = "$(cat ${DIR_DELIVERY}/$LIST | grep ${FILE} | cut -f 1 -d " ")" ] ; then
			echo "file $FILE exist and are at the good version"
			DL_FULL="TRUE"
		fi
	fi
	DL_SCRIPT="FALSE"
	FILE=${NS_HOST}_${UVER}_delivery_scripts.tgz
	if [ -e ${DIR_DELIVERY}/${FILE} ] ; then
		if [ "$(/bin/md5sum ${DIR_DELIVERY}/${FILE} | cut -f 1 -d " ")" = "$(cat ${DIR_DELIVERY}/$LIST | grep ${FILE} | cut -f 1 -d " ")" ] ; then
			echo "file $FILE exist and are at the good version"
			DL_SCRIPT="TRUE"
		fi
	else
		download_test
	fi
	if [ "$DL_FULL" = "TRUE" ] ; then
		echo "${NS_HOST}_delivery_${UVER}.tgz is already downloed and at good version"
	else
		if [ -z "$2" ] ; then
			### here download part and generate tgz ...
			DL_PART="FALSE"
			NO_MORE="FALSE"
			for SUFFIX in aa ab ac ad ae af ag ah ai aj ak
			do
				grep ${NS_HOST}_delivery_${UVER}_${SUFFIX} ${DIR_DELIVERY}/$LIST
				if [ $? -eq 0 ] ; then
					FILE=${NS_HOST}_delivery_${UVER}_${SUFFIX}
					download_test
				else
					NO_MORE="TRUE"
				fi
				if [ "$NO_MORE" = "TRUE" ] ; then
					break
				fi
			done
			DL_PART="TRUE"
		else
			### download full environment in one file 
			FILE="${NS_HOST}_delivery_${UVER}.tgz"
			download_test
			DL_FULL="TRUE"
		fi
		## if you are here all part or full download works as well
		if [ "$DL_PART" = "TRUE" ] ; then
			cat ${NS_HOST}_delivery_${UVER}_* > ${NS_HOST}_delivery_${UVER}.tgz
		fi
		### last verification
		FILE="${NS_HOST}_delivery_${UVER}.tgz"
		if [ "$(/bin/md5sum ${DIR_DELIVERY}/${FILE} | cut -f 1 -d " ")" = "$(cat ${DIR_DELIVERY}/$LIST | grep ${FILE} | cut -f 1 -d " ")" ] ; then
			echo "${FILE} is good and downloaded"
		else
			echo "Hum download is complete but md5 is false strange ???"
			exit 1
		fi
	fi
echo "Downloaded ... finished ..."
or get the tar file hereafter
pre_download_myHD.sh.tar
(10 KiB) Downloaded 8 times
Copy the tar file to /share/Public (your share Public)
open a console and do
cd /share/Public
tar xf pre_download_myHD.sh.tar

execute the shell
./pre_download_myHD.sh 1804|1604
remove after
rm -f pre_download_myHD.sh.tar pre_download_myHD.sh

Philippe.
QNAP / Asustor package integrator
Post Reply