Commit df437298 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm play: refactoring check script

parent 979183d4
...@@ -286,7 +286,7 @@ __epm_play_update() ...@@ -286,7 +286,7 @@ __epm_play_update()
continue continue
fi fi
prescription="$i" prescription="$i"
if ! __check_play_script $prescription ; then if ! has_play_script $prescription ; then
warning "Can't find executable play script for $prescription. Try epm play --remove $prescription if you don't need it anymore." warning "Can't find executable play script for $prescription. Try epm play --remove $prescription if you don't need it anymore."
RES=1 RES=1
continue continue
...@@ -303,19 +303,13 @@ __epm_play_install_one() ...@@ -303,19 +303,13 @@ __epm_play_install_one()
local prescription="$1" local prescription="$1"
shift shift
if __epm_is_shell_script "$prescription" ; then if has_play_script "$prescription" ; then
# direct run play script
__epm_play_run_script "$prescription" --run "$@" || fatal "There was some error during install the application."
return
fi
if __check_play_script "$prescription" ; then
#__is_app_installed "$prescription" && info "$$prescription is already installed (use --remove to remove)" && exit 1 #__is_app_installed "$prescription" && info "$$prescription is already installed (use --remove to remove)" && exit 1
__epm_play_run "$prescription" --run "$@" && __save_installed_app "$prescription" || fatal "There was some error during install the application." __epm_play_run "$prescription" --run "$@" && __save_installed_app "$prescription" || fatal "There was some error during install the application."
else else
opsdir=$psdir local opsdir=$psdir
psdir=$prsdir psdir=$prsdir
__check_play_script "$prescription" || fatal "We have no idea how to play $prescription (checked in $opsdir and $prsdir)" has_play_script "$prescription" || fatal "We have no idea how to play $prescription (checked in $opsdir and $prsdir)"
__epm_play_run "$prescription" --run "$@" || fatal "There was some error during run $prescription script." __epm_play_run "$prescription" --run "$@" || fatal "There was some error during run $prescription script."
fi fi
} }
......
...@@ -18,16 +18,33 @@ ...@@ -18,16 +18,33 @@
# #
# args: appname/appscript
get_play_script()
{
local playscript="$1"
is_abs_path "$playscript" || playscript="$psdir/$1.sh"
echo "$playscript"
}
has_play_script()
{
local script="$(get_play_script "$1")"
shift
[ -f "$script.rpmnew" ] && warning 'There is .rpmnew file ${script}.rpmnew. The play script can be outdated.'
[ -s "$script" ]
}
__run_script() __run_script()
{ {
local script="$psdir/$1.sh" local script="$(get_play_script "$1")"
[ -s "$script" ] || return shift
[ -f "$script.rpmnew" ] && warning 'There is .rpmnew file(s) in $psdir dir. The play script can be outdated.' has_play_script "$script" || return
local bashopt='' local bashopt=''
[ -n "$debug" ] && bashopt='-x' [ -n "$debug" ] && bashopt='-x'
shift
[ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH" [ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
( unset EPMCURDIR ; export PATH=$SCPATH ; $CMDSHELL $bashopt $script "$@" ) ( unset EPMCURDIR ; export PATH=$SCPATH ; $CMDSHELL $bashopt $script "$@" )
return return
...@@ -45,18 +62,10 @@ __get_app_description() ...@@ -45,18 +62,10 @@ __get_app_description()
fi fi
} }
__check_play_script()
{
local script="$psdir/$1.sh"
shift
[ -s "$script" ]
}
__epm_play_run_script() __epm_play_run()
{ {
local script="$1" local script="$(get_play_script "$1")"
shift shift
local addopt local addopt
...@@ -69,36 +78,18 @@ __epm_play_run_script() ...@@ -69,36 +78,18 @@ __epm_play_run_script()
( export EPM_OPTIONS="$EPM_OPTIONS $addopt" export PATH=$SCPATH ; docmd $CMDSHELL $bashopt $script "$@" ) ( export EPM_OPTIONS="$EPM_OPTIONS $addopt" export PATH=$SCPATH ; docmd $CMDSHELL $bashopt $script "$@" )
} }
__epm_play_run()
{
local script="$psdir/$1.sh"
shift
__epm_play_run_script "$script" "$@"
}
__epm_is_shell_script()
{
local script="$1"
[ -x "$script" ] && rhas "$script" "\.sh$" && head -n1 "$script" | grep -q "^#!/"
}
__epm_play_remove() __epm_play_remove()
{ {
local prescription local prescription
for prescription in $* ; do for prescription in $* ; do
# run shell script directly
if __epm_is_shell_script "$prescription" ; then
__epm_play_run_script $prescription --remove
continue
fi
# run play script # run play script
if __check_play_script "$prescription" ; then if has_play_script "$prescription" ; then
__epm_play_run $prescription --remove __epm_play_run $prescription --remove
__remove_installed_app "$prescription" __remove_installed_app "$prescription"
else else
psdir=$prsdir psdir=$prsdir
__check_play_script "$prescription" || fatal 'We have no idea how to remove $prescription (checked in $psdir and $prsdir)' has_play_script "$prescription" || fatal 'We have no idea how to remove $prescription (checked in $psdir and $prsdir)'
__epm_play_run "$prescription" --remove || fatal "There was some error during run the script." __epm_play_run "$prescription" --remove || fatal "There was some error during run the script."
fi fi
done done
......
...@@ -66,7 +66,7 @@ done ...@@ -66,7 +66,7 @@ done
prescription="$1" prescription="$1"
shift shift
__check_play_script "$prescription" || fatal 'We have no idea how to play $prescription (checked in $psdir)' has_play_script "$prescription" || fatal 'We have no idea how to play $prescription (checked in $psdir)'
__epm_play_run "$prescription" --run "$@" || fatal "There was some error during run the script." __epm_play_run "$prescription" --run "$@" || fatal "There was some error during run the script."
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment