Skip to content

Commit bd01851

Browse files
committed
Factor installation of pth and scripts to shell functions.
Do not prompt for the script path if there are no scripts to install.
1 parent c6df30a commit bd01851

1 file changed

Lines changed: 73 additions & 57 deletions

File tree

Linux/install

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ adjust_macosx_environment() {
197197
local cxxhasboost
198198
cxxhasboost=( ${^compilerpaths}/boost(N-/) )
199199
if [[ -z $cxxhasboost && -d ${PORTDIR}/include/boost ]]; then
200-
print "Warning: Adjusting CPATH to include MacPorts header files."
200+
print "WARNING: Adjusting CPATH to include MacPorts header files."
201201
cpath=( $PORTDIR/include $cpath )
202202
print -r "CPATH=${(q)CPATH}"
203203
print
204204
local plib=${PORTDIR}/lib
205205
if [[ -d $plib && -z ${(M)library_path:#${plib}} ]]; then
206-
print "Warning: Adjusting LIBRARY_PATH to include MacPorts libraries."
206+
print "WARNING: Adjusting LIBRARY_PATH to include MacPorts libraries."
207207
library_path=( $plib $library_path )
208208
print -r "LIBRARY_PATH=${(q)LIBRARY_PATH}"
209209
print
@@ -332,6 +332,75 @@ do_build() {
332332
}
333333

334334

335+
install_pthfile() {
336+
local TGTDIR=$(print -lr \
337+
'import site, distutils.sysconfig' \
338+
'if site.ENABLE_USER_SITE: print site.USER_SITE' \
339+
'else: print distutils.sysconfig.get_python_lib()' \
340+
| ${PYTHON} )
341+
print
342+
print "Python path directory for installing ${PTHFILE:t}"
343+
vared -p '--> ' TGTDIR
344+
TGTDIR=${TGTDIR%%[[:space:]]##}
345+
expand_tilde TGTDIR
346+
if [[ -z $TGTDIR ]]; then
347+
print "No directory, installation cancelled."
348+
exit 1
349+
fi
350+
if [[ ! -d $TGTDIR ]]; then
351+
print "Directory $TGTDIR does not exist."
352+
read -q '?Create? (y/n) '; print
353+
if [[ $REPLY == [yY] ]]; then
354+
mkdir -p ${TGTDIR} || exit $?
355+
else
356+
print "No directory, installation cancelled."
357+
exit 1
358+
fi
359+
fi
360+
if [[ ${PTHFILE} -ef ${TGTDIR}/${PTHFILE:t} && -L ${TGTDIR}/${PTHFILE:t} ]];
361+
then
362+
print "Symbolic link to ${PTHFILE:t} already exists, good!"
363+
else
364+
print "Creating symbolic link"
365+
ln -siv ${PTHFILE} ${TGTDIR} || exit $?
366+
fi
367+
print
368+
}
369+
370+
371+
install_scripts() {
372+
local scriptfiles
373+
scriptfiles=( ${BASEDIR}/bin/*(-*N) )
374+
if [[ -z $scriptfiles ]]; then
375+
return
376+
fi
377+
TGTDIR=${HOME}/bin
378+
d=$(print -rD -- $TGTDIR)
379+
print "Directory for installing executable scripts"
380+
vared -p "--> " TGTDIR
381+
TGTDIR=${TGTDIR%%[[:space:]]##}
382+
expand_tilde TGTDIR
383+
if [[ ! -d ${TGTDIR} ]]; then
384+
print -D "Directory" $TGTDIR "does not exist, scripts not installed."
385+
print
386+
return
387+
fi
388+
# scrub scriptfiles that are already installed
389+
scriptfiles=( ${^scriptfiles}(Ne,'[[ ! $REPLY -ef $TGTDIR/${REPLY:t} ]]',) )
390+
if [[ -z ${scriptfiles} ]]; then
391+
print "Scripts are already installed, good!"
392+
else
393+
print "Creating symbolic links:"
394+
ln -siv $scriptfiles ${TGTDIR}
395+
fi
396+
d=( ${^path}(Ne:'[[ $REPLY -ef $TGTDIR ]]':) )
397+
if [[ -z $d ]]; then
398+
print -D "\nWARNING:" $TGTDIR "is not in the PATH."
399+
fi
400+
print
401+
}
402+
403+
335404
do_install() {
336405
print $HASHLINE
337406
print "Welcome to DiffPy-CMI ${VERSION?}"
@@ -372,61 +441,8 @@ do_install() {
372441
print "\n[dry run] - installation of symbolic links skipped."
373442
exit
374443
fi
375-
local TGTDIR=$(print -lr \
376-
'import site, distutils.sysconfig' \
377-
'if site.ENABLE_USER_SITE: print site.USER_SITE' \
378-
'else: print distutils.sysconfig.get_python_lib()' \
379-
| ${PYTHON} )
380-
print
381-
print "Python path directory for installing ${PTHFILE:t}"
382-
vared -p '--> ' TGTDIR
383-
TGTDIR=${TGTDIR%%[[:space:]]##}
384-
expand_tilde TGTDIR
385-
if [[ -z $TGTDIR ]]; then
386-
print "No directory, installation cancelled."
387-
exit 1
388-
fi
389-
if [[ ! -d $TGTDIR ]]; then
390-
print "Directory $TGTDIR does not exist."
391-
if read -q '?Create? (y/n) '; then
392-
mkdir -p ${TGTDIR} || exit $?
393-
print
394-
else
395-
print "\nNo directory, installation cancelled."
396-
exit 1
397-
fi
398-
fi
399-
if [[ ${PTHFILE} -ef ${TGTDIR}/${PTHFILE:t} && -L ${TGTDIR}/${PTHFILE:t} ]];
400-
then
401-
print "Symbolic link to ${PTHFILE:t} already exists, good!"
402-
else
403-
print "Creating symbolic link"
404-
ln -siv ${PTHFILE} ${TGTDIR} || exit $?
405-
fi
406-
TGTDIR=${HOME}/bin
407-
d=$(print -rD -- $TGTDIR)
408-
print "\nDirectory for installing executable scripts"
409-
vared -p "--> " TGTDIR
410-
TGTDIR=${TGTDIR%%[[:space:]]##}
411-
expand_tilde TGTDIR
412-
if [[ ! -d ${TGTDIR} ]]; then
413-
print -D "Directory" $TGTDIR "does not exist, scripts not installed."
414-
else
415-
local f scriptfiles
416-
scriptfiles=( ${BASEDIR}/bin/*(-*N) )
417-
scriptfiles=( ${^scriptfiles}(Ne:'[[ ! $REPLY -ef $TGTDIR/${REPLY:t} ]]':) )
418-
if [[ -z ${scriptfiles} ]]; then
419-
print "Scripts are already installed, good."
420-
else
421-
print "Creating symbolic links:"
422-
ln -siv $scriptfiles ${TGTDIR}
423-
fi
424-
d=( ${^path}(Ne:'[[ $REPLY -ef $TGTDIR ]]':) )
425-
if [[ -z $d ]]; then
426-
print -D "Warning:" $TGTDIR "is not in the PATH."
427-
fi
428-
fi
429-
print
444+
install_pthfile
445+
install_scripts
430446
print $FINALINFO
431447
}
432448

0 commit comments

Comments
 (0)