Files
new_install/operation/install_pkg.sh
lizhi-rocky 220e6bfe40 add Qin Bo's operating shell scripts in
rename directory 'python' to 'interface', for I think it is a better name for its included python scripts function.
2010-09-03 15:59:49 +08:00

176 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
#
# DESCRIPTION: install package
#
# SCRIPT NAME: install_pkg.sh
#
# Usage: echo "acl" |./install_pkg.sh -s /Rocky/packages
#
# Input: stdin
# 1. pkgname
# argument:
# [--help] show usage
# [-s|--source] Package source directory
#
# Output:
# 1 argument error
# 2 pkgname doesn't exist in source directory
#
# TODO:
# 1. need handle more case for install package (use pkgadd utils)
# 1). if package has already installed.
# 2). if devices near no spaces left.
#
# 2. add install package from below media:
# 1). install from network.
# (1). get packages.txt from mirror.
# (2). download package from mirror to hardisk /var/lib/pkg/cache,
# make sure cache is have enough spaces to store download package.
# Notice: download package, need convert package name of #->%23
# 2). install from nfs.
# (1). mount nfs directory as package source directory.
#
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-09
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-09 create
#
#
#
source ./functions
usage ()
{
if [ "$1" == "-n" ];then
cmd="info"
ret=0
else
cmd="err"
ret=1
fi
$cmd "
This script will install a package
Usage: $0 options
options:
[--help] Show this message
[-s | --source] Package source directory
(ex: echo make|install_pkg.sh -s /Rocky/packages)
"
return $ret
}
# get the package file in source directory
get_pkg_file ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkg_name="$1"
if [ -e "$PKG_SOURCE_DIR"/"$pkgname"'#'*tar.gz ]; then
ls "$PKG_SOURCE_DIR"/"$pkgname"'#'*tar.gz|head -n 1
else
err "package \"$pkgname\" doesn't exist in "$PKG_SOURCE_DIR" "
return 2
fi
}
add_pkg ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkg_src=$1
pkgadd -f -r $TARGET $pkg_src 1>$dev_LOG 2>&1
}
install_pkg ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkgname="$1"
# create db for pkgutils
db_dir="/var/lib/pkg"
db="$TARGET$db_dir/db"
if [ ! -e "$db" ];then
info "create $TARGET$db_dir ..."
mkdir -p "$TARGET$db_dir"
touch "$db"
fi
local pkg_src=$(get_pkg_file $pkgname)
erv
info "install $pkgname to $TARGET"
add_pkg $pkg_src
erv
}
main ()
{
tmp=$(getopt -o s: --long source:,help -- "$@" 2>$dev_LOG)
if [ $? -ne 0 ];then
usage
erv
fi
# set all argument to arg variable
eval set -- "$tmp"
while true ;do
case "$1" in
-s|--source)
PKG_SOURCE_DIR="$2"
shift 2
;;
--help) usage -n; exit 0 ;;
# shift the last "--", this dash is define by getopt (more information see man getopt)
--) shift; break;;
*) usage; erv ;;
esac
done
if [ -z "$PKG_SOURCE_DIR" ];then
usage
erv
elif [ ! -e "$PKG_SOURCE_DIR" ];then
err "$PKG_SOURCE_DIR doen't exist !"
exit 1
fi
while read line ;do
echo "$line"
done | sort -u |
while read pkgname;do
if [ -n "$pkgname" ];then
install_pkg "$pkgname"
erv
fi
done
}
PKG_SOURCE_DIR=""
main "$@"