remove unused options, codes, colour and etc...

This commit is contained in:
emmett1
2019-01-28 16:37:52 +08:00
parent a3812438b7
commit c17ef8ec52
7 changed files with 127 additions and 284 deletions

115
pkgadd
View File

@@ -18,45 +18,32 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
CYAN='\e[0;36m'
CRESET='\e[0m'
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
export LC_ALL=C
interrupted() {
echo
ret 1
}
nocolor() {
RED=
GREEN=
YELLOW=
CYAN=
CRESET=
}
msg() {
echo -e "${GREEN}==>${CRESET} $1"
echo -e "==> $1"
}
msg2() {
echo -e " ${CYAN}*${CRESET} $1"
echo -e " -> $1"
}
msgerr() {
echo -e "${RED}==> ERROR:${CRESET} $1"
echo -e "==> ERROR: $1"
}
msgwarn() {
echo -e "${YELLOW}==> WARNING:${CRESET} $1"
echo -e "==> WARNING: $1"
}
runhooks() {
runhooks() {
if [ "$UPGRADE_PKG" ]; then
opr=upgrade
else
@@ -71,7 +58,6 @@ runhooks() {
if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ]; then
if [ "$(echo $operation | grep -w "$opr" )" ]; then
if [ "$(grep $target $INDEX_DIR/$name/.files)" ]; then
[ "$SILENT_INSTALL" ] || msg2 "$description"
. $hook
if [ "`type -t exechook`" = "function" ]; then
exechook
@@ -81,34 +67,27 @@ runhooks() {
fi
unset description operation target
unset -f exechook
done
done
}
help() {
cat << EOF
Usage:
$(basename $0) package.spkg.txz <options>
$(basename $0) [ <options> <package.spkg.txz> ]
Options:
-u, --upgrade upgrade package
-r, --reinstall reinstall package
-c, --ignore-conflict ignore conflict when installing package
-v, --verbose print files installed
-s, --silent print install message in simple format
-h, --help show this help message
--no-preinstall skip preinstall script before build/install package
--no-postinstall skip postinstall script after install package
--no-preupgrade skip preupgrade script before upgrade package
--no-postupgrade skip postupgrade script after upgrade package
--no-backup skip backup when upgrading package
--no-color disable colour for output
--no-hook skip executing hook
--root=<path> install to custom root directory
Example:
$(basename $0) foobar-1.0-1.spkg.txz -uc --no-backup upgrade package foobar-1.0-1 without backup its
old configuration files and skip conflict check
EOF
}
@@ -133,7 +112,6 @@ parse_opts() {
-r | --reinstall) REINSTALL_PKG=yes ;;
-c | --ignore-conflict) IGNORE_CONFLICT=yes ;;
-v | --verbose) VERBOSE_INSTALL=yes ;;
-s | --silent) SILENT_INSTALL=yes ;;
-h | --help) SHOWHELP=yes ;;
--no-preinstall) NO_PREINSTALL=yes ;;
--no-postinstall) NO_POSTINSTALL=yes ;;
@@ -152,8 +130,8 @@ parse_opts() {
}
ret() {
# remove lock file on exit
rm -fr $LOCK_FILE $TMP_PKGADD
# remove lock and all tmp files on exit
rm -f $LOCK_FILE $TMP_PKGADD $TMP_PKGINSTALL $TMP_PKGINSTALL_BKP $TMP_PKGADD_RMLIST
exit $1
}
@@ -169,10 +147,7 @@ parse_opts $(extract_opt $@)
INDEX_DIR="$ROOT/var/lib/scratchpkg/index"
PKGADD_DIR="$ROOT/var/lib/scratchpkg"
TMP_PKGADD="$PKGADD_DIR/$(basename $0)-tmp"
LOCK_FILE="$PKGADD_DIR/spkg.lock"
TMP_PKGINSTALL="$TMP_PKGADD/$(basename $0).install"
TMP_PKGINSTALL_BKP="$TMP_PKGADD/$(basename $0).bkp.install"
HOOK_DIR=/etc/hooks
# show help page
@@ -180,13 +155,11 @@ if [ "$SHOWHELP" ] || [ -z "$PKGNAME" ]; then
help
ret 0
fi
# disable color for output
if [ "$NOCOLOR" ]; then
nocolor
fi
mkdir -p $PKGADD_DIR
if [ ! -d $INDEX_DIR ]; then
msgerr "Package's database directory not exist! ($INDEX_DIR)"
ret 1
fi
# check for lock file
if [ -f $LOCK_FILE ]; then
@@ -201,8 +174,6 @@ else
fi
fi
mkdir -p $INDEX_DIR $TMP_PKGADD
if [ -n "$PKGNAME" ]; then
BASEPKGNAME=$(basename $PKGNAME)
fi
@@ -232,14 +203,19 @@ if isinstalled $name; then
fi
if [ "$ALREADYINSTALLED" = "yes" ] && [ ! "$UPGRADE_PKG" ] && [ ! "$REINSTALL_PKG" ]; then
msg "Package '$name' already installed. ($iversion-$irelease)"
echo "Package '$name' already installed. ($iversion-$irelease)"
ret 0
fi
echo -ne "Loading $BASEPKGNAME...\033[0K\r"
TMP_PKGADD="$(mktemp)" || exit 1
TMP_PKGINSTALL="$(mktemp)" || exit 1
TMP_PKGINSTALL_BKP="$(mktemp)" || exit 1
TMP_PKGADD_RMLIST="$(mktemp)" || exit 1
# check integrity of package
tar -tf $PKGNAME > $TMP_PKGADD/files 2>/dev/null
tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null
if [ $? != 0 ]; then
msgerr "Package '$1' is corrupted!"
ret 1
@@ -254,21 +230,20 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
fi
if [ "$UPGRADE_PKG" ]; then
if [ "$version-$release" = "$iversion-$irelease" ]; then
msg "Package '$name' is up-to-date. ($iversion-$irelease)"
echo "Package '$name' is up-to-date. ($iversion-$irelease)"
ret 0
fi
fi
fi
### INSTALL PACKAGE INTO SYSTEM ###
opr=Installing; oprdone=installed
[ "$UPGRADE_PKG" ] && { opr=Upgrading; oprdone=upgraded; }
[ "$REINSTALL_PKG" ] && { opr=Reinstalling; oprdone=reinstalled; }
[ "$SILENT_INSTALL" ] || msg "$opr '$name-$version-$release'..."
opr=Installing
[ "$UPGRADE_PKG" ] && opr=Upgrading
[ "$REINSTALL_PKG" ] && opr=Reinstalling
echo "$opr '$name-$version-$release'..."
#ignore conflict
if [ ! "$IGNORE_CONFLICT" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Checking file conflict..."
while IFS=' ' read -r line; do
if [ "$line" = "${line%.*}.spkgnew" ]; then
line=${line%.*}
@@ -282,19 +257,18 @@ if [ ! "$IGNORE_CONFLICT" ]; then
fileconflict+=(${line})
fi
fi
done < <(cat $TMP_PKGADD/files | grep -Ev '(.pkginfo|.pkginstall|.pkgreadme)' | grep -v '/$')
done < <(cat $TMP_PKGADD | grep -Ev '(.pkginfo|.pkginstall|.pkgreadme)' | grep -v '/$')
if [ "${#fileconflict[@]}" -gt 0 ]; then
[ "$SILENT_INSTALL" ] && echo
msgerr "File conflict found:"
for fc in ${fileconflict[@]}; do
msg2 "$fc"
echo "$fc"
done
ret 1
fi
fi
if [ $(grep -x .pkginstall $TMP_PKGADD/files) ]; then
if [ $(grep -x .pkginstall $TMP_PKGADD) ]; then
source <(tar -xf "$PKGNAME" .pkginstall -O)
fi
@@ -302,7 +276,6 @@ fi
( cd $ROOT/
if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
if [ "`type -t pre_install`" = "function" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Running preinstall script..."
pre_install "$version" &>/dev/null
fi
fi
@@ -312,23 +285,15 @@ fi
( cd $ROOT/
if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then
if [ "`type -t pre_upgrade`" = "function" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Running preupgrade script..."
pre_upgrade "$version" "$iversion" &>/dev/null
fi
fi
)
#installing package into system
total=$(cat $TMP_PKGADD/files | grep -Ev '(.pkginfo|.pkginstall|.pkgreadme)' | wc -l)
count=0
[ "$SILENT_INSTALL" ] || msg2 "Extracting package..."
installcmd="tar --keep-directory-symlink -p -x -v -f $PKGNAME -C ${ROOT:-/} --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme"
rm -f $TMP_PKGINSTALL $TMP_PKGINSTALL_BKP
$installcmd | while IFS=' ' read line; do
count=$(( $count + 1 ))
[ "$SILENT_INSTALL" ] && echo -ne "$opr $name-$version-$release [ $(( 100*$count/$total ))% ]\r"
if [ "$line" = "${line%.*}.spkgnew" ]; then
echo "$line" >> $TMP_PKGINSTALL_BKP
line=${line%.*}
@@ -340,17 +305,17 @@ $installcmd | while IFS=' ' read line; do
mv "$ROOT/$line".spkgnew "$ROOT/$line"
fi
fi
[ "$VERBOSE_INSTALL" = yes ] && echo ">>> $line"
echo "$line" >> $TMP_PKGINSTALL
done
# remove old files from old package that not exist in new package
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Removing old files..."
grep -Fxv -f $TMP_PKGINSTALL $INDEX_DIR/$name/.files > $TMP_PKGADD/$name.rmlist
grep -v '/$' $TMP_PKGADD/$name.rmlist | while IFS=' ' read line; do
grep -Fxv -f $TMP_PKGINSTALL $INDEX_DIR/$name/.files > $TMP_PKGADD_RMLIST
grep -v '/$' $TMP_PKGADD_RMLIST | while IFS=' ' read line; do
rm "$ROOT/$line" &>/dev/null
done
grep '/$' $TMP_PKGADD/$name.rmlist | tac | while IFS=' ' read line; do
grep '/$' $TMP_PKGADD_RMLIST | tac | while IFS=' ' read line; do
if [ ! "$(grep -R --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then
rmdir "$ROOT/$line" &>/dev/null
fi
@@ -363,14 +328,13 @@ mkdir $INDEX_DIR/$name
echo "name = $name" > $INDEX_DIR/$name/.pkginfo
echo "version = $version" >> $INDEX_DIR/$name/.pkginfo
echo "release = $release" >> $INDEX_DIR/$name/.pkginfo
mv $TMP_PKGINSTALL $INDEX_DIR/$name/.files
[ -f $TMP_PKGINSTALL_BKP ] && mv $TMP_PKGINSTALL_BKP $INDEX_DIR/$name/.bkpfiles
install -m644 $TMP_PKGINSTALL $INDEX_DIR/$name/.files
[ -f $TMP_PKGINSTALL_BKP ] && install -m644 $TMP_PKGINSTALL_BKP $INDEX_DIR/$name/.bkpfiles
tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginstall .pkgreadme >/dev/null 2>&1
( cd $ROOT/
if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
if [ "`type -t post_install`" = "function" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Running postinstall script..."
post_install "$version" &>/dev/null
fi
fi
@@ -379,7 +343,6 @@ tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginstall .pkgreadme >/dev/null 2>&1
( cd $ROOT/
if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then
if [ "`type -t post_upgrade`" = "function" ]; then
[ "$SILENT_INSTALL" ] || msg2 "Running postupgrade script..."
post_upgrade "$version" "$iversion" &>/dev/null
fi
fi
@@ -390,12 +353,6 @@ if [ "$ROOT" = "" ]; then
[ $(type -p sysusers) ] && sysusers
fi
if [ "$SILENT_INSTALL" ]; then
echo
else
msg "Package '$name-$version-$release' $oprdone."
fi
# running ldconfig
if [ -x /sbin/ldconfig ]; then
/sbin/ldconfig -r $ROOT/

128
pkgbuild
View File

@@ -18,26 +18,20 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
CYAN='\e[0;36m'
CRESET='\e[0m'
msg() {
echo -e "${GREEN}==>${CRESET} $1"
echo -e "==> $1"
}
msg2() {
echo -e " ${CYAN}*${CRESET} $1"
echo -e " -> $1"
}
msgerr() {
echo -e "${RED}==> ERROR:${CRESET} $1"
echo -e "==> ERROR: $1"
}
msgwarn() {
echo -e "${YELLOW}==> WARNING:${CRESET} $1"
echo -e "==> WARNING: $1"
}
updatemdsum() {
@@ -127,7 +121,10 @@ download_src() {
FILENAME=$(basename $FILE)
SRCURL=$FILE
fi
WGETCMD="wget -c --passive-ftp --no-directories --tries=3 --waitretry=3 --output-document=$SOURCE_DIR/$FILENAME.partial"
case $DOWNLOAD_PROG in
curl) DLCMD="curl -C - --fail --ftp-pasv --retry 3 --retry-delay 3 -o $SOURCE_DIR/$FILENAME.partial $CURL_OPTS" ;;
wget) DLCMD="wget -c --passive-ftp --no-directories --tries=3 --waitretry=3 --output-document=$SOURCE_DIR/$FILENAME.partial $WGET_OPTS" ;;
esac
if [ "$FILENAME" != "$FILE" ]; then
if [ -f "$SOURCE_DIR/$FILENAME" ] && [ -z "$REDOWNLOAD_SOURCE" ]; then
msg "Source '$FILENAME' found."
@@ -138,7 +135,7 @@ download_src() {
else
msg "Downloading '$SRCURL'."
fi
$WGETCMD $SRCURL
$DLCMD $SRCURL
if [ $? = 0 ]; then
[ "$REDOWNLOAD_SOURCE" ] && rm -f "$SOURCE_DIR/$FILENAME"
mv $SOURCE_DIR/$FILENAME.partial $SOURCE_DIR/$FILENAME
@@ -218,7 +215,7 @@ prepare_src() {
runprebuildscript() {
if [ "`type -t pre_build`" = "function" ]; then
pre_build && PREBUILD_STATUS=OK || PREBUILD_STATUS=KO
pre_build
fi
}
@@ -255,7 +252,6 @@ run_build() {
purgefiles() {
local OPTIONS
[ "${#PURGE_FILES[@]}" -gt 0 ] || return 0
msg2 "Purging unwanted files..."
for OPTIONS in ${PURGE_FILES[@]}; do
if [ -e $OPTIONS ]; then
rm -fr $OPTIONS
@@ -264,26 +260,14 @@ purgefiles() {
}
removeemptydirs() {
msg2 "Removing empty directories..."
find . -type d -empty -delete
}
removedocs() {
local OPTIONS
[ "${#DOC_DIRS[@]}" -gt 0 ] || return 0
msg2 "Removing docs..."
for OPTIONS in ${DOC_DIRS[@]}; do
[ -d $OPTIONS ] && rm -fr $OPTIONS
done
}
removelibtool() {
msg2 "Removing libtool files..."
find . ! -type d -name "*.la" -delete
}
strip_files() {
msg2 "Stripping binaries & libraries..."
strip_files() {
find . -type f 2>/dev/null | while read -r binary ; do
case "$(file -bi "$binary")" in
*application/x-sharedlib*) # Libraries (.so)
@@ -307,30 +291,23 @@ strip_files() {
done
}
compressinfomanpages() {
msg2 "Compressing man & info pages..."
for mandir in ${MAN_DIRS[@]}; do
if [ -d $mandir ]; then
(cd $mandir
for file in $(find . -type f); do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 -f "$file"
fi
done
for i in $(find . -type l) ; do
FILE="${i%%.gz}.gz"
TARGET="$(readlink $i)"
TARGET="${TARGET##*/}"
TARGET="${TARGET%%.gz}.gz"
DIR=$(dirname "$FILE")
rm -f $i
if [ -e "$DIR/$TARGET" ]; then
ln -sf $TARGET $FILE
fi
done
)
compressinfomanpages() {
find . -type f -path "*/man/man*/*" | while read file; do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 -f "$file"
fi
done
done
find . -type l -path "*/man/man*/*" | while read file; do
FILE="${file%%.gz}.gz"
TARGET="$(readlink $file)"
TARGET="${TARGET##*/}"
TARGET="${TARGET%%.gz}.gz"
DIR=$(dirname "$FILE")
rm -f $file
if [ -e "$DIR/$TARGET" ]; then
ln -sf $TARGET $FILE
fi
done
if [ -d usr/share/info ]; then
(cd usr/share/info
for file in $(find . -type f); do
@@ -357,14 +334,14 @@ backupconf() {
packaging() {
local FILE
[ -f install ] && cp install $PKG/.pkginstall
[ -f readme ] && cp readme $PKG/.pkgreadme
[ -f install ] && install -m644 install $PKG/.pkginstall
[ -f readme ] && install -m644 readme $PKG/.pkgreadme
pushd $PKG >/dev/null
[ "$PURGE_FILE" = 1 ] && purgefiles
rm -f usr/{,share/}info/dir
[ "$KEEP_EMPTYDIR" = 0 ] && removeemptydirs
[ "$KEEP_DOC" = 0 ] && removedocs
[ "$KEEP_LIBTOOL" = 0 ] && removelibtool
[ "$STRIP_BINARY" = 1 ] && strip_files
[ "$ZIP_MAN" = 1 ] && compressinfomanpages
@@ -373,7 +350,6 @@ packaging() {
backupconf
fi
msg2 "Compressing package..."
for FILE in .pkginstall .pkgreadme; do
if [ -f $FILE ]; then
addtotar+=($FILE)
@@ -384,24 +360,15 @@ packaging() {
tar -c -J -p -f $PACKAGE_DIR/$PKGNAME * "${addtotar[@]}"
if [ $? != 0 ]; then
msgerr "Packaging failed."
if [ -f $PACKAGE_DIR/$PKGNAME ]; then
rm $PACKAGE_DIR/$PKGNAME
fi
rm -f $PACKAGE_DIR/$PKGNAME
msgerr "Packaging '$PKGNAME' failed."
abort 1
fi
tar -tvf $PACKAGE_DIR/$PKGNAME
pkgsize="$(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}')"
if [ "$VERBOSE" ]; then
tar -t -v -f $PACKAGE_DIR/$PKGNAME
fi
msg "Successfully created package '$PKGNAME'. (${pkgsize})"
case $PREBUILD_STATUS in
OK) msg2 "prebuild : ${GREEN}OK${CRESET}" ;;
KO) msg2 "prebuild : ${RED}FAIL${CRESET}" ;;
esac
popd >/dev/null
}
@@ -445,10 +412,6 @@ set_options() {
!emptydirs) KEEP_EMPTYDIR=0;;
strip) STRIP_BINARY=1 ;;
!strip) STRIP_BINARY=0 ;;
docs) KEEP_DOC=1 ;;
!docs) KEEP_DOC=0 ;;
purge) PURGE_FILE=1 ;;
!purge) PURGE_FILE=0 ;;
zipman) ZIP_MAN=1 ;;
!zipman) ZIP_MAN=0 ;;
buildflags) BUILD_FLAGS=1 ;;
@@ -504,13 +467,6 @@ Options:
--no-color disable color
--no-backup skip backup configuration file when upgrading package
--redownload re-download source file
Example:
$(basename $0) -irw this will force rebuild, install package and keep working directory
Note:
* use $(basename $0) without any options will only download source and build package by using other default options
* $(basename $0) need to run inside port directory
EOF
}
@@ -542,8 +498,7 @@ extract_opt() {
echo ${BOPTS[@]}
}
parse_opts() {
parse_opts() {
while [ "$1" ]; do
case $1 in
-i | --install) INSTALL_PKG=yes ;;
@@ -573,8 +528,7 @@ parse_opts() {
*) msg "Invalid $(basename $0) option! ($1)"; exit 1 ;;
esac
shift
done
done
}
main() {
@@ -658,7 +612,7 @@ main() {
# build package
if [ -f "$PACKAGE_DIR/$PKGNAME" ] && [ ! "$FORCE_REBUILD" ]; then
if [ ! "$INSTALL_PKG" ] && [ ! "$REINSTALL_PKG" ] && [ ! "$UPGRADE_PKG" ]; then
msg "Package '$PKGNAME' is up-to-date."
echo "Package '$PKGNAME' is up-to-date."
abort 0
fi
else
@@ -680,16 +634,16 @@ main() {
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
export LC_ALL=C
PKGBUILD_CONF="/etc/scratchpkg.conf"
PKGBUILD_BSCRIPT="spkgbuild"
SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages"
WORK_DIR="/tmp"
DOWNLOAD_PROG="wget"
OPTIONS=(!libtool emptydirs strip docs purge zipman buildflags makeflags)
DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
MAN_DIRS=({usr{,/local}{,/share},opt/*}/man)
PURGE_FILES=(usr/{,share/}info/dir)
OPTIONS=(!libtool emptydirs strip zipman buildflags makeflags)
main "$@"

98
pkgdel
View File

@@ -18,52 +18,38 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
CYAN='\e[0;36m'
CRESET='\e[0m'
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
export LC_ALL=C
interrupted() {
echo
ret 1
}
nocolor() {
RED=
GREEN=
YELLOW=
CYAN=
CRESET=
}
msg() {
echo -e "${GREEN}==>${CRESET} $1"
echo -e "==> $1"
}
msg2() {
echo -e " ${CYAN}*${CRESET} $1"
echo -e " -> $1"
}
msgerr() {
echo -e "${RED}==> ERROR:${CRESET} $1"
echo -e "==> ERROR: $1"
}
msgwarn() {
echo -e "${YELLOW}==> WARNING:${CRESET} $1"
echo -e "==> WARNING: $1"
}
runremovehooks() {
runremovehooks() {
if [ "${#runthishook[@]}" -gt 0 ]; then
for hook in ${runthishook[@]}; do
description=$(cat "$hook" | grep ^"# description" | sed 's/\://' | cut -d ' ' -f 3-)
operation=$(cat "$hook" | grep ^"# operation" | sed 's/\://' | cut -d ' ' -f 3-)
target=$(cat "$hook" | grep ^"# target" | sed 's/\://' | cut -d ' ' -f 3-)
if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ]; then
[ "$SILENT_REMOVE" ] || msg2 "$description"
. $hook
if [ "`type -t exechook`" = "function" ]; then
exechook
@@ -72,12 +58,10 @@ runremovehooks() {
unset description operation target
unset -f exechook
done
fi
fi
}
runpreremovehooks() {
runpreremovehooks() {
for hook in $HOOK_DIR/*.hook; do
[ -f $hook ] || continue
operation=$(cat "$hook" | grep ^"# operation" | sed 's/\://' | cut -d ' ' -f 3-)
@@ -88,8 +72,7 @@ runpreremovehooks() {
fi
fi
unset operation target
done
done
}
help() {
@@ -98,18 +81,11 @@ Usage:
$(basename $0) [ <options> <package name> ]
Options:
-v, --verbose print removed files
-h, --help show this help message
-s, --silent print remove message in simple format
--no-preremove don't run pre-remove script
--no-postremove don't run post-remove script
--no-color disable colour for output
--no-hook skip executing hook
--root=<path> remove package from custom root directory
Example:
$(basename $0) firefox -dv --no-preremove remove package firefox, skipping dependency check,
print deleted files and skipp pre-remove script
EOF
}
@@ -124,28 +100,24 @@ extract_opt() {
echo ${OPTS[@]}
}
parse_opts() {
parse_opts() {
if [ -z "$1" ]; then
SHOWHELP=yes
else
while [ "$1" ]; do
case $1 in
-v | --verbose) VERBOSE_REMOVE=yes ;;
-h | --help) SHOWHELP=yes ;;
-s | --silent) SILENT_REMOVE=yes ;;
-v | --verbose) VERBOSE_REMOVE=yes ;;
--no-preremove) NO_PREREMOVE=yes ;;
--no-postremove) NO_POSTREMOVE=yes ;;
--no-color) NOCOLOR=yes ;;
--no-hook) NOHOOK=yes ;;
--no-hook) NOHOOK=yes ;;
--root=*) ROOT="${1#*=}" ;;
-*) msg "Invalid option: ($1)"; exit 1 ;;
*) RMNAME=$1 ;;
esac
shift
done
fi
fi
}
ret() {
@@ -174,11 +146,6 @@ if [ "$SHOWHELP" ] || [ -z "$RMNAME" ]; then
help
ret 0
fi
# disable color for output
if [ "$NOCOLOR" ]; then
nocolor
fi
# check for lock file
if [ -f $LOCK_FILE ]; then
@@ -213,11 +180,7 @@ if [ -z $name ] && [ -z $version ] && [ -z $release ]; then
ret 1
fi
if [ "$SILENT_REMOVE" ]; then
echo -ne "Removing $name-$version-$release "
else
msg "Removing '$name-$version-$release'..."
fi
echo "Removing '$name-$version-$release'..."
# source .install script
if [ "$ROOT" = "" ]; then
@@ -228,36 +191,41 @@ fi
if [ ! "$NO_PREREMOVE" ]; then
if [ "`type -t pre_remove`" = "function" ]; then
[ "$SILENT_REMOVE" ] || msg2 "Running preremove script..."
pre_remove "$version" &>/dev/null
fi
fi
if [ "$ROOT" = "" ] && [ "$NOHOOK" != "yes" ]; then
runpreremovehooks $name
runpreremovehooks $name &>/dev/null
fi
if [ -f "$INDEX_DIR/$name/.bkpfiles" ]; then
[ "$SILENT_REMOVE" ] || msg2 "Removing backup files..."
while IFS=' ' read -r line; do
[ -e "$ROOT/$line" ] && rm "$ROOT/$line"
if [ -e "$ROOT/$line" ]; then
[ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line"
rm "$ROOT/$line"
fi
done < <(tac $INDEX_DIR/$name/.bkpfiles)
fi
[ "$SILENT_REMOVE" ] || msg2 "Removing files & dirs..."
while IFS=' ' read -r line; do
rm "$ROOT/$line" &>/dev/null
if [ -e $ROOT/$line ]; then
[ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line"
rm "$ROOT/$line"
fi
done < <(tac $INDEX_DIR/$name/.files | grep -v '/$')
while IFS=' ' read -r line; do
if [ ! "$(grep -R --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then
rmdir "$ROOT/$line" &>/dev/null
if [ -d $ROOT/$line ]; then
[ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line"
rmdir "$ROOT/$line"
fi
fi
done < <(tac $INDEX_DIR/$name/.files | grep '/$')
if [ ! "$NO_POSTREMOVE" ]; then
if [ "`type -t post_remove`" = "function" ]; then
[ "$SILENT_REMOVE" ] || msg2 "Running postremove script..."
post_remove "$version" &>/dev/null
fi
fi
@@ -268,15 +236,9 @@ if [ "$ROOT" = "" ] && [ "$NOHOOK" != "yes" ]; then
runremovehooks
fi
if [ "$SILENT_REMOVE" ]; then
echo "[ done ]"
else
msg "Package '$name-$version-$release' removed."
fi
# running ldconfig
if [ "$ROOT" = "" ] && [ -x /sbin/ldconfig ]; then
/sbin/ldconfig
if [ -x /sbin/ldconfig ]; then
/sbin/ldconfig -r $ROOT/
fi
ret 0

View File

@@ -18,29 +18,23 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
CYAN='\e[0;36m'
CRESET='\e[0m'
INDEX_DIR="/var/lib/scratchpkg/index"
REPO_FILE="/etc/scratchpkg.repo"
msgerr() {
echo -e "${RED}==> ERROR:${CRESET} $1"
echo -e "==> ERROR: $1"
}
msginst() {
echo -e "[${GREEN}i${CRESET}] $1"
echo -e "[i] $1"
}
msgmiss() {
echo -e "[${YELLOW}m${CRESET}] $1"
echo -e "[m] $1"
}
msgnoinst() {
echo -e "[${RED}-${CRESET}] $1"
echo -e "[-] $1"
}
checkdep() {
@@ -48,7 +42,6 @@ checkdep() {
PORT_PATH=$(getportpath "$1")
if [ "$PORT_PATH" ]; then
depends=$(grep "^# depends[[:blank:]]*:" $PORT_PATH/spkgbuild | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' | tr ' ' '\n' | awk '!a[$0]++')
#source $PORT_PATH/spkgbuild
for dep in ${depends[@]}; do
echo $dep
done
@@ -128,6 +121,7 @@ while [ "$1" ]; do
-m|--missing) MISSING=1 ;;
-l|--loop) IGNORE_LOOP=1 ;;
-h|--help) USAGE=1 ;;
-*) msgerr "Invalid option. ($1)"; exit 1 ;;
*) PKG+=($1) ;;
esac
shift
@@ -162,14 +156,6 @@ if [ ! "$INSTALLED" ] && [ ! "$NOT_INSTALLED" ] && [ ! "$MISSING" ]; then
MISSING=1
fi
# check for ports existence
#for pkg in ${PKG[@]}; do
#if [ ! $(getportpath $pkg) ]; then
#msgerr "Package '$pkg' not found."
#exit 1
#fi
#done
# calculate dependencies
for pkg in ${PKG[@]}; do
deplist $pkg

7
revdep
View File

@@ -105,7 +105,7 @@ rebuild() {
read
fi
for p in $order; do
scratch build -f $p && scratch install -r $p || exit 1
scratch build -f $p && scratch install -r $p || { cleanup; exit 1; }
done
}
@@ -154,8 +154,7 @@ done
TARGET_SEARCH_DIRS="/bin /usr/bin /sbin /usr/sbin /lib /usr/lib /lib64 /usr/libexec $EXTRA_SEARCH_DIRS"
INDEX_DIR="/var/lib/scratchpkg/index"
FILE_LIST=/tmp/$(basename $0)-$$
touch $FILE_LIST || { echo "Can't create temporary file .Aborting..."; exit 1; }
FILE_LIST=$(mktemp) || { echo "Can't create temporary file .Aborting..."; exit 1; }
echo "SEARCH DIRS:"
for d in $TARGET_SEARCH_DIRS; do
@@ -234,4 +233,6 @@ else
echo "All packages is doing fine."
fi
cleanup
exit 0

14
scratch
View File

@@ -579,7 +579,7 @@ installpkg() {
echo "Package '$ii' not installed."
else
pushd $(getportpath $ii)
pkgbuild -s --no-hook ${OPTS[@]}
pkgbuild --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break
@@ -650,7 +650,7 @@ installpkg() {
pushd $portpathh
. $BUILD_SCRIPT
settermtitle "[ $count/$total ] installing $name-$version-$release"
pkgbuild -is --no-hook ${OPTS[@]}
pkgbuild -i --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break
@@ -738,7 +738,7 @@ removepkg() {
count=$(( $count + 1 ))
srunpreremovehooks $pkg
settermtitle "[ $count/$pkgcount ] Removing $pkg"
pkgdel -s --no-hook $pkg ${OPTS[@]} || return 1
pkgdel --no-hook $pkg ${OPTS[@]} || return 1
done
settermtitle "Triggering remove hook"
srunremovehooks
@@ -801,14 +801,14 @@ sysup() {
. $BUILD_SCRIPT
if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $name-$version-$release"
pkgbuild -is --no-hook ${OPTS[@]}
pkgbuild -i --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break
fi
else
settermtitle "[ $count/$total ] Upgrading $name-$version-$release"
pkgbuild -us --no-hook ${OPTS[@]}
pkgbuild -u --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break
@@ -894,7 +894,7 @@ upgradepkg() {
pushd $(getportpath $newpkg)
. $BUILD_SCRIPT
settermtitle "[ $count/$total ] Installing $name-$version-$release"
pkgbuild -is --no-hook ${OPTS[@]}
pkgbuild -i --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break
@@ -907,7 +907,7 @@ upgradepkg() {
pushd $(getportpath $pkg)
. $BUILD_SCRIPT
settermtitle "[ $count/$total ] Upgrading $name-$version-$release"
pkgbuild -us --no-hook ${OPTS[@]}
pkgbuild -u --no-hook ${OPTS[@]}
if [ $? != 0 ]; then
error=1
break

View File

@@ -2,23 +2,17 @@
# Configuration file for scratchpkg
#
##
## COMPILE FLAGS
##
CFLAGS="-O2 -march=x86-64 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEFLAGS="-j$(nproc)"
##
## PATH
##
# -- Default path for some configuration
# -- Uncomment and change it if you want change these path
#
# SOURCE_DIR="/var/cache/scratchpkg/sources"
# PACKAGE_DIR="/var/cache/scratchpkg/packages"
# WORK_DIR="/tmp"
# HOOK_DIR="/etc/hooks"
# DOWNLOAD_PROG="wget"
# WGET_OPTS=""
# CURL_OPTS=""
##
## GLOBAL PACKAGE OPTIONS
@@ -26,8 +20,6 @@ MAKEFLAGS="-j$(nproc)"
# -- libtool: Keep libtool file (*.la) in packages
# -- emptydirs: Keep empty directories in packages
# -- strip: Strip symbols from binaries/libraries
# -- docs: Keep docs directories specified by DOC_DIRS
# -- purge: Remove files specified in PURGE_FILES
# -- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
# -- buildflags: Enable buildflags (CFLAGS and CXXFLAGS)
# -- makeflags: Enable makeflags (MAKEFLAGS)
@@ -35,13 +27,4 @@ MAKEFLAGS="-j$(nproc)"
# -- These are default values for the options=() settings
# -- add '!' in front of this option to disable it
#
# OPTIONS=(!libtool emptydirs strip docs purge zipman buildflags makeflags)
# -- Files to be removed from all packages (if purge is specified)
# PURGE_FILES=(usr/{,share/}info/dir)
# -- Doc directories to remove (if !docs is specified)
# DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
# -- Manual (man and info) directories to compress (if zipman is specified)
# MAN_DIRS=({usr{,/local}{,/share},opt/*}/man)
# OPTIONS=(!libtool emptydirs strip zipman buildflags makeflags)