9 Commits
0.3 ... 0.5

Author SHA1 Message Date
emmett1
9b186bfd31 add logging, --log 2020-03-13 17:20:31 +08:00
emmett1
8e8c62d338 xchroot: add '-l' to umount 2020-03-05 17:32:54 +08:00
emmett1
c8b2eca5ba updated 2020-02-25 23:59:33 +08:00
emmett1
a23a22c659 fix scratch_upgrade 2020-02-25 18:07:35 +08:00
emmett1
9a06fbd474 fix pkgadd 2020-02-19 17:03:24 +08:00
emmett1
7a91fbdcd4 replace type with command 2020-02-19 15:23:42 +08:00
emmett1
00e55a2473 replace type with command 2020-02-19 00:39:34 +08:00
emmett1
0ee256b921 fix 2020-02-17 23:58:18 +08:00
emmett1
424c56f075 fix typo 2020-02-12 23:48:17 +08:00
8 changed files with 134 additions and 77 deletions

View File

@@ -15,6 +15,7 @@ install -d ${DESTDIR}${REVDEPD}
install -dm777 ${DESTDIR}${CACHE_DIR}/packages
install -dm777 ${DESTDIR}${CACHE_DIR}/sources
install -dm777 ${DESTDIR}${CACHE_DIR}/work
install -dm777 ${DESTDIR}${CACHE_DIR}/log
install -m755 xchroot revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf ${DESTDIR}${BINDIR}
install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias ${DESTDIR}${CONFDIR}

3
pkgadd
View File

@@ -140,7 +140,7 @@ LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"
}
[ -d "$ROOT_DIR/$INDEX_DIR" ] || {
msgerr "Package's database directory not exist! ($ROOT_DIR$/INDEX_DIR)"
msgerr "Package's database directory not exist! ($ROOT_DIR/$INDEX_DIR)"
ret 1
}
@@ -154,6 +154,7 @@ LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"
[ -f "$ROOT_DIR/$LOCK_FILE" ] && {
msgerr "Cant install/remove package simultaneously."
msgerr "remove '$ROOT_DIR/$LOCK_FILE' if no install/remove package process running."
exit 1
}
touch "$ROOT_DIR/$LOCK_FILE" 2>/dev/null || {

View File

@@ -98,9 +98,14 @@ download_src() {
FILENAME=$(basename $FILE)
SRCURL=$FILE
fi
[ "$DOWNLOAD_PROG" = "auto" ] && {
command -v curl >/dev/null && DOWNLOAD_PROG=curl
command -v wget >/dev/null && DOWNLOAD_PROG=wget
}
case $DOWNLOAD_PROG in
curl) DLCMD="curl -C - -L --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" ;;
*) msgerr "No download agent found"; abort 1;;
esac
if [ "$FILENAME" != "$FILE" ]; then
if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then
@@ -158,7 +163,7 @@ prepare_src() {
if [ "$FILENAME" != "$FILE" ] && [ "$nxt" != 1 ]; then
case $FILENAME in
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
if [ $(type -p bsdtar) ]; then
if [ $(command -v bsdtar) ]; then
COMMAND="bsdtar -p -o -C $SRC -xf $FILENAME"
else
COMMAND="tar -p -o -C $SRC -xf $FILENAME"
@@ -415,7 +420,7 @@ check_buildscript() {
elif [ -z "$release" ]; then
msgerr "'release' is empty!"
exit 1
elif [ "$(type -t build)" != "function" ]; then
elif [ ! "$(command -v build)" ]; then
msgerr "'build' function not exist!"
exit 1
elif echo "$version" | grep -q '-'; then
@@ -691,7 +696,7 @@ PKGBUILD_BSCRIPT="spkgbuild"
SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages"
WORK_DIR="/var/cache/scratchpkg/work"
DOWNLOAD_PROG="wget"
DOWNLOAD_PROG="auto"
COMPRESSION_MODE="xz"
OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales"

View File

@@ -350,7 +350,7 @@ fi
shift
if [ $(type -t pkg_$opts) ]; then
if [ $(command -v pkg_$opts) ]; then
pkg_$opts "$@"
else
print_runhelp_msg

178
scratch
View File

@@ -133,7 +133,7 @@ confirm() {
}
checktool() {
if ! type -p $1 >/dev/null; then
if ! command -v $1 >/dev/null; then
msgerr "'$1' not exist in your system!"
exit 1
fi
@@ -286,37 +286,37 @@ post_triggers() {
done
fi
if [ "$trig_11" = 1 ] && [ $(type -p fc-cache) ]; then
if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then
echo "trigger: Updating fontconfig cache..."
fc-cache -s
fi
if [ "$trig_10" = 1 ] && [ $(type -p gdk-pixbuf-query-loaders) ]; then
if [ "$trig_10" = 1 ] && [ $(command -v gdk-pixbuf-query-loaders) ]; then
echo "trigger: Probing GDK-Pixbuf loader modules..."
gdk-pixbuf-query-loaders --update-cache
fi
if [ "$trig_9" = 1 ] && [ $(type -p gio-querymodules) ]; then
if [ "$trig_9" = 1 ] && [ $(command -v gio-querymodules) ]; then
echo "trigger: Updating GIO module cache..."
gio-querymodules /usr/lib/gio/modules
fi
if [ "$trig_8" = 1 ] && [ $(type -p glib-compile-schemas) ]; then
if [ "$trig_8" = 1 ] && [ $(command -v glib-compile-schemas) ]; then
echo "trigger: Compiling GSettings XML schema files..."
glib-compile-schemas /usr/share/glib-2.0/schemas
fi
if [ "$trig_7" = 1 ] && [ $(type -p gtk-query-immodules-2.0) ]; then
if [ "$trig_7" = 1 ] && [ $(command -v gtk-query-immodules-2.0) ]; then
echo "trigger: Probing GTK2 input method modules..."
gtk-query-immodules-2.0 --update-cache
fi
if [ "$trig_6" = 1 ] && [ $(type -p gtk-query-immodules-3.0) ]; then
if [ "$trig_6" = 1 ] && [ $(command -v gtk-query-immodules-3.0) ]; then
echo "trigger: Probing GTK3 input method modules..."
gtk-query-immodules-3.0 --update-cache
fi
if [ "$trig_5" = 1 ] && [ $(type -p gtk-update-icon-cache) ]; then
if [ "$trig_5" = 1 ] && [ $(command -v gtk-update-icon-cache) ]; then
echo "trigger: Updating icon theme caches..."
for dir in /usr/share/icons/* ; do
if [ -e $dir/index.theme ]; then
@@ -328,12 +328,12 @@ post_triggers() {
done
fi
if [ "$trig_4" = 1 ] && [ $(type -p udevadm) ]; then
if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then
echo "trigger: Updating hardware database..."
udevadm hwdb --update
fi
if [ "$trig_3" = 1 ] && [ $(type -p mkfontdir) ] && [ $(type -p mkfontscale) ]; then
if [ "$trig_3" = 1 ] && [ $(command -v mkfontdir) ] && [ $(command -v mkfontscale) ]; then
echo "trigger: Updating X fontdir indices..."
for dir in $(find /usr/share/fonts -maxdepth 1 -type d \( ! -path /usr/share/fonts -a ! -name X11 \)) /usr/share/fonts/X11/*; do
rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid
@@ -344,12 +344,12 @@ post_triggers() {
done
fi
if [ "$trig_2" = 1 ] && [ $(type -p update-desktop-database) ]; then
if [ "$trig_2" = 1 ] && [ $(command -v update-desktop-database) ]; then
echo "trigger: Updating desktop file MIME type cache..."
update-desktop-database --quiet
fi
if [ "$trig_1" = 1 ] && [ $(type -p update-mime-database) ]; then
if [ "$trig_1" = 1 ] && [ $(command -v update-mime-database) ]; then
echo "trigger: Updating the MIME type database..."
update-mime-database /usr/share/mime
fi
@@ -481,6 +481,7 @@ scratch_build() {
while [ "$1" ]; do
case $1 in
-i|-u|-r|-g|-p) ;;
--log) LOGBUILD=1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
esac
@@ -497,7 +498,12 @@ scratch_build() {
}
cd $ppath
settermtitle "Building $pkg..."
pkgbuild $OPTS || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS | tee $LOG_DIR/$pkg.log
else
pkgbuild $OPTS
fi
[ "$?" = 0 ] || {
settermtitle "Building $pkg failed."
return 1
}
@@ -514,6 +520,7 @@ scratch_install() {
-r|--reinstall) REINSTALL=1;;
-y|--yes) NOCONFIRM=1;;
-n|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
@@ -535,7 +542,12 @@ scratch_install() {
else
cd $(getportpath $ii)
settermtitle "Reinstalling $ii..."
pkgbuild $OPTS -r || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -r | tee $LOG_DIR/$ii.log
else
pkgbuild $OPTS -r
fi
[ "$?" = 0 ] || {
error=1
break
}
@@ -559,7 +571,12 @@ scratch_install() {
else
cd $(getportpath $ii)
settermtitle "Installing $ii..."
pkgbuild -i $OPTS || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$ii.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1
break
}
@@ -606,7 +623,12 @@ scratch_install() {
if portpathh=$(getportpath $int); then
cd $portpathh
settermtitle "[ $count/$total ] installing $int..."
pkgbuild -i $OPTS || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$int.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
@@ -700,6 +722,7 @@ scratch_sysup() {
-i|-u|-r) ;;
-y|--yes) NOCONFIRM=1;;
-n|--no-dep) NODEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
esac
@@ -756,14 +779,24 @@ scratch_sysup() {
cd $(getportpath $inst)
if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..."
pkgbuild -i $OPTS || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
}
else
settermtitle "[ $count/$total ] Upgrading $inst..."
pkgbuild -u $OPTS || {
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -u | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS-u
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
@@ -785,6 +818,7 @@ scratch_upgrade() {
-i|-r) ;;
-y|--yes) NOCONFIRM=1;;
-d|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";;
@@ -797,78 +831,89 @@ scratch_upgrade() {
}
for pkg in $PKGNAME; do
if ! isinstalled $pkg; then
msgerr "Package '$pkg' not installed."
echo "Package '$pkg' not installed."
continue
elif [ ! $(getportpath $pkg) ]; then
msgerr "Package '$pkg' not exist."
echo "Package '$pkg' not exist."
continue
else
. $(getportpath $pkg)/$BUILD_SCRIPT
if [ "$(installed_pkg_info version $pkg)-$(installed_pkg_info release $pkg)" = "$version-$release" ]; then
msg "Package '$pkg' is up to date."
echo "Package '$pkg' is up to date."
continue
fi
fi
upkg="$upkg $pkg"
done
[ "$upkg" ] || return 0
[ "$NO_DEP" ] || {
UPGPKG=0
NEWPKG=0
if [ "$NODEP" != 1 ]; then
echo "Resolving dependencies..."
DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}')
for dep in $DEP; do
if ! isinstalled $dep; then
[ "$(getportpath $dep)" ] && newpkg="$newpkg $dep"
echo
for d in $DEP; do
if [ "$(echo $upkg | tr ' ' '\n' | grep -x $d)" = "$d" ]; then
printf "[${GREEN}u${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
UPGPKG=$(( UPGPKG + 1 ))
elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then
printf "[${CYAN}n${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
NEWPKG=$(( NEWPKG + 1 ))
fi
done
}
echo
tnew=0
tup=0
for i in $newpkg; do
tnew=$(( tnew + 1 ))
printf "[${CYAN}n${CRESET}] $i "
done
for i in $upkg; do
tup=$(( tup + 1 ))
printf "[${GREEN}u${CRESET}] $i "
done
else
echo
for dd in $upkg; do
printf "[${GREEN}u${CRESET}] $dd "
WILLINSTALL="$WILLINSTALL $dd"
UPGPKG=$(( UPGPKG + 1 ))
done
fi
echo; echo
echo "( $tup upgrade, $tnew new install )"
echo "( $UPGPKG upgrade, $NEWPKG new install )"
echo
[ "$NOCONFIRM" ] || {
confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $?
echo
}
total=$(( tup + tnew ))
count=0
error=0
if [ "$newpkg" ]; then
for pkg in $newpkg; do
count=$(( count + 1 ))
cd $(getportpath $pkg)
settermtitle "[ $count/$total ] Installing $pkg..."
pkgbuild -i $OPTS || {
error=1
count=$(( count - 1 ))
break
}
done_pkg="$done_pkg $pkg"
cd - >/dev/null
done
fi
for pkg in $upkg; do # upgrade all target packages
count=0
total=$(echo $WILLINSTALL | wc -w)
for inst in $WILLINSTALL; do # install all required dependencies and target packages itself
count=$(( count + 1 ))
cd $(getportpath $pkg)
settermtitle "[ $count/$total ] Upgrading $pkg..."
pkgbuild -u $OPTS || {
cd $(getportpath $inst)
if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..."
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
}
done_pkg="$done_pkg $pkg"
else
settermtitle "[ $count/$total ] Upgrading $inst..."
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -u | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -u
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
}
fi
cd - >/dev/null
done_pkg="$done_pkg $inst"
done
settermtitle "triggering upgrade hook..."
settermtitle "Triggering install hook."
[ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) upgraded."
return "$error"
@@ -1140,11 +1185,13 @@ Options:
-r|--reinstall reinstall
-n|--no-dep skip dependencies
-y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated
upgrade <ports> <arg> upgrade ports (use pkgbuild arg, except '-i' & '-r')
-n|--no-dep skip dependencies
-y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated
remove <ports> <arg> remove installed ports (use pkgdel arg)
@@ -1153,6 +1200,7 @@ Options:
sysup <arg> full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u')
-n|--no-dep skip dependencies
-y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated
deplist <ports> print all dependencies for ports
@@ -1160,6 +1208,7 @@ Options:
--exclude=* exclude dependencies, comma separated
build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p')
--log log build process
lock <ports> locking ports prevent upgrade
unlock <ports> unlock locked ports
@@ -1191,13 +1240,14 @@ ALIAS_FILE="/etc/scratchpkg.alias"
# default value from pkgbuild
SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages"
LOG_DIR="/var/cache/scratchpkg/log"
COMPRESSION_MODE="xz"
mode=$1
if [ -z "$mode" ]; then
[ "$mode" ] || {
print_runhelp_msg
fi
}
shift
@@ -1209,7 +1259,7 @@ for opt in $@; do
-*) char=${#opt}; count=1
while [ "$count" != "$char" ]; do
count=$((count+1))
MAINOPTS="$MAINOPTS -$(echo $opt | cut -c $count)"
MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)"
done;;
*) MAINOPTS="$MAINOPTS $opt";;
esac
@@ -1222,7 +1272,7 @@ if [ -f "$REPO_FILE" ]; then
done
fi
if [ "$(type -t scratch_$mode)" = "function" ]; then
if [ "$(command -v scratch_$mode)" ]; then
scratch_$mode $MAINOPTS
else
print_runhelp_msg

View File

@@ -9,7 +9,7 @@ MAKEFLAGS="-j$(nproc)"
# SOURCE_DIR="/var/cache/scratchpkg/sources"
# PACKAGE_DIR="/var/cache/scratchpkg/packages"
# WORK_DIR="/var/cache/scratchpkg/work"
# DOWNLOAD_PROG="wget"
# DOWNLOAD_PROG="auto"
# WGET_OPTS=""
# CURL_OPTS=""
# COMPRESSION_MODE="xz"

View File

@@ -20,7 +20,7 @@
EDITOR=${EDITOR:-vi}
type -p $EDITOR >/dev/null || {
command -v $EDITOR >/dev/null || {
echo "Editor '$EDITOR' not exist. Append 'EDITOR=<your editor>' to ${0##*/}."
exit 2
}

12
xchroot
View File

@@ -78,13 +78,13 @@ retval=$?
mv $TARGET/etc/resolv.conf.tmp $TARGET/etc/resolv.conf
}
umount $TARGET/dev/pts
umount $TARGET/dev
umount $TARGET/run
umount $TARGET/proc
umount -l $TARGET/dev/pts
umount -l $TARGET/dev
umount -l $TARGET/run
umount -l $TARGET/proc
if [ -n "$EFI_SYSTEM" ]; then
umount $TARGET/sys/firmware/efi/efivars
umount -l $TARGET/sys/firmware/efi/efivars
fi
umount $TARGET/sys
umount -l $TARGET/sys
exit $retval