#!/bin/sh #--------------------------------------------------------------------------- # /var/install/bin/install-local-package - install package from local harddisk # # Creation: 2005-10-03 jed # Last Update: $Id$ # # Copyright (c) 2001-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # usage: install-local-package # or: install-local-package directory-name # or: install-local-package index-number of directory # or: install-local-package --add-menu # or: install-local-package --del-menu # # options: --add-menu - add menu entry to package menu # --del-menu - remove menu entry to package menu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #--------------------------------------------------------------------------- # read eislib . /var/install/include/eislib . /var/install/include/eismanlib # debug mode: true/false #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi #--------------------------------------------------------------------------- # check if numeric value # input : $1 - value # return: 0 - numeric # 1 - no numeric #--------------------------------------------------------------------------- is_numeric () { echo "$1"|grep -q '^[0-9]*$' } #--------------------------------------------------------------------------- # check directory list file # $1 - directory to add #--------------------------------------------------------------------------- add_to_dirlist () { dirname="$1" if [ -f ${dirlist_file} ] then # file exist - add to existing file last_dirname="`sed -n '1p;1q' $dirlist_file`" # add to file if not equal last entry cp ${dirlist_file} ${dirlist_file}.tmp { echo "$dirname" grep -v "^${dirname}$" ${dirlist_file}.tmp } | sed '11,$d' > ${dirlist_file} rm -f ${dirlist_file}.tmp else # create new file echo "$dirname" > ${dirlist_file} fi } #--------------------------------------------------------------------------- # show last 10 directory entries #--------------------------------------------------------------------------- show_dirlist () { idx=0 if [ -f ${dirlist_file} ] then max_lines=`cat ${dirlist_file} | wc -l` if [ $max_lines -ge 1 ] then # print only if more than one entry mecho "Previous selections:" mecho techo --begin '1 3r 2 65' while read line do idx=`expr $idx + 1` techo --row "" $idx "" $line done < ${dirlist_file} techo --end fi fi } #=========================================================================== # main #=========================================================================== rundir=/run tmp_dir=/var/install if [ ! -d ${tmp_dir} ] then mkdir -p ${tmp_dir} fi if [ -f ${rundir}/install-local-package-list ] then mv ${rundir}/install-local-package-list ${tmp_dir}/ fi dirlist_file=${tmp_dir}/install-local-package-list pgmname=`basename $0` if [ ! -f ${dirlist_file} ] then echo "/var/tmp" >${dirlist_file} fi # check for CUI menu if $(grep -qE "^MENU=['\"]/var/install/bin/show-menu.cui['\"]" /etc/config.d/setup) then browser="/var/install/bin/browse-packages.cui.sh" else browser='/var/install/bin/browse-packages' fi # read parameters noask=0 if [ $# -gt 0 ] then while [ $# -ne 0 -a $noask -eq 0 ] do case $1 in '--add-menu'|'-add-menu') /var/install/bin/add-menu --script "setup.packages.menu" install-local-package "Install (new) package from local directory" exit 1 ;; '--del-menu'|'-del-menu') /var/install/bin/del-menu "setup.packages.menu" install-local-package exit 1 ;; *) package_dir="$*" noask=1 ;; esac done fi u_exit=0 until [ ${u_exit} -eq 1 ] do # read number of entries if [ -f ${dirlist_file} ] then maxnum=`cat ${dirlist_file} | wc -l` else maxnum=0 fi if [ $noask -eq 0 ] then clrhome mecho --info "Enter package directory" mecho # show previous selections show_dirlist mecho if [ $maxnum -ge 1 ] then preselectstr="`sed -n '1p;1q' $dirlist_file`" else preselectstr='' fi # create menu addition if [ $maxnum -ge 1 ] then selectstr="1-$maxnum" else selectstr='' fi _ask_file=`/bin/mktemp -t ${pgmname}-ask.XXXXXXXXX` /var/install/bin/ask "Enter local package directory (absolute path) (${selectstr}, ENTER=Return, 0=Exit)" "${preselectstr}" "*" > ${_ask_file} rc=$? package_dir="`cat ${_ask_file} | sed 's/\/$//'`" rm -f ${_ask_file} if [ $rc = 255 ] then exit 127 fi fi case "$package_dir" in '') # quit program exit 0 ;; 0) exit 127 ;; * ) # go on... u_exit=0 if is_numeric $package_dir then # numeric value - read from directory list file if [ $package_dir -lt 1 -o $package_dir -gt $maxnum ] then # error if [ -f $dirlist_file ] then mecho --error "Value out of range!" else mecho --error "Invalid input because no $dirlist_file exists!" fi if [ $noask -eq 0 ] then u_exit=2 anykey else # called from command line - exit u_exit=1 fi else # read from directory list package_dir="`sed -n \"${package_dir}p;${package_dir}q\" $dirlist_file`" fi fi if [ $u_exit -eq 0 ] then if [ -d "$package_dir" ] then # check if it is equal /tmp echo "$package_dir" | grep -q "^/tmp$" if [ $? -ne 0 ] then # build URL from path url="file://$(realpath ${package_dir})" # add packages from local dir eisman localdir "${package_dir}" # perform query eisman query --unstable --url="${url}" > /tmp/query$$.txt # show packages ${browser} --install /tmp/query$$.txt # flush packages eisman flushurl "${url}" # remove query file rm /tmp/query$$.txt # add package dir to dir list file, if packages have been found if [ -n "$(find "${package_dir}" -name "*.info")" ] then add_to_dirlist "${package_dir}" fi fi u_exit=1 else mecho --error "Directory '$package_dir' doesn't exist!" if [ $noask -eq 0 ] then anykey else # exit if called from command line u_exit=1 fi fi fi ;; esac done #=========================================================================== # end #===========================================================================