#!/bin/bash ## script: ./publish-ezfit-latest.sh # #------------------------------------------------------------------------------ # Description: Publish ezFIT installer to AutoUpdate website # Usage: # Format: # Current date: % ./publish-ezfit-latest.sh # Arbitrary date: % ./publish-ezfit-latest.sh [YYYY-MMDD] # YYYY - Year (4 digits). # MM - Month (always 2 digits, including leading zero if necessary). # DD - Day of month (always 2 digitis, including leading zero if necessary). # Example: % ./publish-ezfit-latest.sh 2014-0422 #------------------------------------------------------------------------------ #----------------------------- # User Defined Variables #----------------------------- TARGETORG=( "Audina" "Auditiva" "iEar" "MDHearingAid" "Acme" ) TARGETAPP=( "ezfit" "fitpro" "accufit" "mdtune" "acmefitapp" ) SOURCEDIR="/var/www/downloads/prototypes" TARGETDIR="/var/www/downloads/ezfit" #SYSDATESTAMP="2013-0117" SYSDATESTAMP=$(date +%Y-%m%d) SYSDATEYEAR=$(date +%Y) # Use command line argument to override variables if [ -n "$1" ] then echo "Current version $SYSDATESTAMP will be ovewritten with $1" SYSDATESTAMP="$1" SYSDATEYEAR=${SYSDATESTAMP:0:4} fi # Try to create TargetDir if it does not exist if ! cd $TARGETDIR; then mkdir $TARGETDIR fi totalOrg=${#TARGETORG[*]} idx=0 while [ $idx -lt $totalOrg ]; do ORG=${TARGETORG[$idx]} APP=${TARGETAPP[$idx]} #echo "Processing company $ORG and app $APP" # Perform operations if TargetDir exists if cd $TARGETDIR; then #----------------------------- # Link current ezfit installer to ezfit-latest.exe #----------------------------- rm $APP-$ORG-$SYSDATEYEAR-latest.exe echo "Copying from $SOURCEDIR to $TARGETDIR . . ." #ln -s $1 ezfit-setup-2012-latest.exe if [ -n "$1" ]; then cp $SOURCEDIR/ezfit-setup-$ORG-$SYSDATESTAMP.exe $APP-$ORG-$SYSDATEYEAR-latest.exe else cp $SOURCEDIR/ezfit-$ORG-$SYSDATEYEAR-latest.exe $APP-$ORG-$SYSDATEYEAR-latest.exe fi chown www-data:web $APP-$ORG-$SYSDATEYEAR-latest.exe echo "Success copying version $SYSDATEYEAR to $APP-$ORG-$SYSDATEYEAR-latest.exe" else echo "Failed to link version $SYSDATEYEAR to $APP-$ORG-$SYSDATEYEAR-latest.exe" fi let idx=idx+1 done #------------------------------------------------ # GetDate #------------------------------------------------ function GetDate() { SYSDATE=$(date +%Y%m%d) } #------------------------------------------------ # GetDateTime #------------------------------------------------ function GetDateTime() { SYSDATETIME=$(date +%Y%m%d-%H%M) } #------------------------------------------------ # GetDateStamp #------------------------------------------------ function GetDateStamp() { SYSDATESTAMP=$(date +%Y-%m%d) } #------------------------------------------------ # GetDate #------------------------------------------------ function GetYear() { SYSDATEYEAR=$(date +%Y) } #------------------------------------------------ # DisplayDate #------------------------------------------------ function DisplayDate() { if [ ! -z $SYSDATE ]; then echo $SYSDATE else echo "SYSDATE not defined. Define using GetDate()" fi }