Project .install: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "<pre> #!/bin/bash # # Installation script. To be executed on initial installation or upgrade, from the bin directory. # link_name=replace_with_application_name remove_older_...")
 
No edit summary
 
Line 6: Line 6:
#
#


link_name=replace_with_application_name
application_name=os-stats
link_name=${application_name}
remove_older_releases=true
remove_older_releases=true


Line 40: Line 41:
function remove-older-releases() {
function remove-older-releases() {


     for i in $(dirname $0)/../../replace_with_application_name-*; do
     for i in $(dirname $0)/../../${application_name}-*; do


         [ ! -d ${i} ] && continue
         [ ! -d ${i} ] && continue

Latest revision as of 21:04, 12 May 2017

#!/bin/bash

#
# Installation script. To be executed on initial installation or upgrade, from the bin directory.
#

application_name=os-stats
link_name=${application_name}
remove_older_releases=true

release_directory=$(basename $(cd $(dirname $0)/..; pwd))

function main() {

    link-to-installation-directory
    configure-user-environment
    ${remove_older_releases} && remove-older-releases
}

function link-to-installation-directory() {

    local link=$(dirname $0)/../../${link_name}

    if [ -h ${link} ]; then

        # the link exists, must be removed
        rm ${link} || { echo "failed to remove the old link ${link}" 1>&2; exit 1; }
    fi

    (cd $(dirname $0)/../..; ln -s ./${release_directory} ${link_name}) || \
        { "failed to link to ${release_directory}" 1>&2; exit 1; }
}

function configure-user-environment() {

    # TODO
    echo "" > /dev/null
}

function remove-older-releases() {

    for i in $(dirname $0)/../../${application_name}-*; do

        [ ! -d ${i} ] && continue

        #
        # skip ourselves
        #

        [ $(basename ${i}) = ${release_directory} ] && continue;

        #
        # remove everything else
        #

        rm -r ${i} || { echo "failed to remove older release ${i}" 1>&2; exit 1; }

    done
}

main $@