From c60ee017ab7a5e5cbbcf7166e87806a878be0e11 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Tue, 4 Apr 2017 18:25:23 +0200 Subject: protect ncp-update from self modifications --- bin/ncp-update | 29 ++++++++++++++++------------- nextcloud.sh | 29 ++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/bin/ncp-update b/bin/ncp-update index 12089bf1..c387d515 100755 --- a/bin/ncp-update +++ b/bin/ncp-update @@ -2,20 +2,23 @@ # update latest NextCloudPi code from github -ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } -echo -e "Downloading updates" -rm -rf /tmp/ncp-update-tmp -git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 -cd /tmp/ncp-update-tmp +{ + ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } + echo -e "Downloading updates" + rm -rf /tmp/ncp-update-tmp + git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 + cd /tmp/ncp-update-tmp -echo -e "Performing updates" -./update.sh + echo -e "Performing updates" + ./update.sh -VER=$( git describe --always --tags ) -echo $VER > /usr/local/etc/ncp-version -echo $VER > /var/run/.ncp-latest-version + VER=$( git describe --always --tags ) + echo $VER > /usr/local/etc/ncp-version + echo $VER > /var/run/.ncp-latest-version -cd / -rm -rf /tmp/ncp-update-tmp + cd / + rm -rf /tmp/ncp-update-tmp -echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" + echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" + exit +} # force to read the whole thing into memory, as its contents might change in update.sh diff --git a/nextcloud.sh b/nextcloud.sh index 46059c6f..c5be3168 100755 --- a/nextcloud.sh +++ b/nextcloud.sh @@ -266,23 +266,26 @@ EOF cat > /usr/local/bin/ncp-update <<'EOF' #!/bin/bash -ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } -echo -e "Downloading updates" -rm -rf /tmp/ncp-update-tmp -git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 -cd /tmp/ncp-update-tmp +{ + ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } + echo -e "Downloading updates" + rm -rf /tmp/ncp-update-tmp + git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 + cd /tmp/ncp-update-tmp -echo -e "Performing updates" -./update.sh + echo -e "Performing updates" + ./update.sh -VER=$( git describe --always --tags ) -echo $VER > /usr/local/etc/ncp-version -echo $VER > /var/run/.ncp-latest-version + VER=$( git describe --always --tags ) + echo $VER > /usr/local/etc/ncp-version + echo $VER > /var/run/.ncp-latest-version -cd / -rm -rf /tmp/ncp-update-tmp + cd / + rm -rf /tmp/ncp-update-tmp -echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" + echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" + exit +} EOF chmod a+x /usr/local/bin/ncp-update -- cgit v1.2.3