Skip to content

Commit

Permalink
check for updates (and update) upon launching nextcloudpi-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Apr 3, 2017
1 parent 138fecc commit 9b5cd81
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
9 changes: 9 additions & 0 deletions bin/ncp-check-updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
cat > /usr/local/bin/ncp-check-updates <<'EOF'
VERFILE=/var/run/.ncp-latest-version
if ncp-test-updates; then
echo -e "\nNextCloudPi \e[1m$( cat $VERFILE )\e[0m available!!"
echo -e "update through 'nextcloudpi-config' or type 'sudo ncp-update'"
else
echo -e "\nNextCloudPi \e[1m$( cat /usr/local/etc/ncp-version )\e[0m is up to date"
fi
24 changes: 24 additions & 0 deletions bin/ncp-test-updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

NEED_UPDATE=false
VERFILE=/var/run/.ncp-latest-version

if test -f $VERFILE && grep -qP "v\d+\.\d+\.\d+" $VERFILE; then

MAJOR=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f1 )
MINOR=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f2 )
PATCH=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f3 )

MAJ=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f1 )
MIN=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f2 )
PAT=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f3 )

if [[ $MAJOR > $MAJ ]]; then
NEED_UPDATE=true
elif [[ $MAJOR == $MAJ ]] && [[ $MINOR > $MIN ]]; then
NEED_UPDATE=true
elif [[ $MAJOR == $MAJ ]] && [[ $MINOR == $MIN ]] && [[ $PATCH > $PAT ]]; then
NEED_UPDATE=true
fi
fi
[[ "$NEED_UPDATE" == "true" ]] && exit 0
22 changes: 19 additions & 3 deletions bin/nextcloudpi-config
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,35 @@
# More at https://ownyourbits.com/2017/03/13/nextcloudpi-gets-nextcloudpi-config/
#

CONFDIR=/usr/local/etc/nextcloudpi-config.d/

source /usr/local/etc/library.sh

function nextcloud-config()
{
local DIALOG_OK=0
local LIST=()
local VERSION=$( cat /usr/local/etc/ncp-version )
local VERFILE=/var/run/.ncp-latest-version
local BACKTITLE="NextCloudPi configuration ver. $VERSION"
local CONFDIR=/usr/local/etc/nextcloudpi-config.d/

# save latest version if it has never done before
test -f $VERFILE || ncp-check-version

# ask for update if outdated
ncp-test-updates && \
whiptail --backtitle "$BACKTITLE" \
--title "NextCloudPi update available" \
--clear --yesno "Update to $( cat $VERFILE )?" \
10 40
[[ $? -eq $DIALOG_OK ]] && ncp-update

# launch the selection menu
for item in $CONFDIR/*.sh; do
local DESC=$( grep "DESCRIPTION=" $item | sed 's|^DESCRIPTION="||;s|"$||' )
LIST+=( $( basename $item .sh ) "$DESC" )
done
local script
script=$( whiptail --backtitle "NextCloudPi configuration" \
script=$( whiptail --backtitle "$BACKTITLE" \
--title "NextCloudPi Software Configuration Tool (nextcloudpi-config)" \
--cancel-button Finish --ok-button Select \
--menu "Select program to configure and activate:" 20 100 10 \
Expand All @@ -34,6 +49,7 @@ function nextcloud-config()

[[ $? -ne $DIALOG_OK ]] || [[ "$script" == "" ]] && return 0

# launch selected script
configure_script $script.sh
}

Expand Down
36 changes: 1 addition & 35 deletions nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,41 +257,6 @@ EOF
##########################################
$APTINSTALL git

cat > /usr/local/bin/ncp-check-updates <<'EOF'
#!/bin/bash
NEED_UPDATE=false
VERFILE=/var/run/.ncp-latest-version
if test -f $VERFILE && grep -qP "v\d+\.\d+\.\d+" $VERFILE; then
MAJOR=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f1 )
MINOR=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f2 )
PATCH=$( grep -oP "\d+\.\d+\.\d+" $VERFILE | cut -d. -f3 )
MAJ=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f1 )
MIN=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f2 )
PAT=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f3 )
if [[ $MAJOR > $MAJ ]]; then
NEED_UPDATE=true
elif [[ $MAJOR == $MAJ ]] && [[ $MINOR > $MIN ]]; then
NEED_UPDATE=true
elif [[ $MAJOR == $MAJ ]] && [[ $MINOR == $MIN ]] && [[ $PATCH > $PAT ]]; then
NEED_UPDATE=true
fi
fi
if $NEED_UPDATE; then
echo -e "\nNextCloudPi \e[1m$( cat $VERFILE )\e[0m available!!"
echo -e "update through 'nextcloudpi-config' or type 'sudo ncp-update'"
else
echo -e "\nNextCloudPi \e[1m$( cat /usr/local/etc/ncp-version )\e[0m is up to date"
fi
EOF
chmod a+x /usr/local/bin/ncp-check-updates


cat > /etc/cron.daily/ncp-check-version <<EOF
#!/bin/sh
/usr/local/bin/ncp-check-version
Expand Down Expand Up @@ -332,6 +297,7 @@ echo -e "NextCloudPi updated to version \e[1m$VER\e[0m"
EOF
chmod a+x /usr/local/bin/ncp-update

# update to latest version from github as part of the build process
/usr/local/bin/ncp-update
fi
}
Expand Down

0 comments on commit 9b5cd81

Please sign in to comment.