This commit is contained in:
emmett1
2021-04-30 17:24:56 +08:00
parent b9e49bcfac
commit 278bc6c512
2 changed files with 43 additions and 69 deletions

View File

@@ -84,7 +84,7 @@ github_sync() {
echo "Failed fetching repo from $1"
exit 1
}
tar -tf $tarball.tar.xz &>/dev/null || {
tar -tf $tarball.tar.xz >/dev/null 2>&1 || {
echo "Tarball from $1 corrupted"
exit 1
}
@@ -103,7 +103,7 @@ httpup_sync() {
# usage:
# httpup_sync <url> <target dir>
#
command -v httpup &>/dev/null || {
command -v httpup >/dev/null 2>&1 || {
echo "httpup not found."
exit 1
}

108
scratch
View File

@@ -89,14 +89,18 @@ vercomp() {
fi
}
installed_pkg_info() {
if isinstalled $2; then
grep ^$1 $PKGDB_DIR/$2/.pkginfo 2>/dev/null | cut -d " " -f3-
fi
get_iver() {
head -n1 $PKGDB_DIR/$1 2>/dev/null | awk '{print $1}'
}
get_irelease() {
head -n1 $PKGDB_DIR/$1 2>/dev/null | awk '{print $2}'
}
allinstalled() {
grep ^name "$PKGDB_DIR"/*/.pkginfo 2>/dev/null | awk '{print $3}'
for i in $PKGDB_DIR/*; do
echo ${i##*/}
done
}
deps_alias() {
@@ -151,7 +155,7 @@ needarg() {
}
isinstalled() {
if [ -s "$PKGDB_DIR/$1/.pkginfo" ] && [ "$(grep $1 $PKGDB_DIR/$1/.pkginfo)" ]; then
if [ -s "$PKGDB_DIR/$1" ]; then
return 0
else
return 1
@@ -165,8 +169,8 @@ settermtitle() {
scratch_integrity() {
if [ "$1" ]; then
cd /
if [ -f $PKGDB_DIR/$1/.files ]; then
cat $PKGDB_DIR/$1/.files | while read -r line; do
if [ -f $PKGDB_DIR/$1 ]; then
tail -n+2 $PKGDB_DIR/$1 | while read -r line; do
if [ ! -e "$line" ]; then
if [ -L "$line" ]; then
printf "${YELLOW}broken symlink${CRESET} $1: /$line"
@@ -183,7 +187,7 @@ scratch_integrity() {
else
cd /
for pkg in $(allinstalled); do
cat $PKGDB_DIR/$pkg/.files | while read -r line; do
tail -n+2 $PKGDB_DIR/$pkg | while read -r line; do
if [ ! -e "$line" ]; then
if [ -L "$line" ]; then
echo "broken symlink $pkg: /$line"
@@ -197,19 +201,6 @@ scratch_integrity() {
fi
}
scratch_lock() {
needroot "Locking package"
for pkg in "$@"; do
if ! isinstalled $pkg; then
msgerr "Package '$pkg' is not installed."
elif [ -f $PKGDB_DIR/$pkg/.lock ]; then
msgerr "Package '$pkg' already locked."
else
touch $PKGDB_DIR/$pkg/.lock && msg "Successfully locked package '$pkg'."
fi
done
}
scratch_locate() {
needarg $@
for repo in $PORT_REPO; do
@@ -217,19 +208,6 @@ scratch_locate() {
done
}
scratch_unlock() {
needroot "Unlocking package"
for pkg in "$@"; do
if ! isinstalled $pkg; then
msgerr "Package '$pkg' is not installed."
elif [ ! -f $PKGDB_DIR/$pkg/.lock ]; then
msgerr "Package '$pkg' is not locked."
else
rm -f $PKGDB_DIR/$pkg/.lock && msg "Successfully unlocked package '$pkg'."
fi
done
}
scratch_isorphan() {
needarg $@
for pkg in $(allinstalled); do
@@ -355,7 +333,7 @@ pre_triggers() {
# mime db
if [ "$trig_1" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/mime/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/mime/$ $PKGDB_DIR/$pkg)" ]; then
trig_1=1
break
fi
@@ -365,7 +343,7 @@ pre_triggers() {
# desktop db
if [ "$trig_2" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/applications/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/applications/$ $PKGDB_DIR/$pkg)" ]; then
trig_2=1
break
fi
@@ -375,7 +353,7 @@ pre_triggers() {
# mkfontdir
if [ "$trig_3" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg)" ]; then
trig_3=1
break
fi
@@ -385,7 +363,7 @@ pre_triggers() {
# hwdb
if [ "$trig_4" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^etc/udev/hwdb.d/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^etc/udev/hwdb.d/$ $PKGDB_DIR/$pkg)" ]; then
trig_4=1
break
fi
@@ -395,7 +373,7 @@ pre_triggers() {
# icon caches
if [ "$trig_5" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/icons/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/icons/$ $PKGDB_DIR/$pkg)" ]; then
trig_5=1
break
fi
@@ -405,7 +383,7 @@ pre_triggers() {
# gtk3 immodules
if [ "$trig_6" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_6=1
break
fi
@@ -415,7 +393,7 @@ pre_triggers() {
# gtk2 immodules
if [ "$trig_7" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_7=1
break
fi
@@ -425,7 +403,7 @@ pre_triggers() {
# gsettings schema
if [ "$trig_8" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $PKGDB_DIR/$pkg)" ]; then
trig_8=1
break
fi
@@ -435,7 +413,7 @@ pre_triggers() {
# gio modules
if [ "$trig_9" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_9=1
break
fi
@@ -445,7 +423,7 @@ pre_triggers() {
# gdk-pixbuf
if [ "$trig_10" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $PKGDB_DIR/$pkg)" ]; then
trig_10=1
break
fi
@@ -455,7 +433,7 @@ pre_triggers() {
# font caches
if [ "$trig_11" != "1" ]; then
for pkg in $@; do
if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg/.files)" ]; then
if [ -s "$PKGDB_DIR/$pkg" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg)" ]; then
trig_11=1
break
fi
@@ -697,8 +675,8 @@ outdatepkg() {
if [ -z "$name" ] || [ -z "$version" ]; then
continue
fi
iversion=$(installed_pkg_info version $pkg)
irelease=$(installed_pkg_info release $pkg)
iversion=$(get_iver $pkg)
irelease=$(get_irelease $pkg)
if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then
echo $name
fi
@@ -829,7 +807,7 @@ scratch_upgrade() {
continue
else
. $(getportpath $pkg)/$BUILD_SCRIPT
if [ "$(installed_pkg_info version $pkg)-$(installed_pkg_info release $pkg)" = "$version-$release" ]; then
if [ "$(get_iver $pkg)-$(get_irelease $pkg)" = "$version-$release" ]; then
echo "Package '$pkg' is up to date."
continue
fi
@@ -919,8 +897,8 @@ scratch_outdate() {
if [ -z "$name" ] || [ -z "$version" ]; then
continue
fi
iversion=$(installed_pkg_info version $pkg)
irelease=$(installed_pkg_info release $pkg)
iversion=$(get_iver $pkg)
irelease=$(get_irelease $pkg)
[ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]"
if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then
ITSLOCK="[masked]"
@@ -1236,12 +1214,11 @@ scratch_dup() {
scratch_foreign() {
for pkg in $(allinstalled); do
if ! getportpath $pkg >/dev/null; then
iname=$(installed_pkg_info name $pkg)
iversion=$(installed_pkg_info version $pkg)
irelease=$(installed_pkg_info release $pkg)
echo "$iname $iversion-$irelease"
iversion=$(get_iver $pkg)
irelease=$(get_irelease $pkg)
echo "$pkg $iversion-$irelease"
fi
unset iname iversion irelease
unset pkg iversion irelease
done
}
@@ -1252,6 +1229,7 @@ scratch_info() {
. $ppath/$BUILD_SCRIPT
desc=$(grep "^# description[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//')
maint=$(grep "^# maintainer[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# maintainer[[:blank:]]*:[[:blank:]]*//')
homep=$(grep "^# homep[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# homepage[[:blank:]]*:[[:blank:]]*//')
deps=$(get_depends $1 | tr '\n' ' ')
echo "Name: $1"
@@ -1260,14 +1238,14 @@ scratch_info() {
echo "Release: $release"
echo "Description: $desc"
echo "Maintainer: $maint"
echo "Homepage: $homep"
echo "Dependencies: $deps"
echo "Installed: $(get_iver $1)-$(get_irelease $1)"
}
scratch_installed() {
for all in $(allinstalled); do
printf "%s" "$all "
grep -e ^version -e ^release $PKGDB_DIR/$all/.pkginfo | awk '{print $3}' | tr '\n' '-' | sed 's:\-$::'
echo
for all in $(allinstalled); do
echo "$all $(get_iver $all)-$(get_irelease $all)"
done
}
@@ -1323,10 +1301,9 @@ scratch_path() {
scratch_provide() {
needarg $@
arg=$(echo $1 | sed "s/^\///")
grep -R "$arg" $PKGDB_DIR/*/.files \
grep -R "$arg" $PKGDB_DIR/* \
| sed "s:$PKGDB_DIR/::" \
| sed "s:/.files::" \
| tr : " "
| tr : "\t"
}
scratch_readme() {
@@ -1346,7 +1323,7 @@ scratch_readme() {
scratch_files() {
needarg $@
if isinstalled $1; then
cat "$PKGDB_DIR/$1/.files"
cat "$PKGDB_DIR/$1"
else
msg "Package '$1' not installed."
fi
@@ -1384,8 +1361,6 @@ Options:
build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p')
--log log build process (/var/log/pkgbuild.log)
lock <ports> locking ports prevent upgrade
unlock <ports> unlock locked ports
trigger [ports] run system trigger
search <pattern> find ports in repo
cat <port> print spkgbuild
@@ -1403,7 +1378,6 @@ Options:
integrity check installed port integrity
dup print duplicate ports in repo
installed print all installed ports
locked print loacked ports
missingdep print missing dependencies
orphan print orphan installed ports
foreign print foreign ports