Files
scratchpkg/functions/functions
2017-10-22 21:15:58 +08:00

190 lines
4.6 KiB
Bash

#!/bin/bash
### SET SOME VALUE ###
CONF_FILE="/etc/scratchpkg.conf"
BUILD_SCRIPT="spkgbuild"
ROOT_DIR=/
INDEX_DIR=/var/spkg/index
BACKUP_DIR=/var/spkg/backup
REJECTED_DIR=/var/spkg/rejected
if [ -f $CONF_FILE ]; then
. $CONF_FILE
else
msgerr "Configuration file not found."
exit 1
fi
FUNCTIONS=${FUNCTIONS:-'/usr/share/scratchpkg'}
source "$FUNCTIONS/options"
source "$FUNCTIONS/color"
### SET BSDTAR FOR EXTRACT PROGRAM IF LIBARCHIVE IS INSTALLED ###
if [ -d $INDEX_DIR/libarchive ]; then
EXTPROG=bsdtar
else
EXTPROG=tar
fi
### FUNCTIONS LOAD BY SCRATCHPKG ###
pushd() {
command pushd "$@" >/dev/null
}
popd() {
command popd >/dev/null
}
msg() {
echo -e "${color_green}==>${color_reset} $1"
}
msginfo() {
echo -e "${color_cyan}==> INFO:${color_reset} $1"
}
msgerr() {
echo -e "${color_red}==> ERROR:${color_reset} $1"
}
msgwarn() {
echo -e "${color_yellow}==> WARNING:${color_reset} $1"
}
msg2() {
echo -e "${color_blue} ->${color_reset} $1"
}
msg3() {
echo -e "$1"
}
msg4() {
echo -e " $1"
}
rmdir_silent() {
command rmdir "$@" 2> /dev/null
}
rm_silent() {
command rm "$@" 2> /dev/null
}
updatesystemdb() {
# update desktop database
#msg2 "Updating desktop database..."
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q /usr/share/applications >/dev/null 2>&1
fi
# update mime database
#msg2 "Updating mime database..."
#if [ -x /usr/bin/update-mime-database ]; then
#/usr/bin/update-mime-database /usr/share/mime >/dev/null 2>&1
#fi
# update icon cache
#msg2 "Updating icon cache..."
if [ -f /usr/bin/gtk-update-icon-cache ]; then
find /usr/share/icons -mindepth 1 -maxdepth 1 -type d | while read -r THEME; do
if [ -f "$THEME/index.theme" ]; then
gtk-update-icon-cache -f "$THEME" >/dev/null 2>&1
fi
done
fi
# update glib schema
#msg2 "Updating glib schemas..."
if [ -e /usr/share/glib-2.0/schemas ]; then
if [ -x /usr/bin/glib-compile-schemas ]; then
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas >/dev/null 2>&1
fi
fi
# run ldconfig
#msg2 "Running ldconfig..."
if [ -f /sbin/ldconfig ]; then
/sbin/ldconfig
fi
}
getpkginfo() {
description=$(cat $BUILD_SCRIPT | grep ^'# description' | sed 's/\://' | cut -d ' ' -f 3-)
homepage=$(cat $BUILD_SCRIPT | grep ^'# homepage' | sed 's/\://' | cut -d ' ' -f 3-)
maintainer=$(cat $BUILD_SCRIPT | grep ^'# maintainer' | sed 's/\://' | cut -d ' ' -f 3-)
backup=$(cat $BUILD_SCRIPT | grep ^'# backup' | sed 's/\://' | cut -d ' ' -f 3-)
conflict=$(cat $BUILD_SCRIPT | grep ^'# conflict' | sed 's/\://' | cut -d ' ' -f 3-)
depends=$(cat $BUILD_SCRIPT | grep ^'# depends' | sed 's/\://' | cut -d ' ' -f 3-)
makedepends=$(cat $BUILD_SCRIPT | grep ^'# makedepends' | sed 's/\://' | cut -d ' ' -f 3-)
noextract=$(cat $BUILD_SCRIPT | grep ^'# noextract' | sed 's/\://' | cut -d ' ' -f 3-)
options=$(cat $BUILD_SCRIPT | grep ^'# options' | sed 's/\://' | cut -d ' ' -f 3-)
. $BUILD_SCRIPT
}
getpkginfofrompkg() {
name=$(tar xf $1 .pkginfo -O | grep ^name | cut -d " " -f3)
version=$(tar xf $1 .pkginfo -O | grep ^version | cut -d " " -f3)
release=$(tar xf $1 .pkginfo -O | grep ^release | cut -d " " -f3)
description=$(tar xf $1 .pkginfo -O | grep ^description | cut -d " " -f3-)
homepage=$(tar xf $1 .pkginfo -O | grep ^homepage | cut -d " " -f3-)
maintainer=$(tar xf $1 .pkginfo -O | grep ^maintainer | cut -d " " -f3-)
backup=$(tar xf $1 .pkginfo -O | grep ^backup | cut -d " " -f3-)
conflict=$(tar xf $1 .pkginfo -O | grep ^conflict | cut -d " " -f3-)
depends=$(tar xf $1 .pkginfo -O | grep ^depends | cut -d " " -f3-)
makedepends=$(tar xf $1 .pkginfo -O | grep ^makedepends | cut -d " " -f3-)
}
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
}
createtemplate() {
if [ -d $TEMPLATE_NAME ]; then
msg "Error directory ${color_red}$TEMPLATE_NAME${color_reset} already exist"
exit 1
else
mkdir $TEMPLATE_NAME
echo "# description :
# backup :
# conflict :
# depends :
# makedepends :
# noextract :
name=$TEMPLATE_NAME
version=
release=1
options=()
source=()
build() {
cd \$name-\$version
./configure --prefix=/usr
make
make DESTDIR=\$PKG install
}" > $TEMPLATE_NAME/$BUILD_SCRIPT
msg "Template port have created for ${color_green}$TEMPLATE_NAME${color_reset}."
fi
}