4 Commits
0.4 ... 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
5 changed files with 112 additions and 56 deletions

View File

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

View File

@@ -98,9 +98,14 @@ download_src() {
FILENAME=$(basename $FILE) FILENAME=$(basename $FILE)
SRCURL=$FILE SRCURL=$FILE
fi fi
[ "$DOWNLOAD_PROG" = "auto" ] && {
command -v curl >/dev/null && DOWNLOAD_PROG=curl
command -v wget >/dev/null && DOWNLOAD_PROG=wget
}
case $DOWNLOAD_PROG in case $DOWNLOAD_PROG in
curl) DLCMD="curl -C - -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $SOURCE_DIR/$FILENAME.partial $CURL_OPTS" ;; 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" ;; 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 esac
if [ "$FILENAME" != "$FILE" ]; then if [ "$FILENAME" != "$FILE" ]; then
if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then
@@ -691,7 +696,7 @@ PKGBUILD_BSCRIPT="spkgbuild"
SOURCE_DIR="/var/cache/scratchpkg/sources" SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages" PACKAGE_DIR="/var/cache/scratchpkg/packages"
WORK_DIR="/var/cache/scratchpkg/work" WORK_DIR="/var/cache/scratchpkg/work"
DOWNLOAD_PROG="wget" DOWNLOAD_PROG="auto"
COMPRESSION_MODE="xz" COMPRESSION_MODE="xz"
OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales" OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales"

146
scratch
View File

@@ -481,6 +481,7 @@ scratch_build() {
while [ "$1" ]; do while [ "$1" ]; do
case $1 in case $1 in
-i|-u|-r|-g|-p) ;; -i|-u|-r|-g|-p) ;;
--log) LOGBUILD=1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
esac esac
@@ -497,7 +498,12 @@ scratch_build() {
} }
cd $ppath cd $ppath
settermtitle "Building $pkg..." 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." settermtitle "Building $pkg failed."
return 1 return 1
} }
@@ -514,6 +520,7 @@ scratch_install() {
-r|--reinstall) REINSTALL=1;; -r|--reinstall) REINSTALL=1;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-n|--no-dep) NO_DEP=1;; -n|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
@@ -535,7 +542,12 @@ scratch_install() {
else else
cd $(getportpath $ii) cd $(getportpath $ii)
settermtitle "Reinstalling $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 error=1
break break
} }
@@ -559,7 +571,12 @@ scratch_install() {
else else
cd $(getportpath $ii) cd $(getportpath $ii)
settermtitle "Installing $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 error=1
break break
} }
@@ -606,7 +623,12 @@ scratch_install() {
if portpathh=$(getportpath $int); then if portpathh=$(getportpath $int); then
cd $portpathh cd $portpathh
settermtitle "[ $count/$total ] installing $int..." 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 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
@@ -700,6 +722,7 @@ scratch_sysup() {
-i|-u|-r) ;; -i|-u|-r) ;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-n|--no-dep) NODEP=1;; -n|--no-dep) NODEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
esac esac
@@ -756,14 +779,24 @@ scratch_sysup() {
cd $(getportpath $inst) cd $(getportpath $inst)
if ! isinstalled $inst; then if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..." 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 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
} }
else else
settermtitle "[ $count/$total ] Upgrading $inst..." 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 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
@@ -785,6 +818,7 @@ scratch_upgrade() {
-i|-r) ;; -i|-r) ;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-d|--no-dep) NO_DEP=1;; -d|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
@@ -797,78 +831,89 @@ scratch_upgrade() {
} }
for pkg in $PKGNAME; do for pkg in $PKGNAME; do
if ! isinstalled $pkg; then if ! isinstalled $pkg; then
msgerr "Package '$pkg' not installed." echo "Package '$pkg' not installed."
continue continue
elif [ ! $(getportpath $pkg) ]; then elif [ ! $(getportpath $pkg) ]; then
msgerr "Package '$pkg' not exist." echo "Package '$pkg' not exist."
continue continue
else else
. $(getportpath $pkg)/$BUILD_SCRIPT . $(getportpath $pkg)/$BUILD_SCRIPT
if [ "$(installed_pkg_info version $pkg)-$(installed_pkg_info release $pkg)" = "$version-$release" ]; then 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 continue
fi fi
fi fi
upkg="$upkg $pkg" upkg="$upkg $pkg"
done done
[ "$upkg" ] || return 0 [ "$upkg" ] || return 0
[ "$NO_DEP" ] || {
UPGPKG=0
NEWPKG=0
if [ "$NODEP" != 1 ]; then
echo "Resolving dependencies..." echo "Resolving dependencies..."
DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}')
for dep in $DEP; do echo
if ! isinstalled $dep; then for d in $DEP; do
[ "$(getportpath $dep)" ] && newpkg="$newpkg $dep" 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 fi
done done
} else
echo echo
tnew=0 for dd in $upkg; do
tup=0 printf "[${GREEN}u${CRESET}] $dd "
for i in $newpkg; do WILLINSTALL="$WILLINSTALL $dd"
tnew=$(( tnew + 1 )) UPGPKG=$(( UPGPKG + 1 ))
printf "[${CYAN}n${CRESET}] $i " done
done fi
for i in $upkg; do
tup=$(( tup + 1 ))
printf "[${GREEN}u${CRESET}] $i "
done
echo; echo echo; echo
echo "( $tup upgrade, $tnew new install )" echo "( $UPGPKG upgrade, $NEWPKG new install )"
echo echo
[ "$NOCONFIRM" ] || { [ "$NOCONFIRM" ] || {
confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $?
echo echo
} }
total=$(( tup + tnew ))
count=0
error=0 error=0
if [ "$newpkg" ]; then count=0
for pkg in $newpkg; do total=$(echo $WILLINSTALL | wc -w)
count=$(( count + 1 )) for inst in $WILLINSTALL; do # install all required dependencies and target packages itself
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=$(( count + 1 )) count=$(( count + 1 ))
cd $(getportpath $pkg) cd $(getportpath $inst)
settermtitle "[ $count/$total ] Upgrading $pkg..." if ! isinstalled $inst; then
pkgbuild -u $OPTS || { 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 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break 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 cd - >/dev/null
done_pkg="$done_pkg $inst"
done done
settermtitle "triggering upgrade hook..." settermtitle "Triggering install hook."
[ "$done_pkg" ] && scratch_trigger $done_pkg [ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) upgraded." settermtitle "$count/$total package(s) upgraded."
return "$error" return "$error"
@@ -1140,11 +1185,13 @@ Options:
-r|--reinstall reinstall -r|--reinstall reinstall
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
upgrade <ports> <arg> upgrade ports (use pkgbuild arg, except '-i' & '-r') upgrade <ports> <arg> upgrade ports (use pkgbuild arg, except '-i' & '-r')
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
remove <ports> <arg> remove installed ports (use pkgdel arg) 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') sysup <arg> full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u')
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
deplist <ports> print all dependencies for ports deplist <ports> print all dependencies for ports
@@ -1160,6 +1208,7 @@ Options:
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p')
--log log build process
lock <ports> locking ports prevent upgrade lock <ports> locking ports prevent upgrade
unlock <ports> unlock locked ports unlock <ports> unlock locked ports
@@ -1191,6 +1240,7 @@ ALIAS_FILE="/etc/scratchpkg.alias"
# default value from pkgbuild # default value from pkgbuild
SOURCE_DIR="/var/cache/scratchpkg/sources" SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages" PACKAGE_DIR="/var/cache/scratchpkg/packages"
LOG_DIR="/var/cache/scratchpkg/log"
COMPRESSION_MODE="xz" COMPRESSION_MODE="xz"
mode=$1 mode=$1

View File

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

12
xchroot
View File

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