mirror of
https://github.com/outbackdingo/scratchpkg.git
synced 2026-02-06 17:30:19 +00:00
513 lines
11 KiB
Bash
Executable File
513 lines
11 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
pushtoport() {
|
|
|
|
for port in ${PORT_REPO[@]}; do
|
|
if [ -d $port/$PORTNAME ]; then
|
|
pushd $port/$PORTNAME
|
|
IGNORE_CONFLICT="$IGNORE_CONFLICT" \
|
|
IGNORE_DEP="$IGNORE_DEP" \
|
|
REINSTALL_PKG="$REINSTALL_PKG" \
|
|
UPGRADE_PKG="$UPGRADE_PKG" \
|
|
VERBOSE_INSTALL="$VERBOSE_INSTALL" \
|
|
INSTALL_PKG="$INSTALL_PKG" \
|
|
buildpkg
|
|
popd
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
listinstalled() {
|
|
for installed in $(ls $INDEX_DIR); do
|
|
getinstalledname $installed
|
|
msg $installedname
|
|
done
|
|
}
|
|
|
|
getinstalledname() {
|
|
|
|
iname=$(cat $INDEX_DIR/$1/.pkginfo | grep ^name | cut -d " " -f3)
|
|
iversion=$(cat $INDEX_DIR/$1/.pkginfo | grep ^version | cut -d " " -f3)
|
|
irelease=$(cat $INDEX_DIR/$1/.pkginfo | grep ^release | cut -d " " -f3)
|
|
depends=$(cat $INDEX_DIR/$1/.pkginfo | grep ^depends | cut -d " " -f3-)
|
|
backup=$(cat $INDEX_DIR/$1/.pkginfo | grep ^backup | cut -d " " -f3-)
|
|
|
|
installedname=$iname-$iversion-$irelease
|
|
|
|
}
|
|
|
|
listorphan() {
|
|
|
|
for all_installed in $(ls ${INDEX_DIR}); do
|
|
dep=$(cat $INDEX_DIR/$all_installed/.pkginfo | grep ^depends | cut -d " " -f3-)
|
|
for deps in ${dep[@]}; do
|
|
ALL_DEP+=($deps)
|
|
done
|
|
done
|
|
|
|
for all in $(ls $INDEX_DIR); do
|
|
ORPHAN=yes
|
|
getinstalledname $all
|
|
for depended in ${ALL_DEP[@]}; do
|
|
if [ $depended = $all ]; then
|
|
ORPHAN=no
|
|
break
|
|
fi
|
|
done
|
|
if [ $ORPHAN = yes ]; then
|
|
msg $installedname
|
|
fi
|
|
done
|
|
|
|
}
|
|
|
|
searchpkg() {
|
|
|
|
for port in ${PORT_REPO[@]}; do
|
|
OUTPUT=()
|
|
if [ -d $port ]; then
|
|
for list in $(ls $port); do
|
|
if [ -f $port/$list/$BUILD_SCRIPT ]; then
|
|
if [ "$(cat $port/$list/$BUILD_SCRIPT | grep ^'# description' | tr -d ':' | cut -d ' ' -f 3- | grep -i $SEARCH_PKG)" ] || [ "$(echo $list | grep -i $SEARCH_PKG)" ]; then
|
|
OUTPUT+=($list)
|
|
fi
|
|
fi
|
|
done
|
|
for out in ${OUTPUT[@]}; do
|
|
if [ -f $port/$out/$BUILD_SCRIPT ]; then
|
|
pushd $port/$out
|
|
getpkginfo
|
|
. $BUILD_SCRIPT
|
|
popd
|
|
if [ ! -z "$name" ] && [ ! -z "$version" ] && [ ! -z "$release" ]; then
|
|
portname=$(basename $port)
|
|
if [ -d $INDEX_DIR/$name ]; then
|
|
msg "($portname) ${color_green}$name${color_reset} $version-$release $description"
|
|
else
|
|
msg "($portname) $name $version-$release $description"
|
|
fi
|
|
unset description
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
}
|
|
|
|
checkowner() {
|
|
|
|
for installed in $(ls $INDEX_DIR); do
|
|
for output in $(cat $INDEX_DIR/$installed/.files | grep $OWNER_FILE_NAME); do
|
|
msg "${color_green}$installed${color_reset} => ${color_purple}$output${color_reset}"
|
|
done
|
|
done
|
|
|
|
}
|
|
|
|
showtree() {
|
|
|
|
if [ ! -d $INDEX_DIR/$TREE_PORT_NAME ]; then
|
|
msg "Package ${color_red}$TREE_PORT_NAME${color_reset} not installed."
|
|
else
|
|
while IFS=' ' read -r line; do
|
|
echo "$line"
|
|
done < <(cat $INDEX_DIR/$TREE_PORT_NAME/.files)
|
|
fi
|
|
|
|
}
|
|
|
|
checkintegrity() {
|
|
|
|
for installed in $(ls $INDEX_DIR); do
|
|
while IFS=' ' read -r line; do
|
|
pushd $ROOT_DIR
|
|
if [ ! -e "$line" ]; then
|
|
msg "${color_yellow}$installed${color_reset} is missing: ${color_purple}/$line${color_reset}"
|
|
MISSING_FILE=yes
|
|
fi
|
|
popd
|
|
done < <(cat $INDEX_DIR/$installed/.files)
|
|
done
|
|
|
|
[ "$UID" != "0" ] && msg "${color_yellow}(check integrity is recommended run as root user or using sudo)${color_reset}"
|
|
[ ! "$MISSING_FILE" ] && msg "Your system file is consistent with package tree."
|
|
|
|
}
|
|
|
|
showpackageinfo() {
|
|
|
|
if [ ! -f $PACKAGE_INFO ]; then
|
|
msg "${color_red}$PACKAGE_INFO${color_reset} not exist."
|
|
exit 1
|
|
else
|
|
if [ $(tar -tf "$PACKAGE_INFO" | grep ".pkginfo") ]; then
|
|
getpkginfofrompkg $PACKAGE_INFO
|
|
echo -e "${color_green}package info:${color_reset}"
|
|
[ -n "$name" ] && echo "name = $name"
|
|
[ -n "$version" ] && echo "version = $version"
|
|
[ -n "$release" ] && echo "release = $release"
|
|
[ -n "$description" ] && echo "description = $description"
|
|
[ -n "$homepage" ] && echo "homepage = $homepage"
|
|
[ -n "$maintainer" ] && echo "maintainer = $maintainer"
|
|
[ -n "$backup" ] && echo "backup = $backup"
|
|
[ -n "$conflict" ] && echo "conflict = $conflict"
|
|
[ -n "$depends" ] && echo "depends = $depends"
|
|
[ -n "$makedepends" ] && echo "makedepends = $makedepends"
|
|
if [ $(tar -tf "$PACKAGE_INFO" | grep ".pkginstall" | cut -d / -f 1 | uniq) ]; then
|
|
echo ""
|
|
echo -e "${color_green}pkginstall files:${color_reset}"
|
|
tar -tf $PACKAGE_INFO .pkginstall | cut -d / -f 2 | sed '/^$/d'
|
|
fi
|
|
|
|
if [ $(tar -tf "$PACKAGE_INFO" | grep ".pkginstall/readme") ]; then
|
|
echo ""
|
|
echo -e "${color_green}readme:${color_reset}"
|
|
tar -xf $PACKAGE_INFO .pkginstall/readme -O
|
|
echo ""
|
|
fi
|
|
else
|
|
msg "${color_yellow}$PACKAGE_INFO${color_reset} is not package created by scratchpkg."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
}
|
|
|
|
showdepends() {
|
|
|
|
for portdepends in ${PORT_REPO[@]}; do
|
|
if [ -f $portdepends/$PACKAGE_DEPENDS/$BUILD_SCRIPT ]; then
|
|
pushd $portdepends/$PACKAGE_DEPENDS
|
|
getpkginfo
|
|
. $BUILD_SCRIPT
|
|
popd
|
|
break
|
|
fi
|
|
done
|
|
if [ -z $name ]; then
|
|
msg "Port ${color_red}$PACKAGE_DEPENDS${color_reset} not exist."
|
|
exit 1
|
|
fi
|
|
|
|
for dep in ${depends[@]}; do
|
|
if [ -d $INDEX_DIR/$dep ]; then
|
|
msg "${color_green}$dep${color_reset}"
|
|
else
|
|
PORT_EXIST=no
|
|
for port in ${PORT_REPO[@]}; do
|
|
if [ -f $port/$dep/$BUILD_SCRIPT ]; then
|
|
PORT_EXIST=yes
|
|
break
|
|
fi
|
|
done
|
|
case $PORT_EXIST in
|
|
yes) msg "${color_yellow}$dep${color_reset}" ;;
|
|
no) msg "${color_red}$dep${color_reset}" ;;
|
|
esac
|
|
fi
|
|
done
|
|
|
|
for mdep in ${makedepends[@]}; do
|
|
if [ -d $INDEX_DIR/$mdep ]; then
|
|
msg "${color_green}$mdep${color_reset} (make)"
|
|
else
|
|
PORT_EXIST=no
|
|
for port in ${PORT_REPO[@]}; do
|
|
if [ -f $port/$mdep/$BUILD_SCRIPT ]; then
|
|
PORT_EXIST=yes
|
|
break
|
|
fi
|
|
done
|
|
case $PORT_EXIST in
|
|
yes) msg "${color_yellow}$mdep${color_reset} (make)" ;;
|
|
no) msg "${color_red}$mdep${color_reset} (make)" ;;
|
|
esac
|
|
fi
|
|
done
|
|
}
|
|
|
|
showupdate() {
|
|
|
|
for package_name in $(ls $INDEX_DIR); do
|
|
for port in ${PORT_REPO[@]}; do
|
|
if [ -f $port/$package_name/$BUILD_SCRIPT ]; then
|
|
. $port/$package_name/$BUILD_SCRIPT
|
|
getinstalledname $name
|
|
if [ "$name-$version-$release" != "$installedname" ]; then
|
|
msg "$name ${color_red}$iversion-$irelease${color_reset} => ${color_green}$version-$release${color_reset}"
|
|
OUTDATE=yes
|
|
fi
|
|
break
|
|
fi
|
|
done
|
|
done
|
|
|
|
[ ! "$OUTDATE" ] && msg "All package is up to date."
|
|
}
|
|
|
|
showdependent() {
|
|
|
|
if [ ! -d $INDEX_DIR/$PACKAGE_DEPENDENT ]; then
|
|
msg "Package ${color_red}$PACKAGE_DEPENDENT${color_reset} not installed."
|
|
exit 1
|
|
else
|
|
for all_installed in $(ls $INDEX_DIR); do
|
|
depend=$(cat $INDEX_DIR/$all_installed/.pkginfo | grep ^depends | cut -d " " -f3-)
|
|
for dep in ${depend[@]}; do
|
|
if [ $dep = $PACKAGE_DEPENDENT ]; then
|
|
msg "$all_installed"
|
|
fi
|
|
done
|
|
done
|
|
fi
|
|
}
|
|
|
|
showglobaldependent() {
|
|
|
|
if [ -d $INDEX_DIR/$GLOBAL_PACKAGE_DEPENDENT ]; then
|
|
msg "Package ${color_green}$GLOBAL_PACKAGE_DEPENDENT${color_reset} is installed."
|
|
else
|
|
msg "Package ${color_red}$GLOBAL_PACKAGE_DEPENDENT${color_reset} not installed."
|
|
fi
|
|
for port in ${PORT_REPO[@]}; do
|
|
if [ -d $port ]; then
|
|
for all in $(ls $port); do
|
|
if [ -f $port/$all/$BUILD_SCRIPT ]; then
|
|
depend=$(cat $port/$all/$BUILD_SCRIPT | grep ^'# depends' | tr -d ':' | cut -d " " -f3-)
|
|
for dep in ${depend[@]}; do
|
|
if [ $dep = $GLOBAL_PACKAGE_DEPENDENT ]; then
|
|
if [ -d $INDEX_DIR/$all ]; then
|
|
msg "${color_green}$all${color_reset}"
|
|
else
|
|
msg "${color_yellow}$all${color_reset}"
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
}
|
|
|
|
interrupted() {
|
|
echo ""
|
|
msg "${color_yellow}Interrupted!${color_reset}"
|
|
exit 1
|
|
}
|
|
|
|
parse_options() {
|
|
|
|
while [ "$1" ]; do
|
|
case $1 in
|
|
-i|--install)
|
|
INSTALL_PKG=yes
|
|
;;
|
|
-id|--ignore-dependency)
|
|
IGNORE_DEP=yes
|
|
;;
|
|
-ic|--ignore-conflict)
|
|
IGNORE_CONFLICT=yes
|
|
;;
|
|
-r|--reinstall)
|
|
REINSTALL_PKG=yes
|
|
;;
|
|
-u|--upgrade)
|
|
UPGRADE_PKG=yes
|
|
;;
|
|
-v|--verbose)
|
|
VERBOSE_INSTALL=yes
|
|
;;
|
|
-l|--list-installed)
|
|
LIST_INSTALLED=yes
|
|
;;
|
|
-lo|--list-orphan)
|
|
LIST_ORPHAN=yes
|
|
;;
|
|
-ci|--check-integrity)
|
|
CHECK_INTEGRITY=yes
|
|
;;
|
|
-cu|--check-update)
|
|
CHECK_UPDATE=yes
|
|
;;
|
|
--no-color)
|
|
NO_COLOR=yes
|
|
;;
|
|
-dp|--dependent)
|
|
if [ ! "$2" ]; then
|
|
info "Option '$1' require an argument (package to show its dependent)"
|
|
exit 1
|
|
fi
|
|
PACKAGE_DEPENDENT="$2"
|
|
shift ;;
|
|
-gdp|--global-dependent)
|
|
if [ ! "$2" ]; then
|
|
info "Option '$1' require an argument (package to show its dependent)"
|
|
exit 1
|
|
fi
|
|
GLOBAL_PACKAGE_DEPENDENT="$2"
|
|
shift ;;
|
|
-d|--depends)
|
|
if [ ! "$2" ]; then
|
|
info "Option '$1' require an argument (package name to show its depends)"
|
|
exit 1
|
|
fi
|
|
PACKAGE_DEPENDS="$2"
|
|
shift
|
|
;;
|
|
-pi|--package-info)
|
|
if [ ! "$2" ] || [ ! "$(echo $2 | grep '.spkg.txz')" ]; then
|
|
msg "Option '$1' require an argument (package '*.spkg.txz' to show its info)."
|
|
exit 1
|
|
fi
|
|
PACKAGE_INFO="$2"
|
|
shift
|
|
;;
|
|
-co|--check-owner)
|
|
if [ ! "$2" ]; then
|
|
msg "Option '$1' require an argument (file name to show its owner)."
|
|
exit 1
|
|
fi
|
|
OWNER_FILE_NAME="$2"
|
|
shift
|
|
;;
|
|
-st|--show-tree)
|
|
if [ ! "$2" ]; then
|
|
msg "Option '$1' require an argument (package name to show tree)."
|
|
exit 1
|
|
fi
|
|
TREE_PORT_NAME="$2"
|
|
shift
|
|
;;
|
|
-s|--search)
|
|
if [ ! "$2" ]; then
|
|
msg "Option '$1' require an argument (package name to search)."
|
|
exit 1
|
|
fi
|
|
SEARCH_PKG="$2"
|
|
shift
|
|
;;
|
|
-p|--package)
|
|
if [ ! "$2" ]; then
|
|
msg "Option '$1' require an argument (package name to install/build)."
|
|
exit 1
|
|
fi
|
|
PORTNAME="$2"
|
|
shift
|
|
;;
|
|
-t|--create-template)
|
|
if [ ! "$2" ]; then
|
|
msg "Option '$1' require an argument (port name to create template)."
|
|
exit 1
|
|
fi
|
|
TEMPLATE_NAME="$2"
|
|
shift
|
|
;;
|
|
*)
|
|
msg "Option invalid!"
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
}
|
|
|
|
main() {
|
|
|
|
. /usr/share/scratchpkg/functions || exit 1
|
|
|
|
parse_options "$@"
|
|
|
|
### DISABLE COLOR ###
|
|
if [ "$NO_COLOR" ]; then
|
|
nocolor
|
|
fi
|
|
|
|
loadconfigfile
|
|
|
|
### CREATE PORT TEMPLATE ###
|
|
if [ $TEMPLATE_NAME ]; then
|
|
createtemplate
|
|
exit 0
|
|
fi
|
|
|
|
### SHOW DEPENDENT (search through only installed package) ###
|
|
if [ $PACKAGE_DEPENDENT ]; then
|
|
showdependent
|
|
exit 0
|
|
fi
|
|
|
|
### SHOW GLOBAL DEPENDENT (search through ports repo) ###
|
|
if [ $GLOBAL_PACKAGE_DEPENDENT ]; then
|
|
showglobaldependent
|
|
exit 0
|
|
fi
|
|
|
|
### SHOW DEPENDS OF A PACKAGE ###
|
|
if [ $PACKAGE_DEPENDS ]; then
|
|
showdepends
|
|
exit 0
|
|
fi
|
|
|
|
### CHECK_UPDATE ###
|
|
if [ $CHECK_UPDATE ]; then
|
|
showupdate
|
|
exit 0
|
|
fi
|
|
|
|
### SHOW INFO OF A PACKAGE ###
|
|
if [ $PACKAGE_INFO ]; then
|
|
showpackageinfo
|
|
exit 0
|
|
fi
|
|
|
|
### LIST INSTALLED ###
|
|
if [ $LIST_INSTALLED ]; then
|
|
listinstalled
|
|
exit 0
|
|
fi
|
|
|
|
### LIST ORPHAN ###
|
|
if [ $LIST_ORPHAN ]; then
|
|
listorphan
|
|
exit 0
|
|
fi
|
|
|
|
### SEARCH PACKAGE ###
|
|
if [ $SEARCH_PKG ]; then
|
|
searchpkg
|
|
exit 0
|
|
fi
|
|
|
|
### CHECK PACKAGE OWNER OF A FILE ###
|
|
if [ $OWNER_FILE_NAME ]; then
|
|
checkowner
|
|
exit 0
|
|
fi
|
|
|
|
### SHOW TREE OF A INSTALLED PACKAGE ###
|
|
if [ $TREE_PORT_NAME ]; then
|
|
showtree
|
|
exit 0
|
|
fi
|
|
|
|
### CHECK INTEGRITY ###
|
|
if [ $CHECK_INTEGRITY ]; then
|
|
checkintegrity
|
|
exit 0
|
|
fi
|
|
|
|
### BUILD PACKAGE ###
|
|
if [ $PORTNAME ]; then
|
|
pushtoport
|
|
exit 0
|
|
fi
|
|
|
|
exit 0
|
|
}
|
|
|
|
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
|
|
|
|
main "$@"
|