Skip to content

Commit

Permalink
Updated build and app scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopadilha committed Jul 9, 2015
1 parent 421a542 commit bf213a0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -24,7 +24,7 @@ exec 2> >(tee -a "${logfile}" >&2)
### environment setup ###
source crosscompile.sh
export NAME="$(basename ${PWD})"
export DEST="/mnt/DroboFS/Shares/DroboApps/${NAME}"
export DEST="${BUILD_DEST:-/mnt/DroboFS/Shares/DroboApps/${NAME}}"
export DEPS="${PWD}/target/install"
export CFLAGS="${CFLAGS:-} -Os -fPIC"
export CXXFLAGS="${CXXFLAGS:-} ${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion crosscompile.sh
@@ -1,5 +1,5 @@
export DROBO="5n"
export TOOLCHAIN=~/xtools/toolchain/${DROBO}
export TOOLCHAIN="${BUILD_TOOLCHAIN:-${HOME}/xtools/toolchain/${DROBO}}"
export ARCH="armv7-a"
export HOST="arm-marvell-linux-gnueabi"
export PATH="${TOOLCHAIN}/bin:~/bin:$PATH"
Expand Down
1 change: 0 additions & 1 deletion src/dest/install.sh
Expand Up @@ -11,7 +11,6 @@ exec 3>&1 4>&2 1>> "${logfile}" 2>&1
echo "$(date +"%Y-%m-%d %H-%M-%S"):" "${0}" "${@}"
set -o errexit # exit on uncaught error code
set -o nounset # exit on unset variable
set -o pipefail # propagate last error code on pipe
set -o xtrace # enable script tracing

# copy default configuration files
Expand Down
68 changes: 46 additions & 22 deletions src/dest/libexec/service.subr
Expand Up @@ -44,7 +44,6 @@ MKTEMP=/bin/mktemp
WC=/usr/bin/wc
AWK=/usr/bin/awk
FIND=/usr/bin/find
TAIL=/usr/bin/tail
WGET=/usr/bin/wget
DIFF=/usr/bin/diff
BASENAME=/usr/bin/basename
Expand Down Expand Up @@ -78,19 +77,6 @@ if [ -f "${SERVICE_WEBUI}" ]; then
fi


# _tail_file
# $1: file name
# $2: nr of lines
_tail_file()
{
if [ "$($WC -l "${1}" | $AWK '{print $1}')" -gt "${2}" ]; then
$TAIL -n "${2}" "${1}" > "${1}.tail"
$CP "${1}.tail" "${1}"
$RM "${1}.tail"
fi
}


# _list_droboapps
# return: a space-separated list of names of all installed DroboApps.
_list_droboapps()
Expand Down Expand Up @@ -366,6 +352,46 @@ _get_depends()
}


# _tgz_contains_file
# $1: tgz file path
# $2: filename without path
# return: 0 if tgz contains file, 1 if not
# This function looks in the tgzs "root" folder for the given filename.
# It will return 0 if "filename" or "./filename" are present in the tgz.
_tgz_contains_file()
{
local _tgz="${1}"
local _file="${2}"

if $TAR -ztf "${_tgz}" "${_file}" > /dev/null 2>&1; then
return 0
elif $TAR -ztf "${_tgz}" "./${_file}" > /dev/null 2>&1; then
return 0
fi
return 1
}


# _tgz_extract_file
# $1: tgz file path
# $2: filename without path
# $@: further tgz options, such as -O or -C
# return: 0 if tgz contains file, 1 if not
# This function looks in the tgzs "root" folder for the given filename.
# It will return 0 if "filename" or "./filename" are present in the tgz.
_tgz_extract_file()
{
local _tgz="${1}"
shift
local _file="${1}"
shift

if ! $TAR -zxf "${_tgz}" "${_file}" "${@}" 2> /dev/null; then
$TAR -zxf "${_tgz}" "./${_file}" "${@}" 2> /dev/null
fi
}


# _extract_depends
# $1: "update" or "install" or "service"
# $2: TGZ_FILE file path
Expand All @@ -378,9 +404,8 @@ _extract_depends()
local _depends=""

_tgzName="$($BASENAME "${_tgz}" .tgz)"
if $TAR -ztf "${_tgz}" service.sh > /dev/null 2>&1; then
# The file exists.
_depends="$($TAR -Ozxf "${_tgz}" service.sh | $GREP '^[Dd]epends=')"
if _tgz_contains_file "${_tgz}" "service.sh"; then
_depends="$(_tgz_extract_file "${_tgz}" "service.sh" -O | $GREP '^[Dd]epends=')"
if [ -n "${_depends}" ]; then
# There is a depends in service.sh
_depends="$(echo "${_depends}" | $SED -e 's/^[Dd]epends=//' -e 's/\"//g')"
Expand Down Expand Up @@ -718,7 +743,7 @@ _download_app()
_tmpWgetDir="$($MKTEMP -dt -p "${_tmpDir}" "${1}.XXXXXX")"

if [ -z "${_tmpWgetDir}" ]; then
echo "Unable to create a temporary folder." >&2
eval echo \"Unable to create a temporary download folder.\" ${STDERR}
return 1
fi

Expand All @@ -728,7 +753,7 @@ _download_app()
$CP "${_tmpWgetDir}/${1}.tgz" "${DROBOAPPS_DIR}/"
$RM -rf "${_tmpWgetDir}"
else
echo "Unable to download ${1}. Please check ${_tmpWgetDir}/wget.log for more information." >&2
eval echo \"Unable to download ${1}. Please check ${_tmpWgetDir}/wget.log for more information.\" ${STDERR}
return ${_result};
fi
}
Expand Down Expand Up @@ -776,9 +801,8 @@ _install_app()
# untar on top of the existing install.
if [ -d "${_appDir}" ]; then
eval echo \"Upgrading ${_tgzName}.\" ${STDOUT}
if $TAR -ztf "${_tgz}" update.sh > /dev/null 2>&1; then
# There's an update.sh
$TAR -zxf "${_tgz}" update.sh -C "${_appDir}"
if _tgz_contains_file "${_tgz}" "update.sh"; then
_tgz_extract_file "${_tgz}" "update.sh" -C "${_appDir}"
# Launch the update script.
(cd "${_appDir}" && $SH "${_appDir}/update.sh" && $RM -f "${_appDir}/update.sh")
fi
Expand Down
12 changes: 7 additions & 5 deletions src/dest/service.sh
Expand Up @@ -21,6 +21,7 @@ errorfile="${tmp_dir}/error.txt"

# backwards compatibility
if [ -z "${FRAMEWORK_VERSION:-}" ]; then
framework_version="2.0"
. "${prog_dir}/libexec/service.subr"
fi

Expand All @@ -32,22 +33,23 @@ elif [ -h "/usr/bin/perl" ] && [ "$(readlink /usr/bin/perl)" != "${prog_dir}/bin
fi

start() {
rm -f "${errorfile}"
echo "Perl 5 is configured." > "${statusfile}"
touch "${pidfile}"
return 0
}

is_running() {
return 0
}

is_stopped() {
return 0
[ -f "${pidfile}" ]
}

stop() {
rm -f "${pidfile}"
return 0
}

force_stop() {
rm -f "${pidfile}"
return 0
}

Expand Down
1 change: 0 additions & 1 deletion src/dest/uninstall.sh
Expand Up @@ -11,7 +11,6 @@ exec 3>&1 4>&2 1>> "${logfile}" 2>&1
echo "$(date +"%Y-%m-%d %H-%M-%S"):" "${0}" "${@}"
set -o errexit # exit on uncaught error code
set -o nounset # exit on unset variable
set -o pipefail # propagate last error code on pipe
set -o xtrace # enable script tracing

if [ -h "/usr/bin/perl" ] && [ "$(readlink /usr/bin/perl)" = "${prog_dir}/bin/perl" ]; then
Expand Down

0 comments on commit bf213a0

Please sign in to comment.