From 06c22a63fca87919e6f53948ae3acb0931102ce9 Mon Sep 17 00:00:00 2001
From: "alexandr.kravchenko" <alexander.kravchenko@demlabs.net>
Date: Sun, 31 May 2020 15:18:56 +0500
Subject: [PATCH] Fixed autopublication script, auto-updating links

---
 .../essentials/node-stretch-latest/.htaccess       |  1 +
 .../essentials/node-stretch-latest/index.php       |  4 ++++
 .../general/essentials/weblink-latest/.htaccess    |  1 +
 .../general/essentials/weblink-latest/index.php    |  4 ++++
 prod_build/linux/debian/scripts/deploy.sh          | 14 ++++++++++----
 5 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 prod_build/general/essentials/node-stretch-latest/.htaccess
 create mode 100644 prod_build/general/essentials/node-stretch-latest/index.php
 create mode 100644 prod_build/general/essentials/weblink-latest/.htaccess
 create mode 100644 prod_build/general/essentials/weblink-latest/index.php

diff --git a/prod_build/general/essentials/node-stretch-latest/.htaccess b/prod_build/general/essentials/node-stretch-latest/.htaccess
new file mode 100644
index 00000000..e2d575a1
--- /dev/null
+++ b/prod_build/general/essentials/node-stretch-latest/.htaccess
@@ -0,0 +1 @@
+DirectoryIndex index.php index.html index.htm
diff --git a/prod_build/general/essentials/node-stretch-latest/index.php b/prod_build/general/essentials/node-stretch-latest/index.php
new file mode 100644
index 00000000..97a81ed6
--- /dev/null
+++ b/prod_build/general/essentials/node-stretch-latest/index.php
@@ -0,0 +1,4 @@
+<script>
+window.onload = function(){
+     document.location = '../cellframe-node-3.4-2-amd64-stretch.deb';}
+</script>
diff --git a/prod_build/general/essentials/weblink-latest/.htaccess b/prod_build/general/essentials/weblink-latest/.htaccess
new file mode 100644
index 00000000..e2d575a1
--- /dev/null
+++ b/prod_build/general/essentials/weblink-latest/.htaccess
@@ -0,0 +1 @@
+DirectoryIndex index.php index.html index.htm
diff --git a/prod_build/general/essentials/weblink-latest/index.php b/prod_build/general/essentials/weblink-latest/index.php
new file mode 100644
index 00000000..7f01b045
--- /dev/null
+++ b/prod_build/general/essentials/weblink-latest/index.php
@@ -0,0 +1,4 @@
+<script>
+window.onload = function(){
+     document.location = '../cellframe-node-3.2-2-Debian-10-amd64-buster.deb';}
+</script>
diff --git a/prod_build/linux/debian/scripts/deploy.sh b/prod_build/linux/debian/scripts/deploy.sh
index 09973c8a..6eeeee9b 100755
--- a/prod_build/linux/debian/scripts/deploy.sh
+++ b/prod_build/linux/debian/scripts/deploy.sh
@@ -19,19 +19,25 @@ PKGFILES=$(ls . | grep .deb)
 [[ $ONBUILDSERVER == 0 ]] && scp -i $CELLFRAME_REPO_KEY ../prod_build/linux/debian/scripts/publish_remote/reprepro.sh "$CELLFRAME_REPO_CREDS:~/tmp/"
 for pkgfile in $PKGFILES; do
 	pkgname=$(echo $pkgfile | sed 's/.deb$//')
+	pkgname_public=$(echo $pkgname | cut -d '-' -f1-4,7-) #cutting away Debian-9.12
+	pkgname_weblink="$(echo $pkgname | cut -d '-' -f2,8 )-latest" #leaving only necessary entries
 	mv $pkgfile $wd/$PACKAGE_PATH/$pkgname$MOD.deb || { echo "[ERR] Something went wrong in publishing the package. Now aborting."; exit -4; }
 	CODENAME=$(echo $pkgname | rev | cut -d '-' -f1 | rev)
+	cp -r ../prod_build/general/essentials/weblink-latest ../prod_build/general/essentials/$pkgname_weblink
+	sed -i "/document/s/cellframe.*deb/$pkgname_public$MOD.deb/" ../prod_build/general/essentials/$pkgname_weblink/index.php
 	if [[ $ONBUILDSERVER == 0 ]]; then
 	#REPREPRO and file_cellframe_services
 		scp -i $CELLFRAME_REPO_KEY $wd/$PACKAGE_PATH/$pkgname$MOD.deb "$CELLFRAME_REPO_CREDS:~/tmp/apt/"
-		ssh -i $CELLFRAME_REPO_KEY "$CELLFRAME_REPO_CREDS" "chmod +x ~/tmp/reprepro.sh && ~/tmp/reprepro.sh main $CODENAME ~/tmp/apt/$pkgname$MOD.deb $CELLFRAME_REPO_PATH"
-		scp -i $CELLFRAME_REPO_KEY $wd/$PACKAGE_PATH/$pkgname$MOD.deb "$CELLFRAME_FILESERVER_CREDS:$CELLFRAME_FILESERVER_PATH/"
-		ssh -i $CELLFRAME_REPO_KEY "$CELLFRAME_FILESERVER_CREDS" "ln -sf $CELLFRAME_FILESERVER_PATH/$pkgname$MOD.deb $CELLFRAME_FILESERVER_PATH/$pkgname$MOD-latest.deb"
+		ssh -i $CELLFRAME_REPO_KEY "$CELLFRAME_REPO_CREDS" "chmod +x ~/tmp/reprepro.sh && ~/tmp/reprepro.sh main $CODENAME ~/tmp/apt/$pkgname_public$MOD.deb $CELLFRAME_REPO_PATH"
+		scp -i $CELLFRAME_REPO_KEY $wd/$PACKAGE_PATH/$pkgname$MOD.deb "$CELLFRAME_FILESERVER_CREDS:$CELLFRAME_FILESERVER_PATH/$pkgname_public$MOD.deb"
+		scp -r -i $CELLFRAME_REPO_KEY ../prod_build/general/essentials/$pkgname_weblink "$CELLFRAME_FILESERVER_CREDS:$CELLFRAME_FILESERVER_PATH/"
+#		ssh -i $CELLFRAME_REPO_KEY "$CELLFRAME_FILESERVER_CREDS" "ln -sf $CELLFRAME_FILESERVER_PATH/$pkgname$MOD.deb $CELLFRAME_FILESERVER_PATH/$pkgname$MOD-latest.deb"
 	fi
+	rm -r ../prod_build/general/essentials/$pkgname_weblink
 done
 [[ $ONBUILDSERVER == 0 ]] && ssh -i $CELLFRAME_REPO_KEY "$CELLFRAME_REPO_CREDS" "rm -v ~/tmp/reprepro.sh"
 
-	export -n "UPDVER"
+#	export -n "UPDVER"
 cd ..
 exit 0
 #symlink name-actual to the latest version.
-- 
GitLab