From 784de43df4836a9155ebdc9e3392cc4bef72eacf Mon Sep 17 00:00:00 2001 From: Voncloft Date: Thu, 4 Mar 2021 09:16:24 -0500 Subject: [PATCH 01/13] Minor Updates --- scratch | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scratch b/scratch index 97b2c4a..b8e5289 100755 --- a/scratch +++ b/scratch @@ -735,7 +735,7 @@ scratch_sysup() { } [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && { echo - msgerr "Please upgrade 'scratchpkg' first." + msgwarn "Please upgrade 'scratchpkg' first.'" return 1 } UPGPKG=0 @@ -910,24 +910,27 @@ scratch_outdate() { if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then ITSLOCK="[masked]" fi - outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" - newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + #outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" + #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" + newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" + if [ "$version" != "$iversion" ]; then vercomp $version $iversion if [ $? = 2 ]; then - echo "$outdatemsg" + echo -e "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo "$newerinstmsg" + echo -e "$newerinstmsg" OUTDATE=yes fi elif [ "$release" != "$irelease" ]; then vercomp $release $irelease if [ $? = 2 ]; then - echo "$outdatemsg" + echo -e "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo "$newerinstmsg" + echo -e "$newerinstmsg" OUTDATE=yes fi fi From 71dbb14f9a4533916ab2a18a56ee252b06f0d760 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Thu, 4 Mar 2021 09:45:38 -0500 Subject: [PATCH 02/13] Minor Updates --- scratch | 1701 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 944 insertions(+), 757 deletions(-) diff --git a/scratch b/scratch index b8e5289..92a8087 100755 --- a/scratch +++ b/scratch @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # scratchpkg # @@ -35,31 +35,31 @@ nocolor() { } msg() { - printf "${GREEN}==>${CRESET} %s\n" "$1" + echo -e "${GREEN}==>${CRESET} $1" +} + +msgerr() { + echo -e "${RED}==> ERROR:${CRESET} $1" } msginst() { - printf "[${GREEN}i${CRESET}] %s\n" "$1" + echo -e "[${GREEN}i${CRESET}] $1" } msgmiss() { - printf "[${YELLOW}m${CRESET}] %s\n" "$1" + echo -e "[${YELLOW}m${CRESET}] $1" } msgnoinst() { - printf "[-] %s\n" "$1" -} - -msgerr() { - printf "${RED}==> ERROR:${CRESET} %s\n" "$1" >&2 + echo -e "[ ] $1" } msgwarn() { - printf "${YELLOW}==> WARNING:${CRESET} %s\n" "$1" >&2 + echo -e "${YELLOW}==> WARNING:${CRESET} $1" } needroot() { - if [ "$(id -u)" != 0 ]; then + if [ $UID != 0 ]; then if [ "$#" -eq 0 ]; then needroot "This operation" else @@ -70,19 +70,27 @@ needroot() { } getportpath() { - for repo in $PORT_REPO; do - if [ -f "$repo/$1/$BUILD_SCRIPT" ]; then - dirname "$repo/$1/$BUILD_SCRIPT" + for repo in ${PORT_REPO[@]}; do + if [[ -f $repo/$1/$BUILD_SCRIPT ]]; then + dirname $repo/$1/$BUILD_SCRIPT return 0 fi done return 1 } +pushd() { + command pushd $1 &>/dev/null +} + +popd() { + command popd &>/dev/null +} + vercomp() { if [ "$1" = "$2" ]; then return 0 # same version - elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then + elif [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]; then return 1 # $1 lower than $2 else return 2 # $1 higher than $2 @@ -91,67 +99,57 @@ vercomp() { installed_pkg_info() { if isinstalled $2; then - grep ^$1 $PKGDB_DIR/$2/.pkginfo 2>/dev/null | cut -d " " -f3- + grep ^$1 $INDEX_DIR/$2/.pkginfo | cut -d " " -f3- fi } allinstalled() { - grep ^name "$PKGDB_DIR"/*/.pkginfo 2>/dev/null | awk '{print $3}' -} - -deps_alias() { - [ -f "$ALIAS_FILE" ] || { - echo $@ - return - } - while [ "$1" ]; do - if [ "$(grep -w ^$1 $ALIAS_FILE)" ]; then - getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}') - [ "$getalias" ] && echo "$getalias" - else - echo "$1" - fi - shift - unset getalias - done + grep ^name "$INDEX_DIR"/*/.pkginfo | awk '{print $3}' } get_depends() { - ppath=$(getportpath $1) || return 0 - deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ + local pkg=$1 + ppath=$(getportpath $pkg) || return 0 + grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ | tr ' ' '\n' \ | awk '!a[$0]++' \ - | sed 's/,//') - deps_alias $deps + | sed 's/,//' } confirm() { - printf "$1 (Y/n) " - read -r response + read -r -p "$1 (Y/n) " response case "$response" in - [Nn][Oo]|[Nn]) echo "$2"; return 2 ;; + [Nn][Oo]|[Nn]) echo "$2"; exit 2 ;; *) : ;; esac - return 0 } checktool() { - if ! command -v $1 >/dev/null; then + if ! type -p $1 &>/dev/null; then msgerr "'$1' not exist in your system!" exit 1 fi } needarg() { - [ "$*" ] || { + if [ -z "$*" ]; then msgerr "This operation required an arguments!" exit 1 - } + fi +} + +scratch_cat() { + if PPATH=$(getportpath "$1"); then + cat "$PPATH/$BUILD_SCRIPT" + else + msgerr "Port '$1' not exist." + exit 1 + fi } isinstalled() { - if [ -s "$PKGDB_DIR/$1/.pkginfo" ] && [ "$(grep $1 $PKGDB_DIR/$1/.pkginfo)" ]; then + if [ -s $INDEX_DIR/$1/.pkginfo ] && [[ $(grep $1 $INDEX_DIR/$1/.pkginfo) ]]; then return 0 else return 1 @@ -159,82 +157,166 @@ isinstalled() { } settermtitle() { - printf "\033]0;$*\a" + echo -en "\033]0;$*\a" +} + +scratch_missingdep() { + local pkg d + + for pkg in $(allinstalled); do + if [ $(getportpath "$pkg") ]; then + depends=$(get_depends $pkg) + fi + if [ "$depends" ]; then + for d in ${depends[@]}; do + if ! isinstalled $d; then + msd+=($d) + fi + done + fi + if [ ${#msd[@]} -gt 0 ]; then + echo -e "${GREEN}$pkg${CRESET} missing ${RED}${msd[@]}${CRESET}" + fi + unset depends msd + done } scratch_integrity() { if [ "$1" ]; then - cd / - if [ -f $PKGDB_DIR/$1/.files ]; then - cat $PKGDB_DIR/$1/.files | while read -r line; do + pushd / + if [ -f $INDEX_DIR/$1/.files ]; then + while read -r line; do if [ ! -e "$line" ]; then + MISSING_FILE=yes if [ -L "$line" ]; then - printf "${YELLOW}broken symlink${CRESET} $1: /$line" + echo -e "${YELLOW}broken symlink${CRESET} $1: /$line" else - printf "${RED}file missing${CRESET} $1: /$line" + echo -e "${RED}file missing${CRESET} $1: /$line" fi fi - done + done < <(cat $INDEX_DIR/$1/.files) else echo "Package '$1' not installed." exit 1 fi - cd - >/dev/null + popd else - cd / + pushd / for pkg in $(allinstalled); do - cat $PKGDB_DIR/$pkg/.files | while read -r line; do + while read -r line; do if [ ! -e "$line" ]; then + MISSING_FILE=yes if [ -L "$line" ]; then - echo "broken symlink $pkg: /$line" + echo -e "${YELLOW}broken symlink${CRESET} $pkg: /$line" else - echo "missing file $pkg: /$line" + echo -e "${RED}file missing${CRESET} $pkg: /$line" fi fi - done + done < <(cat $INDEX_DIR/$pkg/.files) done - cd - >/dev/null + popd + fi + + [ "$UID" != "0" ] && msg "${YELLOW}(check integrity is recommended run as root or using sudo)${CRESET}" + if [ "$1" ]; then + p="Package '$1'" + else + p="Your system" fi + [ ! "$MISSING_FILE" ] && msg "$p files is consistent with package tree." +} + +scratch_listinst() { + for all in $(allinstalled); do + echo -ne "$all " + grep -e ^version -e ^release $INDEX_DIR/$all/.pkginfo | awk '{print $3}' | tr '\n' '-' | sed 's:\-$::' + echo + done +} + +scratch_listorphan() { + local pkg dep + tmpallpkg=$(mktemp) + tmpalldep=$(mktemp) + for pkg in $(allinstalled); do + echo $pkg >> $tmpallpkg + dep="$dep $(get_depends $pkg)" + done + echo $dep | tr ' ' '\n' | sort | uniq > $tmpalldep + grep -xvF -f $tmpalldep $tmpallpkg + rm $tmpalldep $tmpallpkg } scratch_lock() { - needroot "Locking package" + local pkg + + needroot "Locking package" + for pkg in "$@"; do if ! isinstalled $pkg; then msgerr "Package '$pkg' is not installed." - elif [ -f $PKGDB_DIR/$pkg/.lock ]; then + elif [ -f $INDEX_DIR/$pkg/.lock ]; then msgerr "Package '$pkg' already locked." else - touch $PKGDB_DIR/$pkg/.lock && msg "Successfully locked package '$pkg'." + touch $INDEX_DIR/$pkg/.lock && msg "Successfully locked package '$pkg'." fi done } -scratch_locate() { - needarg $@ - for repo in $PORT_REPO; do - grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' | column -t - done -} - scratch_unlock() { - needroot "Unlocking package" + local pkg + + needroot "Unlocking package" + for pkg in "$@"; do if ! isinstalled $pkg; then msgerr "Package '$pkg' is not installed." - elif [ ! -f $PKGDB_DIR/$pkg/.lock ]; then + elif [ ! -f $INDEX_DIR/$pkg/.lock ]; then msgerr "Package '$pkg' is not locked." else - rm -f $PKGDB_DIR/$pkg/.lock && msg "Successfully unlocked package '$pkg'." + rm -f $INDEX_DIR/$pkg/.lock && msg "Successfully unlocked package '$pkg'." fi done } +scratch_listlocked() { + local pkg + for pkg in $(allinstalled); do + if [ -f "$INDEX_DIR"/$pkg/.lock ]; then + echo -e "$pkg" + fi + done +} + +scratch_depends() { + local dep + + if [ $(getportpath "$1") ]; then + depends=$(get_depends $1) + else + msgerr "Port '$1' not exist." + exit 1 + fi + + for dep in ${depends[@]}; do + if isinstalled $dep; then + msginst "$dep" + elif getportpath $dep >/dev/null; then + msgnoinst "$dep" + else + msgmiss "$dep" + fi + done +} + scratch_isorphan() { - needarg $@ + needarg $1 + for pkg in $(allinstalled); do - if depend=$(get_depends $pkg); then - for dep in $depend; do + pkgpath=$(getportpath $pkg) + if [ $pkgpath ]; then + depend=$(get_depends $pkg) + for dep in ${depend[@]}; do if [ $dep = $1 ]; then return 1 fi @@ -245,8 +327,53 @@ scratch_isorphan() { return 0 } +scratch_dependent() { + local port all dep pname + + needarg $1 + + for port in ${PORT_REPO[@]}; do + if [ -d $port ]; then + for all in $port/*/$BUILD_SCRIPT; do + [ -f $all ] || continue + depend=$(grep "^# depends[[:blank:]]*:" $all | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' | tr ' ' '\n' | awk '!a[$0]++') + for dep in ${depend[@]}; do + if [ $dep = $1 ]; then + GDP=yes + pname=$(dirname $all) + pname=${pname##*/} + if isinstalled $pname; then + msginst "$pname" + else + msgnoinst "$pname" + fi + break + fi + done + done + fi + done + + [ "$GDP" ] && return 0 || return 1 +} + +scratch_own() { + local arg + arg=$(echo $1 | sed "s/^\///") + grep -R $arg $INDEX_DIR/*/.files | sed "s:$INDEX_DIR/::" | sed "s:/.files::" | tr : " " | column -t +} + +scratch_files() { + if ! isinstalled $1; then + msg "Package'$1' not installed." + else + cat $INDEX_DIR/$1/.files + fi +} + scratch_sync() { - checktool httpup + checktool httpup + needroot "Updating ports" if [ ! -e "$REPO_FILE" ]; then @@ -254,21 +381,116 @@ scratch_sync() { exit 1 fi - grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do - if [ "$repodir" ] && [ "$repourl" ]; then - httpup sync $repourl $repodir || { + while read repodir repourl junk; do + case $repodir in + ""|"#"*) continue ;; + esac + if [ -n "$repodir" ] && [ -n "$repourl" ]; then + httpup sync $repourl $repodir + if [ $? != 0 ]; then msgerr "Failed sync from $repourl" exit 1 - } + fi + fi + done < "$REPO_FILE" +} + +scratch_readme() { + needarg $@ + + if PPATH=$(getportpath "$1"); then + if [ -f "$PPATH/readme" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + +scratch_search() { + needarg $@ + + case $1 in + -*) msgerr "Invalid pattern '$1'" + return 1 ;; + esac + + local port found OUTPUT + + for port in ${PORT_REPO[@]}; do + if [ -d $port ]; then + pushd $port + OUTPUT=$(grep -R description | grep "$BUILD_SCRIPT:# description[[:blank:]]*:" | sed "s/$BUILD_SCRIPT:# description[[:blank:]]*://" | grep -i "$1" | cut -d '/' -f1 | sort) + popd + if [ -n "$OUTPUT" ]; then + found=yes + for out in ${OUTPUT[@]}; do + if [ -f $port/$out/$BUILD_SCRIPT ]; then + pushd $port/$out + description=$(grep "^# description[[:blank:]]*:" $BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') + . $BUILD_SCRIPT + popd + if [ -n "$name" ] && [ -n "$version" ] && [ -n "$release" ]; then + portname=$(basename $port) + search_result="${PURPLE}($portname)${CRESET} $name ${CYAN}$version-$release${CRESET} $description" + if isinstalled $name; then + echo -e "[${GREEN}*${CRESET}] $search_result" + else + echo -e "[ ] $search_result" + fi + unset description name version release + fi + fi + done + fi fi done + if [ ! "$found" ]; then + msg "No matching package found." + fi +} + +scratch_foreignpkg() { + 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 -e "$iname ${GREEN}$iversion${CRESET}-${CYAN}$irelease${CRESET}" + fi + unset iname iversion irelease + done +} + +scratch_info() { + needarg $@ + local pkg=$1 + ppath=$(getportpath $pkg) || return 1 + + . $ppath/$BUILD_SCRIPT + desc=$(grep "^# description[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') + url=$(grep "^# homepage[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# homepage[[:blank:]]*:[[:blank:]]*//') + maint=$(grep "^# maintainer[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# maintainer[[:blank:]]*:[[:blank:]]*//') + deps=$(get_depends $pkg | tr '\n' ' ') + + echo -e "Name: $pkg" + echo -e "Path: $ppath" + echo -e "Version: $version" + echo -e "Release: $release" + echo -e "Description: $desc" + echo -e "Homepage: $url" + echo -e "Maintainer: $maint" + echo -e "Dependencies: $deps" } scratch_trigger() { needroot "Run trigger" - if [ -z "$*" ]; then - for i in $(seq 12); do - eval trig_$i=1 + if [[ -z "$@" ]]; then + for i in trig_{1..12}; do + eval $i=1 done else pre_triggers $@ @@ -279,59 +501,70 @@ scratch_trigger() { post_triggers() { if [ "$trig_12" = 1 ]; then echo "trigger: Running mkdirs..." - for mkd in $PKGDB_DIR/*/.pkgmkdirs; do + for mkd in $INDEX_DIR/*/.pkgmkdirs; do [ -s $mkd ] || continue - grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do - if [ -e "$dir" ]; then - if [ "$uid" != '-' ]; then - getent passwd $uid >/dev/null && chown "$uid" "$dir" + while read dir mode uid gid junk; do + # Ignore comments and blank lines + case "$dir" in + ""|\#*) continue ;; + esac + if [ -e "$dir" ]; then + if [ "$uid" != '-' ]; then + getent passwd $uid >/dev/null + if [[ "$?" = 0 ]]; then + chown "$uid" "$dir" fi - if [ "$gid" != '-' ]; then - getent group $gid >/dev/null && chgrp "$gid" "$dir" - fi - if [ "$mode" != '-' ]; then - chmod "$mode" "$dir" + fi + if [ "$gid" != '-' ]; then + getent group $gid >/dev/null + if [[ "$?" = 0 ]]; then + chgrp "$gid" "$dir" fi fi - done - done + if [ "$mode" != '-' ]; then + chmod "$mode" "$dir" + fi + fi + done < "$mkd" + done + fi - if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then + if [ "$trig_11" = 1 ] && [ $(type -p fc-cache) ]; then echo "trigger: Updating fontconfig cache..." fc-cache -s fi - if [ "$trig_10" = 1 ] && [ $(command -v gdk-pixbuf-query-loaders) ]; then + if [ "$trig_10" = 1 ] && [ $(type -p gdk-pixbuf-query-loaders) ]; then echo "trigger: Probing GDK-Pixbuf loader modules..." gdk-pixbuf-query-loaders --update-cache fi - if [ "$trig_9" = 1 ] && [ $(command -v gio-querymodules) ]; then + if [ "$trig_9" = 1 ] && [ $(type -p gio-querymodules) ]; then echo "trigger: Updating GIO module cache..." gio-querymodules /usr/lib/gio/modules fi - if [ "$trig_8" = 1 ] && [ $(command -v glib-compile-schemas) ]; then + if [ "$trig_8" = 1 ] && [ $(type -p 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 ] && [ $(command -v gtk-query-immodules-2.0) ]; then + if [ "$trig_7" = 1 ] && [ $(type -p 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 ] && [ $(command -v gtk-query-immodules-3.0) ]; then + if [ "$trig_6" = 1 ] && [ $(type -p 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 ] && [ $(command -v gtk-update-icon-cache) ]; then + if [ "$trig_5" = 1 ] && [ $(type -p gtk-update-icon-cache) ]; then echo "trigger: Updating icon theme caches..." for dir in /usr/share/icons/* ; do - if [ -e $dir/index.theme ]; then - gtk-update-icon-cache -q $dir 2>/dev/null + if [[ -e $dir/index.theme ]]; then + gtk-update-icon-cache -q $dir &>/dev/null else rm -f $dir/icon-theme.cache rmdir --ignore-fail-on-non-empty $dir @@ -339,38 +572,40 @@ post_triggers() { done fi - if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then + if [ "$trig_4" = 1 ] && [ $(type -p udevadm) ]; then echo "trigger: Updating hardware database..." udevadm hwdb --update fi - if [ "$trig_3" = 1 ] && [ $(command -v mkfontdir) ] && [ $(command -v mkfontscale) ]; then + if [ "$trig_3" = 1 ] && [ $(type -p mkfontdir) ] && [ $(type -p 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 + rm -f $dir/fonts.{scale,dir} $dir/.uuid rmdir --ignore-fail-on-non-empty $dir - [ -d "$dir" ] || continue + [[ -d $dir ]] || continue mkfontdir $dir mkfontscale $dir done fi - if [ "$trig_2" = 1 ] && [ $(command -v update-desktop-database) ]; then + if [ "$trig_2" = 1 ] && [ $(type -p update-desktop-database) ]; then echo "trigger: Updating desktop file MIME type cache..." update-desktop-database --quiet fi - if [ "$trig_1" = 1 ] && [ $(command -v update-mime-database) ]; then + if [ "$trig_1" = 1 ] && [ $(type -p update-mime-database) ]; then echo "trigger: Updating the MIME type database..." update-mime-database /usr/share/mime fi } -pre_triggers() { +pre_triggers() { + local pkg + # 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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/mime/$ $INDEX_DIR/$pkg/.files)" ]; then trig_1=1 break fi @@ -380,7 +615,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/applications/$ $INDEX_DIR/$pkg/.files)" ]; then trig_2=1 break fi @@ -390,7 +625,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then trig_3=1 break fi @@ -400,7 +635,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^etc/udev/hwdb.d/$ $INDEX_DIR/$pkg/.files)" ]; then trig_4=1 break fi @@ -410,7 +645,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/icons/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then trig_5=1 break fi @@ -420,7 +655,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $INDEX_DIR/$pkg/.files)" ]; then trig_6=1 break fi @@ -430,7 +665,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $INDEX_DIR/$pkg/.files)" ]; then trig_7=1 break fi @@ -440,7 +675,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $INDEX_DIR/$pkg/.files)" ]; then trig_8=1 break fi @@ -450,7 +685,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $INDEX_DIR/$pkg/.files)" ]; then trig_9=1 break fi @@ -460,7 +695,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $INDEX_DIR/$pkg/.files)" ]; then trig_10=1 break fi @@ -470,7 +705,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 "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then trig_11=1 break fi @@ -480,7 +715,7 @@ pre_triggers() { # makedirs if [ "$trig_12" != "1" ]; then for pkg in $@; do - if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then + if [ -s "$INDEX_DIR/$pkg/.pkgmkdirs" ]; then trig_12=1 break fi @@ -491,430 +726,469 @@ pre_triggers() { scratch_build() { while [ "$1" ]; do case $1 in - -i|-u|-r|-g|-p) ;; - --log) LOG=1;; - -*) OPTS="$OPTS $1";; - *) PKGNAME="$PKGNAME $1";; + -i|-u|-r) ;; + -*) OPTS+=($1);; + *) PKGNAME+=($1);; esac shift done - [ "$PKGNAME" ] || { - echo "Please specify package(s) to build." - return 1 - } - for pkg in $PKGNAME; do - ppath=$(getportpath $pkg) || { - echo "Package '$pkg' not found." - return 1 - } - cd $ppath - settermtitle "Building $pkg..." - if [ "$LOG" ]; then - pkgbuild $OPTS | tee /var/log/pkgbuild.log || { - settermtitle "Building $pkg failed." + for P in ${PKGNAME[@]}; do + pushd $(getportpath $P) + if [ $? = 0 ]; then + settermtitle "Building $P..." + pkgbuild ${OPTS[@]} || { + settermtitle "Building $P failed" return 1 } + settermtitle "Building $P done" else - pkgbuild $OPTS || { - settermtitle "Building $pkg failed." - return 1 - } + echo "Package '$P' not found." + return 1 fi - settermtitle "Building $pkg done." - cd - >/dev/null + popd done } scratch_install() { + local pkg i int pkgcount count IPKG OPTS REINSTALL done_pkg + needroot "Installing package" + while [ "$1" ]; do case $1 in -i|-u) ;; - -r|--reinstall) REINSTALL=1;; + -r) REINSTALL=1;; -y|--yes) NOCONFIRM=1;; -n|--no-dep) NO_DEP=1;; --exclude=*) EXOPT=$1;; - -*) OPTS="$OPTS $1";; - *) PKGNAME="$PKGNAME $1";; + -*) OPTS+=($1);; + *) PKGNAME+=($1);; esac shift - done - [ "$PKGNAME" ] || { + done + + if [ -z "$PKGNAME" ]; then echo "Please specify package(s) to install." return 1 - } + fi + # use custom root location + if [ "$ROOT_DIR" ]; then + OPTS+=(--root=$ROOT_DIR) + fi # if reinstall, dont calculate dep, just reinstall it then exit if [ "$REINSTALL" = 1 ]; then - error=0 - for ii in $PKGNAME; do + for ii in ${PKGNAME[@]}; do if [ ! $(getportpath $ii) ]; then echo "Package '$ii' not found." elif ! isinstalled $ii; then echo "Package '$ii' not installed." else - cd $(getportpath $ii) + pushd $(getportpath $ii) settermtitle "Reinstalling $ii..." - pkgbuild $OPTS -r || { + pkgbuild ${OPTS[@]} -r + if [ $? != 0 ]; then error=1 break - } - done_pkg="$done_pkg $ii" - cd - >/dev/null + fi + done_pkg+=($ii) + popd fi done - settermtitle "Triggering install hook..." - [ "$done_pkg" ] && scratch_trigger $done_pkg - settermtitle "Reinstalling done." - return "$error" + settermtitle "Triggering install hook" + if [ ${#done_pkg[@]} -gt 0 ]; then + scratch_trigger ${done_pkg[@]} + fi + settermtitle "Reinstalling done" + [ "$error" = 1 ] && return 1 || return 0 fi if [ "$NO_DEP" = 1 ]; then - error=0 - for ii in $PKGNAME; do + for ii in ${PKGNAME[@]}; do if [ ! $(getportpath $ii) ]; then echo "Package '$ii' not found." elif isinstalled $ii; then echo "Package '$ii' already installed." - continue + return 0 else - cd $(getportpath $ii) + pushd $(getportpath $ii) settermtitle "Installing $ii..." - pkgbuild -i $OPTS || { + pkgbuild -i ${OPTS[@]} + if [ $? != 0 ]; then error=1 break - } - done_pkg="$done_pkg $ii" - cd - >/dev/null + fi + done_pkg+=($ii) + popd fi done - settermtitle "Triggering install hook..." - [ "$done_pkg" ] && scratch_trigger $done_pkg - settermtitle "Installing done." - return "$error" + settermtitle "Triggering install hook" + if [ ${#done_pkg[@]} -gt 0 ]; then + scratch_trigger ${done_pkg[@]} + fi + settermtitle "Installing done" + [ "$error" = 1 ] && return 1 || return 0 fi - for i in $PKGNAME; do + for i in ${PKGNAME[@]}; do if [ ! $(getportpath $i) ]; then echo "Package '$i' not found." elif isinstalled $i; then echo "Package '$i' already installed." else - IPKG="$IPKG $i" + IPKG+=($i) fi done - [ "$IPKG" ] || return 0 + if [ "${#IPKG[@]}" = 0 ]; then + return 0 + fi echo "Resolving dependencies..." - INST="$(scratch_deplist -q $IPKG $EXOPT)" + INST="$(scratch_deplist -q ${IPKG[@]} $EXOPT)" + if [ "$INST" ]; then echo pkgcount=0 for pkg in $INST; do pkgcount=$(( pkgcount + 1 )) - printf "[${GREEN}i${CRESET}] $pkg " + echo -en "[${GREEN}i${CRESET}] $pkg " done echo; echo echo "( $pkgcount install )" echo if [ ! "$NOCONFIRM" ]; then - confirm "Continue install package(s)?" "Package installation cancelled." || exit $? + confirm "Continue install package(s)?" "Package installation cancelled." echo fi error=0 count=0 total=$(echo $INST | wc -w) - for int in $INST; do + for int in ${INST[@]}; do count=$(( count + 1 )) - if portpathh=$(getportpath $int); then - cd $portpathh + portpathh=$(getportpath $int) + if [ "$portpathh" ]; then + pushd $portpathh settermtitle "[ $count/$total ] installing $int..." - pkgbuild -i $OPTS || { + pkgbuild -i ${OPTS[@]} + if [ $? != 0 ]; then error=1 count=$(( count - 1 )) break - } - done_pkg="$done_pkg $int" - cd - >/dev/null + fi + done_pkg+=($int) + popd else msgwarn "Skipping missing package: $int" fi unset portpathh done - settermtitle "Triggering install hook..." - [ "$done_pkg" ] && scratch_trigger $done_pkg - settermtitle "$count/$total package(s) installed." + settermtitle "Triggering install hook" + if [ ${#done_pkg[@]} -gt 0 ]; then + scratch_trigger ${done_pkg[@]} + fi + settermtitle "$count/$total package(s) installed" return "$error" fi } +outdatepkg() { + local pkg + + for pkg in $(allinstalled); do + if [ ! -e "$INDEX_DIR/$pkg/.lock" ] && getportpath $pkg >/dev/null; then + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then + echo $name + fi + unset iversion irelease version release + fi + done +} + scratch_remove() { + local pkg i IPKG OPTS + needroot "Removing package" + while [ "$1" ]; do case $1 in -y|--yes) NOCONFIRM=1;; - -*) OPTS="$OPTS $1";; - *) PKGNAME="$PKGNAME $1";; + -*) OPTS+=($1);; + *) PKGNAME+=($1);; esac shift done - [ "$PKGNAME" ] || { + + if [ -z "$PKGNAME" ]; then echo "Please specify package(s) to remove." return 1 - } - for i in $PKGNAME; do + fi + # use custom root location + if [ "$ROOT_DIR" ]; then + OPTS+=(--root=$ROOT_DIR) + fi + + for i in ${PKGNAME[@]}; do if ! isinstalled $i; then echo "Package '$i' not installed." else - IPKG="$IPKG $i" + IPKG+=($i) fi done - [ "$IPKG" ] || return 0 - echo "Removing packages..." - echo - pkgcount=0 - count=0 - for pkg in $IPKG; do - pkgcount=$(( pkgcount + 1 )) - printf "[${RED}x${CRESET}] $pkg " - done - echo; echo - echo "( $pkgcount remove )" - echo - [ "$NOCONFIRM" ] || { - confirm "Continue remove package(s)?" "Package removing cancelled." || exit $? + if [ "${#IPKG[@]}" = 0 ]; then + return 0 + fi + if [ "$IPKG" ]; then + echo "Removing packages..." echo - } - for pkg in $IPKG; do - count=$(( count + 1 )) - pre_triggers $pkg - settermtitle "[ $count/$pkgcount ] Removing $pkg..." - pkgdel $pkg $OPTS || { - error=1 - break - } - done - settermtitle "Triggering remove hook..." - post_triggers - settermtitle "$pkgcount package(s) removed." -} - -outdatepkg() { - for pkg in $(allinstalled); do - if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -w $pkg) ]; then - continue - fi - [ -e "$PKGDB_DIR/$pkg/.lock" ] && continue - getportpath $pkg >/dev/null || continue - . $(getportpath $pkg)/$BUILD_SCRIPT - if [ -z "$name" ] || [ -z "$version" ]; then - continue - fi - iversion=$(installed_pkg_info version $pkg) - irelease=$(installed_pkg_info release $pkg) - if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then - echo $name - fi - unset iversion irelease version release - done + pkgcount=0 + count=0 + for pkg in ${IPKG[@]}; do + pkgcount=$(( pkgcount + 1 )) + echo -en "[${RED}x${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount remove )" + echo + if [ ! "$NOCONFIRM" ]; then + confirm "Continue remove package(s)?" "Package removing cancelled." + echo + fi + for pkg in ${IPKG[@]}; do + count=$(( count + 1 )) + pre_triggers $pkg + settermtitle "[ $count/$pkgcount ] Removing $pkg..." + pkgdel $pkg ${OPTS[@]} || return 1 + done + settermtitle "Triggering remove hook" + post_triggers + settermtitle "$pkgcount package(s) removed" + fi } scratch_sysup() { - needroot "Upgrading package" + local d UPGPKG NEWPKG PKGOUTDATE OPTS done_pkg + + needroot "Upgrading package" + while [ "$1" ]; do case $1 in -i|-u|-r) ;; -y|--yes) NOCONFIRM=1;; - -n|--no-dep) NODEP=1;; - --exclude=*) EXOPT=$1;; - -*) OPTS="$OPTS $1";; + -d|--no-dep) NODEP=1;; + -s|--sync) SYNC=1;; + --exclude=*) EXOPT+=($1);; + -*) OPTS+=($1);; esac shift done + + # use custom root location + if [ "$ROOT_DIR" ]; then + OPTS+=(--root=$ROOT_DIR) + fi + + if [ "$SYNC" = 1 ]; then + scratch_sync + fi + echo "Checking for outdated packages..." PKGOUTDATE=$(outdatepkg) - [ "$PKGOUTDATE" ] || { + + if [ ! "$PKGOUTDATE" ]; then echo "All packages are up to date." return 0 - } - [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && { - echo - msgwarn "Please upgrade 'scratchpkg' first.'" - return 1 - } + fi + UPGPKG=0 - NEWPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then echo "Resolving dependencies..." - DEP=$(scratch_deplist $PKGOUTDATE $EXOPT | awk '{print $2}') + DEP=$(scratch_deplist ${PKGOUTDATE[@]} $EXOPT | awk '{print $2}') echo for d in $DEP; do if [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x $d)" = "$d" ]; then - printf "[${GREEN}u${CRESET}] $d " - WILLINSTALL="$WILLINSTALL $d" + echo -ne "[${GREEN}u${CRESET}] $d " + WILLINSTALL+=($d) UPGPKG=$(( UPGPKG + 1 )) - elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then - printf "[${CYAN}n${CRESET}] $d " - WILLINSTALL="$WILLINSTALL $d" + elif ! isinstalled $d && [ $(getportpath "$d") ]; then + echo -ne "[${CYAN}n${CRESET}] $d " + WILLINSTALL+=($d) NEWPKG=$(( NEWPKG + 1 )) fi done else echo - for dd in $PKGOUTDATE; do - printf "[${GREEN}u${CRESET}] $dd " - WILLINSTALL="$WILLINSTALL $dd" + for dd in ${PKGOUTDATE[@]}; do + echo -ne "[${GREEN}u${CRESET}] $dd " + WILLINSTALL+=($dd) UPGPKG=$(( UPGPKG + 1 )) done fi - echo; echo + echo + echo echo "( $UPGPKG upgrade, $NEWPKG new install )" echo - [ "$NOCONFIRM" ] || { - confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + if [ ! "$NOCONFIRM" ]; then + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." echo - } + fi error=0 count=0 - total=$(echo $WILLINSTALL | wc -w) - for inst in $WILLINSTALL; do # install all required dependencies and target packages itself + total=$(echo ${WILLINSTALL[@]} | wc -w) + for inst in ${WILLINSTALL[@]}; do # install all required dependencies and target packages itself count=$(( count + 1 )) - cd $(getportpath $inst) + pushd $(getportpath $inst) if ! isinstalled $inst; then settermtitle "[ $count/$total ] Installing $inst..." - pkgbuild -i $OPTS || { + pkgbuild -i ${OPTS[@]} + if [ $? != 0 ]; then error=1 count=$(( count - 1 )) break - } + fi else settermtitle "[ $count/$total ] Upgrading $inst..." - pkgbuild -u $OPTS || { + pkgbuild -u ${OPTS[@]} + if [ $? != 0 ]; then error=1 count=$(( count - 1 )) break - } + fi fi - cd - >/dev/null - done_pkg="$done_pkg $inst" + done_pkg+=($inst) done - settermtitle "Triggering install hook." - [ "$done_pkg" ] && scratch_trigger $done_pkg - settermtitle "$count/$total package(s) upgraded." - return "$error" + settermtitle "Triggering install hook" + if [ ${#done_pkg[@]} -gt 0 ]; then + scratch_trigger ${done_pkg[@]} + fi + settermtitle "$count/$total package(s) upgraded" + return $error } scratch_upgrade() { - needroot "Upgrading package" + local pkg done_pkg + + needroot "Upgrading package" + while [ "$1" ]; do case $1 in - -i|-r) ;; -y|--yes) NOCONFIRM=1;; -d|--no-dep) NO_DEP=1;; --exclude=*) EXOPT=$1;; - -*) OPTS="$OPTS $1";; - *) PKGNAME="$PKGNAME $1";; + -*) OPTS+=($1);; + *) PKGNAME+=($1);; esac shift - done - [ "$PKGNAME" ] || { - echo "Please specify package(s) to upgrade." + done + + if [ -z "$PKGNAME" ]; then + echo "Please specify package(s) to remove." return 1 - } - for pkg in $PKGNAME; do + fi + + # use custom root location + if [ "$ROOT_DIR" ]; then + OPTS+=(--root=$ROOT_DIR) + fi + for pkg in ${PKGNAME[@]}; do if ! isinstalled $pkg; then - echo "Package '$pkg' not installed." - continue - elif [ ! $(getportpath $pkg) ]; then - 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 - echo "Package '$pkg' is up to date." - continue - fi + msgerr "Package '$pkg' not installed." + return 1 + fi + if [ ! $(getportpath $pkg) ]; then + msgerr "Package '$pkg' not exist." + return 1 + fi + . $(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." + return 0 fi - upkg="$upkg $pkg" done - [ "$upkg" ] || return 0 - - UPGPKG=0 - NEWPKG=0 - if [ "$NODEP" != 1 ]; then + if [ -z "$NO_DEP" ]; then echo "Resolving dependencies..." - DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') - 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 )) + DEP=$(scratch_deplist ${PKGNAME[@]} $EXOPT | awk '{print $2}') + for dep in $DEP; do + if ! isinstalled $dep; then + if [ $(getportpath $dep) ]; then + NEWPKG+=($dep) + fi fi done - else - echo - for dd in $upkg; do - printf "[${GREEN}u${CRESET}] $dd " - WILLINSTALL="$WILLINSTALL $dd" - UPGPKG=$(( UPGPKG + 1 )) - done fi - echo; echo - echo "( $UPGPKG upgrade, $NEWPKG new install )" echo - [ "$NOCONFIRM" ] || { - confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? - echo - } - error=0 count=0 - total=$(echo $WILLINSTALL | wc -w) - for inst in $WILLINSTALL; do # install all required dependencies and target packages itself + for i in ${NEWPKG[@]}; do count=$(( count + 1 )) - cd $(getportpath $inst) - if ! isinstalled $inst; then - settermtitle "[ $count/$total ] Installing $inst..." - pkgbuild -i $OPTS || { - error=1 - count=$(( count - 1 )) - break - } - else - settermtitle "[ $count/$total ] Upgrading $inst..." - pkgbuild -u $OPTS || { + echo -en "[${CYAN}n${CRESET}] $i " + done + for i in ${PKGNAME[@]}; do + count=$(( count + 1 )) + echo -en "[${GREEN}u${CRESET}] $i " + done + echo + echo + echo "( ${#PKGNAME[@]} upgrade, ${#NEWPKG[@]} new install )" + echo + total=$count + count=0 + if [ ! "$NOCONFIRM" ]; then + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." + echo + fi + if [ ${#NEWPKG[@]} -gt 0 ]; then + for newpkg in ${NEWPKG[@]}; do + count=$(( count + 1 )) + pushd $(getportpath $newpkg) + settermtitle "[ $count/$total ] Installing $newpkg..." + pkgbuild -i ${OPTS[@]} + if [ $? != 0 ]; then + error=1 + count=$(( count - 1 )) + break + fi + done_pkg+=($newpkg) + popd + done + fi + for pkg in ${PKGNAME[@]}; do # upgrade all target packages + count=$(( count + 1 )) + pushd $(getportpath $pkg) + settermtitle "[ $count/$total ] Upgrading $pkg..." + pkgbuild -u ${OPTS[@]} + if [ $? != 0 ]; then error=1 count=$(( count - 1 )) break - } - fi - cd - >/dev/null - done_pkg="$done_pkg $inst" + fi + done_pkg+=($pkg) + popd done - settermtitle "Triggering install hook." - [ "$done_pkg" ] && scratch_trigger $done_pkg - settermtitle "$count/$total package(s) upgraded." - return "$error" + settermtitle "triggering upgrade hook" + if [ ${#done_pkg[@]} -gt 0 ]; then + scratch_trigger ${done_pkg[@]} + fi + settermtitle "$count/$total package(s) upgraded" + return $error } scratch_outdate() { + local pkg + for pkg in $(allinstalled); do - if [ "$(getportpath $pkg)" ]; then + if [ $(getportpath $pkg) ]; then . $(getportpath $pkg)/$BUILD_SCRIPT if [ -z "$name" ] || [ -z "$version" ]; then continue fi iversion=$(installed_pkg_info version $pkg) irelease=$(installed_pkg_info release $pkg) - [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" - if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then - ITSLOCK="[masked]" - fi - #outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" - #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" - outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" - newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" - + [ -f "$INDEX_DIR/$pkg/.lock" ] && ITSLOCK="[locked]" + outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" + newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" if [ "$version" != "$iversion" ]; then vercomp $version $iversion if [ $? = 2 ]; then @@ -941,174 +1215,162 @@ scratch_outdate() { [ ! "$OUTDATE" ] && msg "All packages are up to date." } -scratch_search() { - needarg $@ - arg=$* - for repo in $PORT_REPO; do - [ -d $repo ] || continue - out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}' | sort) - [ "$out" ] || continue - found=1 - for line in $out; do - repo=$(echo $line | rev | awk -F / '{print $3}' | rev) - desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') - . $line - if isinstalled $name; then - ins="[${GREEN}*${CRESET}]" - else - ins="[ ]" - fi - printf "$ins ${PURPLE}($repo)${CRESET} $name ${CYAN}$version-$release${CRESET}: $desc\n" - unset repo desc name version release build +clearpkgcache() { + if [ ${#ALL_PACKAGES[@]} -gt 0 ]; then + for pkg in ${ALL_PACKAGES[@]}; do + rm -v $PACKAGE_DIR/$pkg done - unset out - done - if [ ! "$found" ]; then - msg "No matching package found." fi + + if [ ${#ALL_SOURCES[@]} -gt 0 ]; then + for src in ${ALL_SOURCES[@]}; do + rm -v $SOURCE_DIR/$src + done + fi } -scratch_cache() { - needroot "Clear old caches" - - allcachepkg=/tmp/.allcachepkg.$$ - allcachesrc=/tmp/.allcachesrc.$$ - keepcachepkg=/tmp/.keepcachepkg.$$ - keepcachesrc=/tmp/.keepcachesrc.$$ - diffcachepkg=/tmp/.diffcachepkg.$$ - diffcachesrc=/tmp/.diffcachesrc.$$ +getpkgcache() { + COMPRESSION_MODE="xz" [ -f /etc/scratchpkg.conf ] && . /etc/scratchpkg.conf - touch \ - $allcachepkg \ - $allcachesrc \ - $keepcachepkg \ - $keepcachesrc \ - $diffcachepkg \ - $diffcachesrc - - if [ "$(find $PACKAGE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then - for list in "$PACKAGE_DIR"/*; do - basename $list >> "$allcachepkg" - done - fi + for list in "$PACKAGE_DIR"/*; do + [ -f "$list" ] && ALL_PACKAGES+=($(basename $list)) + done - if [ "$(find $SOURCE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then - for list in "$SOURCE_DIR"/*; do - basename $list >> "$allcachesrc" - done - fi + for list in "$SOURCE_DIR"/*; do + [ -f "$list" ] && ALL_SOURCES+=($(basename $list)) + done - for repo in $PORT_REPO; do + for repo in ${PORT_REPO[@]}; do if [ "$(find $repo/*/ -mindepth 1 -print -quit 2>/dev/null)" ]; then # check directory if its not empty for port in $repo/*/$BUILD_SCRIPT; do . $port - echo "$name-$version-$release.spkg.tar.$COMPRESSION_MODE" >> "$keepcachepkg" - if [ "$source" ]; then - for src in $source; do - if echo $src | grep -Eq "(ftp|http|https)://"; then - if echo $src | grep -Eq "::(ftp|http|https)://"; then + PORT_PACKAGES+=($name-$version-$release.spkg.tar.$COMPRESSION_MODE) + if [ -n "$source" ]; then + for src in ${source[@]}; do + if [ $(echo $src | grep -E "(ftp|http|https)://") ]; then + if [ $(echo $src | grep -E "::(ftp|http|https)://") ]; then sourcename="$(echo $src | awk -F '::' '{print $1}')" else sourcename="$(echo $src | rev | cut -d / -f 1 | rev)" fi - echo $sourcename >> "$keepcachesrc" + SOURCE_NAMES+=($sourcename) fi done fi done fi done - grep -Fxv -f "$keepcachepkg" "$allcachepkg" > "$diffcachepkg" - grep -Fxv -f "$keepcachesrc" "$allcachesrc" > "$diffcachesrc" - cat $diffcachepkg - cat $diffcachesrc + for i in ${PORT_PACKAGES[@]}; do + for pkg in ${!ALL_PACKAGES[@]}; do + if [ "${ALL_PACKAGES[pkg]}" = "$i" ]; then + unset 'ALL_PACKAGES[pkg]' + break + fi + done + done + + for a in ${SOURCE_NAMES[@]}; do + for src in ${!ALL_SOURCES[@]}; do + if [ "${ALL_SOURCES[src]}" = "$a" ]; then + unset 'ALL_SOURCES[src]' + break + fi + done + done +} + +scratch_cache() { + getpkgcache - if [ -s "$diffcachepkg" ]; then - cd "$PACKAGE_DIR" - sizepkg=$(du -ch $(cat $diffcachepkg) | grep total | awk '{print $1}') - cd - >/dev/null + if [ ${#ALL_PACKAGES[@]} -gt 0 ]; then + ALL_PACKAGES_SIZE=$(pushd "$PACKAGE_DIR" && du -ch ${ALL_PACKAGES[@]} | grep total | awk '{print $1}' && popd) else - sizepkg=0M + ALL_PACKAGES_SIZE=0M fi - if [ -s "$diffcachesrc" ]; then - cd "$SOURCE_DIR" - sizesrc=$(du -ch $(cat $diffcachesrc) | grep total | awk '{print $1}') - cd - >/dev/null + if [ ${#ALL_SOURCES[@]} -gt 0 ]; then + ALL_SOURCES_SIZE=$(pushd "$SOURCE_DIR" && du -ch ${ALL_SOURCES[@]} | grep total | awk '{print $1}' && popd) else - sizesrc=0M + ALL_SOURCES_SIZE=0M fi - echo "Total package cache size: $sizepkg" - echo "Total source cache size : $sizesrc" + [ ${#ALL_PACKAGES[@]} -gt 0 ] && (echo ${ALL_PACKAGES[@]} | tr ' ' '\n') + [ ${#ALL_SOURCES[@]} -gt 0 ] && (echo ${ALL_SOURCES[@]} | tr ' ' '\n') - if [ -s "$diffcachepkg" ] || [ -s "$diffcachesrc" ]; then - echo - confirm "Clear old caches?" "Old caches is kept." && { - for i in $(cat $diffcachepkg); do - [ -e "$PACKAGE_DIR/$i" ] && rm -v "$PACKAGE_DIR/$i" - done - for i in $(cat $diffcachesrc); do - [ -e "$SOURCE_DIR/$i" ] && rm -v "$SOURCE_DIR/$i" - done - } + echo + echo -e "Package caches ($ALL_PACKAGES_SIZE)" + echo -e "Source caches ($ALL_SOURCES_SIZE)" + echo + + if [ ${#ALL_PACKAGES[@]} -gt 0 ] || [ ${#ALL_SOURCES[@]} -gt 0 ]; then + confirm "Clear old caches?" "Old caches is keep." + needroot "Clear old caches" + clearpkgcache fi +} + +scratch_path() { + needarg $@ - rm -f \ - "$allcachepkg" \ - "$allcachesrc" \ - "$keepcachepkg" \ - "$keepcachesrc" \ - "$diffcachepkg" \ - "$diffcachesrc" + if PPATH=$(getportpath "$1"); then + echo "$PPATH" + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + +scratch_dup() { + dup=$(find ${PORT_REPO[@]} -type d -print | grep -Exv "($(echo ${PORT_REPO[@]} | tr ' ' '|'))" | \ + rev | cut -d '/' -f1 | rev | sort | uniq -d) + + if [ "$dup" ]; then + for dp in $dup; do + for repo in ${PORT_REPO[@]}; do + [ -d $repo/$dp ] && echo "$repo/$dp" + done + done + else + msg "No duplicate ports found." + fi } scratch_deplist() { - OLDIFS=$IFS - IFS=, while [ "$1" ]; do case $1 in - -q|--quick) quick=1;; - --exclude=*) for i in ${1#*=}; do exclude="$exclude $i"; done;; + -q) quick=1;; + --exclude=*) IFS=, read -r -a exclude <<< ${1#*=};; -*) ;; - *) PKG="$PKG $1";; + *) PKG+=($1);; esac shift done - IFS=$OLDIFS - [ "$PKG" ] || { - echo "Please specify package(s) to list dependencies." - return 1 - } - for p in $PKG; do - if [ "$(getportpath $p)" ]; then - PPKG="$PPKG $p" - else - [ "$quick" = 1 ] || msgerr "Package '$p' not exist." - fi - done - for p in $PPKG; do - deplist $p - done + if [ "${#PKG[@]}" -gt 0 ]; then + for p in ${PKG[@]}; do + deplist $p + done + else + return 1 + fi - [ "$DEP" ] || return 0 + [[ ${DEP[@]} ]] || return 0 if [ "$quick" = 1 ]; then - echo $DEP | tr ' ' '\n' + echo ${DEP[@]} | tr ' ' '\n' else - for p in $DEP; do + for p in ${DEP[@]}; do if isinstalled $p; then echo "[*] $p" else echo "[-] $p" fi done - if [ "$MISSINGDEP" ]; then - for m in $MISSINGDEP; do + if [ "${#MISSINGDEP[@]}" -gt 0 ]; then + for m in ${MISSINGDEP[@]}; do echo "Missing deps: $m" | sed 's/(/ (/' done fi @@ -1117,29 +1379,28 @@ scratch_deplist() { deplist() { # skip excluded dependencies - if echo $exclude | tr " " "\n" | grep -qx $1; then + if [[ $(echo ${exclude[@]} | tr " " "\n" | grep -x $1) ]]; then return 0 fi - # check currently process for circular dependencies - # for circular dependencies, found first will take precedence - [ "$CHECK" ] && { - if echo $CHECK | tr " " "\n" | grep -qx $1; then + # check currently process package for loop + if [ ${#CHECK[@]} -gt 0 ]; then + if [[ "$(echo ${CHECK[@]} | tr " " "\n" | grep -x $1)" == "$1" ]]; then return 0 fi - } + fi # add package to currently process - CHECK="$CHECK $1" + CHECK+=($1) # check dependencies for i in $(get_depends $1); do if [ "$quick" = 1 ] && isinstalled $i; then continue else - if ! echo $DEP | tr " " "\n" | grep -qx $i; then + if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "" ]]; then if ! getportpath $i >/dev/null; then - MISSINGDEP="$MISSINGDEP $i($1)" + MISSINGDEP+=("$i($1)") else deplist $i fi @@ -1148,322 +1409,248 @@ deplist() { done # add dependency to list checked dep - if ! echo $DEP | tr " " "\n" | grep -qx $1; then - if [ "$quick" = 1 ]; then - isinstalled $1 || DEP="$DEP $1" + if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $1) = "" ]]; then + if [ "$quick" != 1 ]; then + DEP+=($1) else - DEP="$DEP $1" + isinstalled $1 || DEP+=($1) fi fi - # delete item from loop process - CHECK=$(echo $CHECK | sed "s/$1//") -} - -scratch_cat() { - needarg $@ - if PPATH=$(getportpath "$1"); then - cat "$PPATH/$BUILD_SCRIPT" - else - msgerr "Port '$1' not exist." - return 1 - fi -} - -scratch_dependent() { - needarg $@ - if [ "$(getportpath $1)" ]; then - grep -R "# depends[[:blank:]]*:" $PORT_REPO \ - | sed "s,:# depends[[:blank:]]*:[[:blank:]]*,#|,;s, ,|,g;s,$,|,g" \ - | grep "|$1|" \ - | awk -F "#" '{print $1}' \ - | rev \ - | awk -F / '{print $2}' \ - | rev - else - msgerr "Port '$1' not exist." - return 1 - fi -} - -scratch_depends() { - needarg $@ - if getportpath "$1" >/dev/null; then - depends=$(get_depends $1) - else - msgerr "Port '$1' not exist." - return 1 - fi - - for dep in $depends; do - if isinstalled $dep; then - msginst "$dep" - elif getportpath $dep >/dev/null; then - msgnoinst "$dep" - else - msgmiss "$dep" + # delete process package array + for i in "${!CHECK[@]}"; do + if [[ ${CHECK[i]} = "$1" ]]; then + unset 'CHECK[i]' fi done } -scratch_dup() { - dup=$(find $PORT_REPO -type d -print | grep -Exv "($(echo $PORT_REPO | tr ' ' '|'))" | \ - rev | cut -d '/' -f1 | rev | sort | uniq -d) - - if [ "$dup" ]; then - for dp in $dup; do - for repo in $PORT_REPO; do - [ -d $repo/$dp ] && echo "$repo/$dp" - done - done - else - msg "No duplicate ports found." - fi -} - -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" - fi - unset iname iversion irelease - done -} - -scratch_info() { - needarg $@ - ppath=$(getportpath $1) || return 1 - - . $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:]]*//') - deps=$(get_depends $1 | tr '\n' ' ') - - echo "Name: $1" - echo "Path: $ppath" - echo "Version: $version" - echo "Release: $release" - echo "Description: $desc" - echo "Maintainer: $maint" - echo "Dependencies: $deps" -} - -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 - done +usage_extra() { + cat << EOF +Usage: + $(basename $0) [ ] + +Operation: + depends show depends of a package + search search packages in port's repos + lock lock packages from upgrade + unlock unlock packages from upgrade + cat view a package build scripts + dependent show package's dependent + own show package's owner of file + files show list files of installed package + path show package's buildscripts path + readme print readme file if exist + info print ports info + sync update port's repo + dup print duplicate ports in repo + listinst list installed package in system + listorphan list orphan package + integrity check integrity of package's files + outdate check for outdated packages + cache print leftover cache + missingdep check for mising dependency of installed package + foreignpkg print package installed without port in repo + listlocked print locked packages + +EOF } -scratch_missingdep() { - for pkg in $(allinstalled); do - if getportpath "$pkg" >/dev/null; then - depends=$(get_depends $pkg) - fi - if [ "$depends" ]; then - for d in $depends; do - if ! isinstalled $d; then - if [ -z "$msd" ]; then - msd="$d" - else - msd="$msd $d" - fi - fi - done - fi - [ "$msd" ] && echo "$pkg: $msd" - unset depends msd - done +usage_build() { + cat << EOF +Usage: + $(basename $0) build [ ] + +Options: + -f, --force-rebuild force rebuild + -m, --skip-mdsum skip md5sum check for sources + -x, --extract extract only + -w, --keep-work keep woring directory + -o, --download download source files only + -l, --log log build process + --redownload re-download source files + --srcdir= override default SOURCE_DIR + --pkgdir= override default PACKAGE_DIR + --logdir= override default LOG_DIR + --workdir= override default WORK_DIR + +EOF } -scratch_locked() { - for pkg in $(allinstalled); do - [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" - done +usage_upgrade() { + cat << EOF +Usage: + $(basename $0) upgrade [ ] + +Options: + -d, --no-dep skip installing dependencies (new dependencies) + -c, --ignore-conflict skip file conflict check + -v, --verbose print install process + -y, --yes dont ask confirmation + -l, --log log build process + --exclude= exclude dependencies, comma separated + --no-backup skip backup configuration file + --no-preupgrade skip pre-upgrade script + --no-postupgrade skip post-upgrade script + --srcdir= override default SOURCE_DIR + --pkgdir= override default PACKAGE_DIR + --logdir= override default LOG_DIR + --workdir= override default WORK_DIR + +EOF } -scratch_orphan() { - tmpallpkg="/tmp/.pkgquery_allpkg.$$" - tmpalldep="/tmp/.pkgquery_alldep.$$" - for pkg in $(allinstalled); do - echo $pkg >> $tmpallpkg - dep="$dep $(get_depends $pkg)" - done - echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep" - grep -xvF -f "$tmpalldep" "$tmpallpkg" - rm "$tmpalldep" "$tmpallpkg" +usage_sysup() { + cat << EOF +Usage: + $(basename $0) sysup + +Options: + -d, --no-dep skip installing dependencies (new dependencies) + -c, --ignore-conflict skip file conflict check + -v, --verbose print install process + -s, --sync sync ports before upgrades + -y, --yes dont ask confirmation + -l, --log log build process + --exclude= exclude dependencies, comma separated + --no-backup skip backup configuration file + --no-preupgrade skip pre-upgrade script + --no-postupgrade skip post-upgrade script + --srcdir= override default SOURCE_DIR + --pkgdir= override default PACKAGE_DIR + --logdir= override default LOG_DIR + --workdir= override default WORK_DIR + +EOF } -scratch_path() { - needarg $@ - if PPATH=$(getportpath "$1"); then - echo "$PPATH" - else - msgerr "Port '$1' not exist." - return 1 - fi +usage_remove() { + cat << EOF +Usage: + $(basename $0) remove [ ] + +Options: + -v, --verbose print removed files + -y, --yes dont ask confirmation + --no-preremove skip pre-remove script + --no-postremove skip post-remove script + +EOF } -scratch_provide() { - needarg $@ - arg=$(echo $1 | sed "s/^\///") - grep -R "$arg" $PKGDB_DIR/*/.files \ - | sed "s:$PKGDB_DIR/::" \ - | sed "s:/.files::" \ - | tr : " " \ - | column -t +usage_install() { + cat << EOF +Usage: + $(basename $0) install [ ] + +Options: + -d, --no-dep skip installing dependencies + -c, --ignore-conflict skip file conflict check + -r, --reinstall reinstall installed package + -v, --verbose print install files + -l, --log log build process + -y, --yes dont ask confirmation + --exclude= exclude dependencies, comma separated + --no-backup skip backup configuration file (use with -r/--reinstall) + --no-preinstall skip pre-install script + --no-postinstall skip post-install script + --srcdir= override default SOURCE_DIR + --pkgdir= override default PACKAGE_DIR + --logdir= override default LOG_DIR + --workdir= override default WORK_DIR + +EOF } -scratch_readme() { - needarg $@ - if PPATH=$(getportpath "$1"); then - if [ -f "$PPATH/readme" ]; then - cat "$PPATH/readme" - else - msgerr "Port '$1' does not have readme." - fi - else - msgerr "Port '$1' not exist." - exit 1 - fi +usage_deplist() { + cat << EOF +Usage: + $(basename $0) deplist [ ] + +Options: + -q, --quick print only not-installed pkg in quick format + --exclude= exclude dependencies, comma separated + +EOF } -scratch_files() { - needarg $@ - if isinstalled $1; then - cat "$PKGDB_DIR/$1/.files" - else - msg "Package '$1' not installed." - fi -} -scratch_help() { +usage_help() { cat << EOF Usage: - $(basename $0) [] + $(basename $0) help + +Operations: + build build package + install install packages + upgrade upgrade packages + sysup full system upgrades + remove remove packages + deplist list all dependencies + extra various extra options -Options: - install install ports (use pkgbuild arg, except '-i' & '-u') - -r|--reinstall reinstall - -n|--no-dep skip dependencies - -y|--yes skip ask user permission - --exclude=* exclude dependencies, comma separated - - upgrade upgrade ports (use pkgbuild arg, except '-i' & '-r') - -n|--no-dep skip dependencies - -y|--yes skip ask user permission - --exclude=* exclude dependencies, comma separated - - remove remove installed ports (use pkgdel arg) - -y|--yes skip ask user permission - - sysup full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u') - -n|--no-dep skip dependencies - -y|--yes skip ask user permission - --exclude=* exclude dependencies, comma separated - - deplist print all dependencies for ports - -q|--quick skip installed ports - --exclude=* exclude dependencies, comma separated - - build build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') - --log log build process (/var/log/pkgbuild.log) - - lock locking ports prevent upgrade - unlock unlock locked ports - trigger [ports] run system trigger - search find ports in repo - cat print spkgbuild - depends print dependencies - dependent print dependent - path print path in repo - provide print port's provided files - readme print readme file, if exist - files print files installed - info print information - locate print location of files in ports repo - sync update ports database - outdate print outdated ports - cache print and clear old pkg and src caches - 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 - help print this help msg - Global options: - --append-repo= append custom repo path - --prepend-repo= prepend custom repo path - --repo-file= use custom repo file (default: $REPO_FILE) - --nocolor disable colour for output - + --repo= add custom local repo path + --root= use custom root path + --nocolor disable colour output + EOF } -print_runhelp_msg() { - echo "Run '$(basename $0) help' to see available options." - exit 2 +scratch_help() { + if [ -z "$1" ]; then + usage_help + return 0 + else + if [ "$(type -t usage_$1)" ]; then + usage_$1 + else + usage_help + fi + fi + return 0 } -# check for 'pkgadd', required for package database path -command -v pkgadd >/dev/null 2>&1 || { - echo "'pkgadd' not found in \$PATH!" - exit 1 +main() { + if [ "$(type -t scratch_$mode)" = "function" ]; then + scratch_$mode $@ + else + echo "Run 'scratch help' to see available operations and options" + return 5 + fi + return $? } mode=$1 - -[ "$mode" ] || { - print_runhelp_msg -} - shift for opt in $@; do case $opt in - --nocolor) nocolor;; - --repo=*) PORT_REPO="$PORT_REPO ${opt#*=}";; - --repo-file=*) REPO_FILE="${opt#*=}";; - --alias-file=*) ALIAS_FILE="${opt#*=}";; - --*) MAINOPTS="$MAINOPTS $opt";; - -*) char=${#opt}; count=1 - while [ "$count" != "$char" ]; do - count=$((count+1)) - MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)" - done;; - *) MAINOPTS="$MAINOPTS $opt";; + --nocolor) nocolor;; + --repo=*) PORT_REPO+=(${opt#*=});; + --root=*) ROOT_DIR=(${opt#*=});; + --*) MAINOPTS+=($opt);; + -*) for (( i=1; i<${#opt}; i++ )); do MAINOPTS+=(-${opt:$i:1}); done;; + *) MAINOPTS+=($opt);; esac - shift done BUILD_SCRIPT="spkgbuild" -PKGDB_DIR="$(pkgadd --print-dbdir)" -REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" -ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" -MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" +INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" +REPO_FILE="/etc/scratchpkg.repo" -# default value from pkgbuild SOURCE_DIR="/var/cache/scratchpkg/sources" PACKAGE_DIR="/var/cache/scratchpkg/packages" -COMPRESSION_MODE="xz" if [ -f "$REPO_FILE" ]; then - for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do - PORT_REPO="$PORT_REPO $repodir" - done + while read -r repodir repourl junk; do + case $repodir in + ""|"#"*) continue ;; + esac + PORT_REPO+=($repodir) + done < "$REPO_FILE" fi -if [ "$(command -v scratch_$mode)" ]; then - scratch_$mode $MAINOPTS -else - print_runhelp_msg -fi +main ${MAINOPTS[@]} exit $? From b0964cd5ecd92b75960442798c0ae881f5c7ee11 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Sun, 7 Mar 2021 15:16:42 -0500 Subject: [PATCH 03/13] Minor Updates --- scratch | 1718 +++++++++++++++++++++++++------------------------------ 1 file changed, 764 insertions(+), 954 deletions(-) mode change 100755 => 100644 scratch diff --git a/scratch b/scratch old mode 100755 new mode 100644 index 92a8087..ad411be --- a/scratch +++ b/scratch @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # scratchpkg # @@ -35,31 +35,31 @@ nocolor() { } msg() { - echo -e "${GREEN}==>${CRESET} $1" -} - -msgerr() { - echo -e "${RED}==> ERROR:${CRESET} $1" + printf "${GREEN}==>${CRESET} %s\n" "$1" } msginst() { - echo -e "[${GREEN}i${CRESET}] $1" + printf "[${GREEN}i${CRESET}] %s\n" "$1" } msgmiss() { - echo -e "[${YELLOW}m${CRESET}] $1" + printf "[${YELLOW}m${CRESET}] %s\n" "$1" } msgnoinst() { - echo -e "[ ] $1" + printf "[-] %s\n" "$1" +} + +msgerr() { + printf "${RED}==> ERROR:${CRESET} %s\n" "$1" >&2 } msgwarn() { - echo -e "${YELLOW}==> WARNING:${CRESET} $1" + printf "${YELLOW}==> WARNING:${CRESET} %s\n" "$1" >&2 } needroot() { - if [ $UID != 0 ]; then + if [ "$(id -u)" != 0 ]; then if [ "$#" -eq 0 ]; then needroot "This operation" else @@ -70,27 +70,19 @@ needroot() { } getportpath() { - for repo in ${PORT_REPO[@]}; do - if [[ -f $repo/$1/$BUILD_SCRIPT ]]; then - dirname $repo/$1/$BUILD_SCRIPT + for repo in $PORT_REPO; do + if [ -f "$repo/$1/$BUILD_SCRIPT" ]; then + dirname "$repo/$1/$BUILD_SCRIPT" return 0 fi done return 1 } -pushd() { - command pushd $1 &>/dev/null -} - -popd() { - command popd &>/dev/null -} - vercomp() { if [ "$1" = "$2" ]; then return 0 # same version - elif [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]; then + elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then return 1 # $1 lower than $2 else return 2 # $1 higher than $2 @@ -99,57 +91,67 @@ vercomp() { installed_pkg_info() { if isinstalled $2; then - grep ^$1 $INDEX_DIR/$2/.pkginfo | cut -d " " -f3- + grep ^$1 $PKGDB_DIR/$2/.pkginfo 2>/dev/null | cut -d " " -f3- fi } allinstalled() { - grep ^name "$INDEX_DIR"/*/.pkginfo | awk '{print $3}' + grep ^name "$PKGDB_DIR"/*/.pkginfo 2>/dev/null | awk '{print $3}' +} + +deps_alias() { + [ -f "$ALIAS_FILE" ] || { + echo $@ + return + } + while [ "$1" ]; do + if [ "$(grep -w ^$1 $ALIAS_FILE)" ]; then + getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}') + [ "$getalias" ] && echo "$getalias" + else + echo "$1" + fi + shift + unset getalias + done } get_depends() { - local pkg=$1 - ppath=$(getportpath $pkg) || return 0 - grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ + ppath=$(getportpath $1) || return 0 + deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ | tr ' ' '\n' \ | awk '!a[$0]++' \ - | sed 's/,//' + | sed 's/,//') + deps_alias $deps } confirm() { - read -r -p "$1 (Y/n) " response + printf "$1 (Y/n) " + read -r response case "$response" in - [Nn][Oo]|[Nn]) echo "$2"; exit 2 ;; + [Nn][Oo]|[Nn]) echo "$2"; return 2 ;; *) : ;; esac + return 0 } 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 } needarg() { - if [ -z "$*" ]; then + [ "$*" ] || { msgerr "This operation required an arguments!" exit 1 - fi -} - -scratch_cat() { - if PPATH=$(getportpath "$1"); then - cat "$PPATH/$BUILD_SCRIPT" - else - msgerr "Port '$1' not exist." - exit 1 - fi + } } isinstalled() { - if [ -s $INDEX_DIR/$1/.pkginfo ] && [[ $(grep $1 $INDEX_DIR/$1/.pkginfo) ]]; then + if [ -s "$PKGDB_DIR/$1/.pkginfo" ] && [ "$(grep $1 $PKGDB_DIR/$1/.pkginfo)" ]; then return 0 else return 1 @@ -157,166 +159,82 @@ isinstalled() { } settermtitle() { - echo -en "\033]0;$*\a" -} - -scratch_missingdep() { - local pkg d - - for pkg in $(allinstalled); do - if [ $(getportpath "$pkg") ]; then - depends=$(get_depends $pkg) - fi - if [ "$depends" ]; then - for d in ${depends[@]}; do - if ! isinstalled $d; then - msd+=($d) - fi - done - fi - if [ ${#msd[@]} -gt 0 ]; then - echo -e "${GREEN}$pkg${CRESET} missing ${RED}${msd[@]}${CRESET}" - fi - unset depends msd - done + printf "\033]0;$*\a" } scratch_integrity() { if [ "$1" ]; then - pushd / - if [ -f $INDEX_DIR/$1/.files ]; then - while read -r line; do + cd / + if [ -f $PKGDB_DIR/$1/.files ]; then + cat $PKGDB_DIR/$1/.files | while read -r line; do if [ ! -e "$line" ]; then - MISSING_FILE=yes if [ -L "$line" ]; then - echo -e "${YELLOW}broken symlink${CRESET} $1: /$line" + printf "${YELLOW}broken symlink${CRESET} $1: /$line" else - echo -e "${RED}file missing${CRESET} $1: /$line" + printf "${RED}file missing${CRESET} $1: /$line" fi fi - done < <(cat $INDEX_DIR/$1/.files) + done else echo "Package '$1' not installed." exit 1 fi - popd + cd - >/dev/null else - pushd / + cd / for pkg in $(allinstalled); do - while read -r line; do + cat $PKGDB_DIR/$pkg/.files | while read -r line; do if [ ! -e "$line" ]; then - MISSING_FILE=yes if [ -L "$line" ]; then - echo -e "${YELLOW}broken symlink${CRESET} $pkg: /$line" + echo "broken symlink $pkg: /$line" else - echo -e "${RED}file missing${CRESET} $pkg: /$line" + echo "missing file $pkg: /$line" fi fi - done < <(cat $INDEX_DIR/$pkg/.files) + done done - popd - fi - - [ "$UID" != "0" ] && msg "${YELLOW}(check integrity is recommended run as root or using sudo)${CRESET}" - if [ "$1" ]; then - p="Package '$1'" - else - p="Your system" + cd - >/dev/null fi - [ ! "$MISSING_FILE" ] && msg "$p files is consistent with package tree." -} - -scratch_listinst() { - for all in $(allinstalled); do - echo -ne "$all " - grep -e ^version -e ^release $INDEX_DIR/$all/.pkginfo | awk '{print $3}' | tr '\n' '-' | sed 's:\-$::' - echo - done -} - -scratch_listorphan() { - local pkg dep - tmpallpkg=$(mktemp) - tmpalldep=$(mktemp) - for pkg in $(allinstalled); do - echo $pkg >> $tmpallpkg - dep="$dep $(get_depends $pkg)" - done - echo $dep | tr ' ' '\n' | sort | uniq > $tmpalldep - grep -xvF -f $tmpalldep $tmpallpkg - rm $tmpalldep $tmpallpkg } scratch_lock() { - local pkg - - needroot "Locking package" - + needroot "Locking package" for pkg in "$@"; do if ! isinstalled $pkg; then msgerr "Package '$pkg' is not installed." - elif [ -f $INDEX_DIR/$pkg/.lock ]; then + elif [ -f $PKGDB_DIR/$pkg/.lock ]; then msgerr "Package '$pkg' already locked." else - touch $INDEX_DIR/$pkg/.lock && msg "Successfully locked package '$pkg'." + touch $PKGDB_DIR/$pkg/.lock && msg "Successfully locked package '$pkg'." fi done } +scratch_locate() { + needarg $@ + for repo in $PORT_REPO; do + grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' | column -t + done +} + scratch_unlock() { - local pkg - - needroot "Unlocking package" - + needroot "Unlocking package" for pkg in "$@"; do if ! isinstalled $pkg; then msgerr "Package '$pkg' is not installed." - elif [ ! -f $INDEX_DIR/$pkg/.lock ]; then + elif [ ! -f $PKGDB_DIR/$pkg/.lock ]; then msgerr "Package '$pkg' is not locked." else - rm -f $INDEX_DIR/$pkg/.lock && msg "Successfully unlocked package '$pkg'." + rm -f $PKGDB_DIR/$pkg/.lock && msg "Successfully unlocked package '$pkg'." fi done } -scratch_listlocked() { - local pkg - for pkg in $(allinstalled); do - if [ -f "$INDEX_DIR"/$pkg/.lock ]; then - echo -e "$pkg" - fi - done -} - -scratch_depends() { - local dep - - if [ $(getportpath "$1") ]; then - depends=$(get_depends $1) - else - msgerr "Port '$1' not exist." - exit 1 - fi - - for dep in ${depends[@]}; do - if isinstalled $dep; then - msginst "$dep" - elif getportpath $dep >/dev/null; then - msgnoinst "$dep" - else - msgmiss "$dep" - fi - done -} - scratch_isorphan() { - needarg $1 - + needarg $@ for pkg in $(allinstalled); do - pkgpath=$(getportpath $pkg) - if [ $pkgpath ]; then - depend=$(get_depends $pkg) - for dep in ${depend[@]}; do + if depend=$(get_depends $pkg); then + for dep in $depend; do if [ $dep = $1 ]; then return 1 fi @@ -327,53 +245,8 @@ scratch_isorphan() { return 0 } -scratch_dependent() { - local port all dep pname - - needarg $1 - - for port in ${PORT_REPO[@]}; do - if [ -d $port ]; then - for all in $port/*/$BUILD_SCRIPT; do - [ -f $all ] || continue - depend=$(grep "^# depends[[:blank:]]*:" $all | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' | tr ' ' '\n' | awk '!a[$0]++') - for dep in ${depend[@]}; do - if [ $dep = $1 ]; then - GDP=yes - pname=$(dirname $all) - pname=${pname##*/} - if isinstalled $pname; then - msginst "$pname" - else - msgnoinst "$pname" - fi - break - fi - done - done - fi - done - - [ "$GDP" ] && return 0 || return 1 -} - -scratch_own() { - local arg - arg=$(echo $1 | sed "s/^\///") - grep -R $arg $INDEX_DIR/*/.files | sed "s:$INDEX_DIR/::" | sed "s:/.files::" | tr : " " | column -t -} - -scratch_files() { - if ! isinstalled $1; then - msg "Package'$1' not installed." - else - cat $INDEX_DIR/$1/.files - fi -} - scratch_sync() { - checktool httpup - + checktool httpup needroot "Updating ports" if [ ! -e "$REPO_FILE" ]; then @@ -381,116 +254,21 @@ scratch_sync() { exit 1 fi - while read repodir repourl junk; do - case $repodir in - ""|"#"*) continue ;; - esac - if [ -n "$repodir" ] && [ -n "$repourl" ]; then - httpup sync $repourl $repodir - if [ $? != 0 ]; then + grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do + if [ "$repodir" ] && [ "$repourl" ]; then + httpup sync $repourl $repodir || { msgerr "Failed sync from $repourl" exit 1 - fi - fi - done < "$REPO_FILE" -} - -scratch_readme() { - needarg $@ - - if PPATH=$(getportpath "$1"); then - if [ -f "$PPATH/readme" ]; then - cat "$PPATH/readme" - else - msgerr "Port '$1' does not have readme." - fi - else - msgerr "Port '$1' not exist." - exit 1 - fi -} - -scratch_search() { - needarg $@ - - case $1 in - -*) msgerr "Invalid pattern '$1'" - return 1 ;; - esac - - local port found OUTPUT - - for port in ${PORT_REPO[@]}; do - if [ -d $port ]; then - pushd $port - OUTPUT=$(grep -R description | grep "$BUILD_SCRIPT:# description[[:blank:]]*:" | sed "s/$BUILD_SCRIPT:# description[[:blank:]]*://" | grep -i "$1" | cut -d '/' -f1 | sort) - popd - if [ -n "$OUTPUT" ]; then - found=yes - for out in ${OUTPUT[@]}; do - if [ -f $port/$out/$BUILD_SCRIPT ]; then - pushd $port/$out - description=$(grep "^# description[[:blank:]]*:" $BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') - . $BUILD_SCRIPT - popd - if [ -n "$name" ] && [ -n "$version" ] && [ -n "$release" ]; then - portname=$(basename $port) - search_result="${PURPLE}($portname)${CRESET} $name ${CYAN}$version-$release${CRESET} $description" - if isinstalled $name; then - echo -e "[${GREEN}*${CRESET}] $search_result" - else - echo -e "[ ] $search_result" - fi - unset description name version release - fi - fi - done - fi + } fi done - if [ ! "$found" ]; then - msg "No matching package found." - fi -} - -scratch_foreignpkg() { - 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 -e "$iname ${GREEN}$iversion${CRESET}-${CYAN}$irelease${CRESET}" - fi - unset iname iversion irelease - done -} - -scratch_info() { - needarg $@ - local pkg=$1 - ppath=$(getportpath $pkg) || return 1 - - . $ppath/$BUILD_SCRIPT - desc=$(grep "^# description[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') - url=$(grep "^# homepage[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# homepage[[:blank:]]*:[[:blank:]]*//') - maint=$(grep "^# maintainer[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# maintainer[[:blank:]]*:[[:blank:]]*//') - deps=$(get_depends $pkg | tr '\n' ' ') - - echo -e "Name: $pkg" - echo -e "Path: $ppath" - echo -e "Version: $version" - echo -e "Release: $release" - echo -e "Description: $desc" - echo -e "Homepage: $url" - echo -e "Maintainer: $maint" - echo -e "Dependencies: $deps" } scratch_trigger() { needroot "Run trigger" - if [[ -z "$@" ]]; then - for i in trig_{1..12}; do - eval $i=1 + if [ -z "$*" ]; then + for i in $(seq 12); do + eval trig_$i=1 done else pre_triggers $@ @@ -501,70 +279,59 @@ scratch_trigger() { post_triggers() { if [ "$trig_12" = 1 ]; then echo "trigger: Running mkdirs..." - for mkd in $INDEX_DIR/*/.pkgmkdirs; do + for mkd in $PKGDB_DIR/*/.pkgmkdirs; do [ -s $mkd ] || continue - while read dir mode uid gid junk; do - # Ignore comments and blank lines - case "$dir" in - ""|\#*) continue ;; - esac - if [ -e "$dir" ]; then - if [ "$uid" != '-' ]; then - getent passwd $uid >/dev/null - if [[ "$?" = 0 ]]; then - chown "$uid" "$dir" + grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do + if [ -e "$dir" ]; then + if [ "$uid" != '-' ]; then + getent passwd $uid >/dev/null && chown "$uid" "$dir" fi - fi - if [ "$gid" != '-' ]; then - getent group $gid >/dev/null - if [[ "$?" = 0 ]]; then - chgrp "$gid" "$dir" + if [ "$gid" != '-' ]; then + getent group $gid >/dev/null && chgrp "$gid" "$dir" + fi + if [ "$mode" != '-' ]; then + chmod "$mode" "$dir" fi fi - if [ "$mode" != '-' ]; then - chmod "$mode" "$dir" - fi - fi - done < "$mkd" - done - + done + 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 - gtk-update-icon-cache -q $dir &>/dev/null + if [ -e $dir/index.theme ]; then + gtk-update-icon-cache -q $dir 2>/dev/null else rm -f $dir/icon-theme.cache rmdir --ignore-fail-on-non-empty $dir @@ -572,40 +339,38 @@ 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} $dir/.uuid + for dir in $(find /usr/share/fonts -maxdepth 1 -type d \( ! -path /usr/share/fonts \)); do + rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid rmdir --ignore-fail-on-non-empty $dir - [[ -d $dir ]] || continue + [ -d "$dir" ] || continue mkfontdir $dir mkfontscale $dir 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 } -pre_triggers() { - local pkg - +pre_triggers() { # mime db if [ "$trig_1" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/mime/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/mime/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_1=1 break fi @@ -615,7 +380,7 @@ pre_triggers() { # desktop db if [ "$trig_2" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/applications/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/applications/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_2=1 break fi @@ -625,7 +390,7 @@ pre_triggers() { # mkfontdir if [ "$trig_3" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_3=1 break fi @@ -635,7 +400,7 @@ pre_triggers() { # hwdb if [ "$trig_4" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^etc/udev/hwdb.d/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^etc/udev/hwdb.d/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_4=1 break fi @@ -645,7 +410,7 @@ pre_triggers() { # icon caches if [ "$trig_5" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/icons/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/icons/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_5=1 break fi @@ -655,7 +420,7 @@ pre_triggers() { # gtk3 immodules if [ "$trig_6" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-3.0/3.0.0/immodules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then trig_6=1 break fi @@ -665,7 +430,7 @@ pre_triggers() { # gtk2 immodules if [ "$trig_7" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gtk-2.0/2.10.0/immodules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then trig_7=1 break fi @@ -675,7 +440,7 @@ pre_triggers() { # gsettings schema if [ "$trig_8" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/glib-2.0/schemas/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_8=1 break fi @@ -685,7 +450,7 @@ pre_triggers() { # gio modules if [ "$trig_9" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gio/modules/.*.so $PKGDB_DIR/$pkg/.files)" ]; then trig_9=1 break fi @@ -695,7 +460,7 @@ pre_triggers() { # gdk-pixbuf if [ "$trig_10" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/.*.so $PKGDB_DIR/$pkg/.files)" ]; then trig_10=1 break fi @@ -705,7 +470,7 @@ pre_triggers() { # font caches if [ "$trig_11" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/[^/]*/$ $INDEX_DIR/$pkg/.files)" ]; then + if [ -s "$PKGDB_DIR/$pkg/.files" ] && [ "$(grep ^usr/share/fonts/$ $PKGDB_DIR/$pkg/.files)" ]; then trig_11=1 break fi @@ -715,7 +480,7 @@ pre_triggers() { # makedirs if [ "$trig_12" != "1" ]; then for pkg in $@; do - if [ -s "$INDEX_DIR/$pkg/.pkgmkdirs" ]; then + if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then trig_12=1 break fi @@ -726,485 +491,443 @@ pre_triggers() { scratch_build() { while [ "$1" ]; do case $1 in - -i|-u|-r) ;; - -*) OPTS+=($1);; - *) PKGNAME+=($1);; + -i|-u|-r|-g|-p) ;; + --log) LOG=1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; esac shift done - for P in ${PKGNAME[@]}; do - pushd $(getportpath $P) - if [ $? = 0 ]; then - settermtitle "Building $P..." - pkgbuild ${OPTS[@]} || { - settermtitle "Building $P failed" + [ "$PKGNAME" ] || { + echo "Please specify package(s) to build." + return 1 + } + for pkg in $PKGNAME; do + ppath=$(getportpath $pkg) || { + echo "Package '$pkg' not found." + return 1 + } + cd $ppath + settermtitle "Building $pkg..." + if [ "$LOG" ]; then + pkgbuild $OPTS | tee /var/log/pkgbuild.log || { + settermtitle "Building $pkg failed." return 1 } - settermtitle "Building $P done" else - echo "Package '$P' not found." - return 1 + pkgbuild $OPTS || { + settermtitle "Building $pkg failed." + return 1 + } fi - popd + settermtitle "Building $pkg done." + cd - >/dev/null done } scratch_install() { - local pkg i int pkgcount count IPKG OPTS REINSTALL done_pkg - needroot "Installing package" - while [ "$1" ]; do case $1 in -i|-u) ;; - -r) REINSTALL=1;; + -r|--reinstall) REINSTALL=1;; -y|--yes) NOCONFIRM=1;; -n|--no-dep) NO_DEP=1;; --exclude=*) EXOPT=$1;; - -*) OPTS+=($1);; - *) PKGNAME+=($1);; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; esac shift - done - - if [ -z "$PKGNAME" ]; then + done + [ "$PKGNAME" ] || { echo "Please specify package(s) to install." return 1 - fi - # use custom root location - if [ "$ROOT_DIR" ]; then - OPTS+=(--root=$ROOT_DIR) - fi + } # if reinstall, dont calculate dep, just reinstall it then exit if [ "$REINSTALL" = 1 ]; then - for ii in ${PKGNAME[@]}; do + error=0 + for ii in $PKGNAME; do if [ ! $(getportpath $ii) ]; then echo "Package '$ii' not found." elif ! isinstalled $ii; then echo "Package '$ii' not installed." else - pushd $(getportpath $ii) + cd $(getportpath $ii) settermtitle "Reinstalling $ii..." - pkgbuild ${OPTS[@]} -r - if [ $? != 0 ]; then + pkgbuild $OPTS -r || { error=1 break - fi - done_pkg+=($ii) - popd + } + done_pkg="$done_pkg $ii" + cd - >/dev/null fi done - settermtitle "Triggering install hook" - if [ ${#done_pkg[@]} -gt 0 ]; then - scratch_trigger ${done_pkg[@]} - fi - settermtitle "Reinstalling done" - [ "$error" = 1 ] && return 1 || return 0 + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Reinstalling done." + return "$error" fi if [ "$NO_DEP" = 1 ]; then - for ii in ${PKGNAME[@]}; do + error=0 + for ii in $PKGNAME; do if [ ! $(getportpath $ii) ]; then echo "Package '$ii' not found." elif isinstalled $ii; then echo "Package '$ii' already installed." - return 0 + continue else - pushd $(getportpath $ii) + cd $(getportpath $ii) settermtitle "Installing $ii..." - pkgbuild -i ${OPTS[@]} - if [ $? != 0 ]; then + pkgbuild -i $OPTS || { error=1 break - fi - done_pkg+=($ii) - popd + } + done_pkg="$done_pkg $ii" + cd - >/dev/null fi done - settermtitle "Triggering install hook" - if [ ${#done_pkg[@]} -gt 0 ]; then - scratch_trigger ${done_pkg[@]} - fi - settermtitle "Installing done" - [ "$error" = 1 ] && return 1 || return 0 + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Installing done." + return "$error" fi - for i in ${PKGNAME[@]}; do + for i in $PKGNAME; do if [ ! $(getportpath $i) ]; then echo "Package '$i' not found." elif isinstalled $i; then echo "Package '$i' already installed." else - IPKG+=($i) + IPKG="$IPKG $i" fi done - if [ "${#IPKG[@]}" = 0 ]; then - return 0 - fi + [ "$IPKG" ] || return 0 echo "Resolving dependencies..." - INST="$(scratch_deplist -q ${IPKG[@]} $EXOPT)" - + INST="$(scratch_deplist -q $IPKG $EXOPT)" if [ "$INST" ]; then echo pkgcount=0 for pkg in $INST; do pkgcount=$(( pkgcount + 1 )) - echo -en "[${GREEN}i${CRESET}] $pkg " + printf "[${GREEN}i${CRESET}] $pkg " done echo; echo echo "( $pkgcount install )" echo if [ ! "$NOCONFIRM" ]; then - confirm "Continue install package(s)?" "Package installation cancelled." + confirm "Continue install package(s)?" "Package installation cancelled." || exit $? echo fi error=0 count=0 total=$(echo $INST | wc -w) - for int in ${INST[@]}; do + for int in $INST; do count=$(( count + 1 )) - portpathh=$(getportpath $int) - if [ "$portpathh" ]; then - pushd $portpathh + if portpathh=$(getportpath $int); then + cd $portpathh settermtitle "[ $count/$total ] installing $int..." - pkgbuild -i ${OPTS[@]} - if [ $? != 0 ]; then + pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break - fi - done_pkg+=($int) - popd + } + done_pkg="$done_pkg $int" + cd - >/dev/null else msgwarn "Skipping missing package: $int" fi unset portpathh done - settermtitle "Triggering install hook" - if [ ${#done_pkg[@]} -gt 0 ]; then - scratch_trigger ${done_pkg[@]} - fi - settermtitle "$count/$total package(s) installed" + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) installed." return "$error" fi } -outdatepkg() { - local pkg - - for pkg in $(allinstalled); do - if [ ! -e "$INDEX_DIR/$pkg/.lock" ] && getportpath $pkg >/dev/null; then - . $(getportpath $pkg)/$BUILD_SCRIPT - if [ -z "$name" ] || [ -z "$version" ]; then - continue - fi - iversion=$(installed_pkg_info version $pkg) - irelease=$(installed_pkg_info release $pkg) - if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then - echo $name - fi - unset iversion irelease version release - fi - done -} - scratch_remove() { - local pkg i IPKG OPTS - needroot "Removing package" - while [ "$1" ]; do case $1 in -y|--yes) NOCONFIRM=1;; - -*) OPTS+=($1);; - *) PKGNAME+=($1);; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; esac shift done - - if [ -z "$PKGNAME" ]; then + [ "$PKGNAME" ] || { echo "Please specify package(s) to remove." return 1 - fi - # use custom root location - if [ "$ROOT_DIR" ]; then - OPTS+=(--root=$ROOT_DIR) - fi - - for i in ${PKGNAME[@]}; do + } + for i in $PKGNAME; do if ! isinstalled $i; then echo "Package '$i' not installed." else - IPKG+=($i) + IPKG="$IPKG $i" fi done - if [ "${#IPKG[@]}" = 0 ]; then - return 0 - fi - if [ "$IPKG" ]; then - echo "Removing packages..." - echo - pkgcount=0 - count=0 - for pkg in ${IPKG[@]}; do - pkgcount=$(( pkgcount + 1 )) - echo -en "[${RED}x${CRESET}] $pkg " - done - echo; echo - echo "( $pkgcount remove )" + [ "$IPKG" ] || return 0 + echo "Removing packages..." + echo + pkgcount=0 + count=0 + for pkg in $IPKG; do + pkgcount=$(( pkgcount + 1 )) + printf "[${RED}x${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount remove )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue remove package(s)?" "Package removing cancelled." || exit $? echo - if [ ! "$NOCONFIRM" ]; then - confirm "Continue remove package(s)?" "Package removing cancelled." - echo - fi - for pkg in ${IPKG[@]}; do - count=$(( count + 1 )) - pre_triggers $pkg - settermtitle "[ $count/$pkgcount ] Removing $pkg..." - pkgdel $pkg ${OPTS[@]} || return 1 - done - settermtitle "Triggering remove hook" - post_triggers - settermtitle "$pkgcount package(s) removed" - fi + } + for pkg in $IPKG; do + count=$(( count + 1 )) + pre_triggers $pkg + settermtitle "[ $count/$pkgcount ] Removing $pkg..." + pkgdel $pkg $OPTS || { + error=1 + break + } + done + settermtitle "Triggering remove hook..." + post_triggers + settermtitle "$pkgcount package(s) removed." } -scratch_sysup() { - local d UPGPKG NEWPKG PKGOUTDATE OPTS done_pkg - - needroot "Upgrading package" - - while [ "$1" ]; do - case $1 in - -i|-u|-r) ;; - -y|--yes) NOCONFIRM=1;; - -d|--no-dep) NODEP=1;; - -s|--sync) SYNC=1;; - --exclude=*) EXOPT+=($1);; - -*) OPTS+=($1);; +outdatepkg() { + for pkg in $(allinstalled); do + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -w $pkg) ]; then + continue + fi + [ -e "$PKGDB_DIR/$pkg/.lock" ] && continue + getportpath $pkg >/dev/null || continue + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then + echo $name + fi + unset iversion irelease version release + done +} + +scratch_sysup() { + needroot "Upgrading package" + while [ "$1" ]; do + case $1 in + -i|-u|-r) ;; + -y|--yes) NOCONFIRM=1;; + -n|--no-dep) NODEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; esac shift done - - # use custom root location - if [ "$ROOT_DIR" ]; then - OPTS+=(--root=$ROOT_DIR) - fi - - if [ "$SYNC" = 1 ]; then - scratch_sync - fi - echo "Checking for outdated packages..." PKGOUTDATE=$(outdatepkg) - - if [ ! "$PKGOUTDATE" ]; then + [ "$PKGOUTDATE" ] || { echo "All packages are up to date." return 0 - fi - + } + [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && { + echo + msgerr "Please upgrade 'scratchpkg' first." + return 1 + } UPGPKG=0 - NEWPKG=0 - + NEWPKG=0 if [ "$NODEP" != 1 ]; then echo "Resolving dependencies..." - DEP=$(scratch_deplist ${PKGOUTDATE[@]} $EXOPT | awk '{print $2}') + DEP=$(scratch_deplist $PKGOUTDATE $EXOPT | awk '{print $2}') echo for d in $DEP; do if [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x $d)" = "$d" ]; then - echo -ne "[${GREEN}u${CRESET}] $d " - WILLINSTALL+=($d) + printf "[${GREEN}u${CRESET}] $d " + WILLINSTALL="$WILLINSTALL $d" UPGPKG=$(( UPGPKG + 1 )) - elif ! isinstalled $d && [ $(getportpath "$d") ]; then - echo -ne "[${CYAN}n${CRESET}] $d " - WILLINSTALL+=($d) + elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then + printf "[${CYAN}n${CRESET}] $d " + WILLINSTALL="$WILLINSTALL $d" NEWPKG=$(( NEWPKG + 1 )) fi done else echo - for dd in ${PKGOUTDATE[@]}; do - echo -ne "[${GREEN}u${CRESET}] $dd " - WILLINSTALL+=($dd) + for dd in $PKGOUTDATE; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" UPGPKG=$(( UPGPKG + 1 )) done fi - echo - echo + echo; echo echo "( $UPGPKG upgrade, $NEWPKG new install )" echo - if [ ! "$NOCONFIRM" ]; then - confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? echo - fi + } error=0 count=0 - total=$(echo ${WILLINSTALL[@]} | wc -w) - for inst in ${WILLINSTALL[@]}; do # install all required dependencies and target packages itself + total=$(echo $WILLINSTALL | wc -w) + for inst in $WILLINSTALL; do # install all required dependencies and target packages itself count=$(( count + 1 )) - pushd $(getportpath $inst) + cd $(getportpath $inst) if ! isinstalled $inst; then settermtitle "[ $count/$total ] Installing $inst..." - pkgbuild -i ${OPTS[@]} - if [ $? != 0 ]; then + pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break - fi + } else settermtitle "[ $count/$total ] Upgrading $inst..." - pkgbuild -u ${OPTS[@]} - if [ $? != 0 ]; then + pkgbuild -u $OPTS || { error=1 count=$(( count - 1 )) break - fi + } fi - done_pkg+=($inst) + cd - >/dev/null + done_pkg="$done_pkg $inst" done - settermtitle "Triggering install hook" - if [ ${#done_pkg[@]} -gt 0 ]; then - scratch_trigger ${done_pkg[@]} - fi - settermtitle "$count/$total package(s) upgraded" - return $error + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" } scratch_upgrade() { - local pkg done_pkg - - needroot "Upgrading package" - + needroot "Upgrading package" while [ "$1" ]; do case $1 in + -i|-r) ;; -y|--yes) NOCONFIRM=1;; -d|--no-dep) NO_DEP=1;; --exclude=*) EXOPT=$1;; - -*) OPTS+=($1);; - *) PKGNAME+=($1);; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; esac shift - done - - if [ -z "$PKGNAME" ]; then - echo "Please specify package(s) to remove." + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to upgrade." return 1 - fi - - # use custom root location - if [ "$ROOT_DIR" ]; then - OPTS+=(--root=$ROOT_DIR) - fi - for pkg in ${PKGNAME[@]}; do + } + for pkg in $PKGNAME; do if ! isinstalled $pkg; then - msgerr "Package '$pkg' not installed." - return 1 - fi - if [ ! $(getportpath $pkg) ]; then - msgerr "Package '$pkg' not exist." - return 1 - fi - . $(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." - return 0 + echo "Package '$pkg' not installed." + continue + elif [ ! $(getportpath $pkg) ]; then + 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 + echo "Package '$pkg' is up to date." + continue + fi fi + upkg="$upkg $pkg" done - if [ -z "$NO_DEP" ]; then + [ "$upkg" ] || return 0 + + UPGPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then echo "Resolving dependencies..." - DEP=$(scratch_deplist ${PKGNAME[@]} $EXOPT | awk '{print $2}') - for dep in $DEP; do - if ! isinstalled $dep; then - if [ $(getportpath $dep) ]; then - NEWPKG+=($dep) - fi + DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') + 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 - fi - echo - count=0 - for i in ${NEWPKG[@]}; do - count=$(( count + 1 )) - echo -en "[${CYAN}n${CRESET}] $i " - done - for i in ${PKGNAME[@]}; do - count=$(( count + 1 )) - echo -en "[${GREEN}u${CRESET}] $i " - done - echo - echo - echo "( ${#PKGNAME[@]} upgrade, ${#NEWPKG[@]} new install )" - echo - total=$count - count=0 - if [ ! "$NOCONFIRM" ]; then - confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." + else echo - fi - if [ ${#NEWPKG[@]} -gt 0 ]; then - for newpkg in ${NEWPKG[@]}; do - count=$(( count + 1 )) - pushd $(getportpath $newpkg) - settermtitle "[ $count/$total ] Installing $newpkg..." - pkgbuild -i ${OPTS[@]} - if [ $? != 0 ]; then - error=1 - count=$(( count - 1 )) - break - fi - done_pkg+=($newpkg) - popd + for dd in $upkg; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" + UPGPKG=$(( UPGPKG + 1 )) done fi - for pkg in ${PKGNAME[@]}; do # upgrade all target packages + echo; echo + echo "( $UPGPKG upgrade, $NEWPKG new install )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + echo + } + error=0 + count=0 + total=$(echo $WILLINSTALL | wc -w) + for inst in $WILLINSTALL; do # install all required dependencies and target packages itself count=$(( count + 1 )) - pushd $(getportpath $pkg) - settermtitle "[ $count/$total ] Upgrading $pkg..." - pkgbuild -u ${OPTS[@]} - if [ $? != 0 ]; then + cd $(getportpath $inst) + if ! isinstalled $inst; then + settermtitle "[ $count/$total ] Installing $inst..." + pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break - fi - done_pkg+=($pkg) - popd + } + else + settermtitle "[ $count/$total ] Upgrading $inst..." + pkgbuild -u $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + fi + cd - >/dev/null + done_pkg="$done_pkg $inst" done - settermtitle "triggering upgrade hook" - if [ ${#done_pkg[@]} -gt 0 ]; then - scratch_trigger ${done_pkg[@]} - fi - settermtitle "$count/$total package(s) upgraded" - return $error + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" } scratch_outdate() { - local pkg - for pkg in $(allinstalled); do - if [ $(getportpath $pkg) ]; then + if [ "$(getportpath $pkg)" ]; then . $(getportpath $pkg)/$BUILD_SCRIPT if [ -z "$name" ] || [ -z "$version" ]; then continue fi iversion=$(installed_pkg_info version $pkg) irelease=$(installed_pkg_info release $pkg) - [ -f "$INDEX_DIR/$pkg/.lock" ] && ITSLOCK="[locked]" - outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" - newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" + [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then + ITSLOCK="[masked]" + fi + outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" + newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" if [ "$version" != "$iversion" ]; then vercomp $version $iversion if [ $? = 2 ]; then - echo -e "$outdatemsg" + echo "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo -e "$newerinstmsg" + echo "$newerinstmsg" OUTDATE=yes fi elif [ "$release" != "$irelease" ]; then vercomp $release $irelease if [ $? = 2 ]; then - echo -e "$outdatemsg" + echo "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo -e "$newerinstmsg" + echo "$newerinstmsg" OUTDATE=yes fi fi @@ -1215,162 +938,174 @@ scratch_outdate() { [ ! "$OUTDATE" ] && msg "All packages are up to date." } -clearpkgcache() { - if [ ${#ALL_PACKAGES[@]} -gt 0 ]; then - for pkg in ${ALL_PACKAGES[@]}; do - rm -v $PACKAGE_DIR/$pkg +scratch_search() { + needarg $@ + arg=$* + for repo in $PORT_REPO; do + [ -d $repo ] || continue + out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}' | sort) + [ "$out" ] || continue + found=1 + for line in $out; do + repo=$(echo $line | rev | awk -F / '{print $3}' | rev) + desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') + . $line + if isinstalled $name; then + ins="[${GREEN}*${CRESET}]" + else + ins="[ ]" + fi + printf "$ins ${PURPLE}($repo)${CRESET} $name ${CYAN}$version-$release${CRESET}: $desc\n" + unset repo desc name version release build done + unset out + done + if [ ! "$found" ]; then + msg "No matching package found." fi - - if [ ${#ALL_SOURCES[@]} -gt 0 ]; then - for src in ${ALL_SOURCES[@]}; do - rm -v $SOURCE_DIR/$src - done - fi } -getpkgcache() { - COMPRESSION_MODE="xz" +scratch_cache() { + needroot "Clear old caches" + + allcachepkg=/tmp/.allcachepkg.$$ + allcachesrc=/tmp/.allcachesrc.$$ + keepcachepkg=/tmp/.keepcachepkg.$$ + keepcachesrc=/tmp/.keepcachesrc.$$ + diffcachepkg=/tmp/.diffcachepkg.$$ + diffcachesrc=/tmp/.diffcachesrc.$$ [ -f /etc/scratchpkg.conf ] && . /etc/scratchpkg.conf - for list in "$PACKAGE_DIR"/*; do - [ -f "$list" ] && ALL_PACKAGES+=($(basename $list)) - done + touch \ + $allcachepkg \ + $allcachesrc \ + $keepcachepkg \ + $keepcachesrc \ + $diffcachepkg \ + $diffcachesrc + + if [ "$(find $PACKAGE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$PACKAGE_DIR"/*; do + basename $list >> "$allcachepkg" + done + fi - for list in "$SOURCE_DIR"/*; do - [ -f "$list" ] && ALL_SOURCES+=($(basename $list)) - done + if [ "$(find $SOURCE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$SOURCE_DIR"/*; do + basename $list >> "$allcachesrc" + done + fi - for repo in ${PORT_REPO[@]}; do + for repo in $PORT_REPO; do if [ "$(find $repo/*/ -mindepth 1 -print -quit 2>/dev/null)" ]; then # check directory if its not empty for port in $repo/*/$BUILD_SCRIPT; do . $port - PORT_PACKAGES+=($name-$version-$release.spkg.tar.$COMPRESSION_MODE) - if [ -n "$source" ]; then - for src in ${source[@]}; do - if [ $(echo $src | grep -E "(ftp|http|https)://") ]; then - if [ $(echo $src | grep -E "::(ftp|http|https)://") ]; then + echo "$name-$version-$release.spkg.tar.$COMPRESSION_MODE" >> "$keepcachepkg" + if [ "$source" ]; then + for src in $source; do + if echo $src | grep -Eq "(ftp|http|https)://"; then + if echo $src | grep -Eq "::(ftp|http|https)://"; then sourcename="$(echo $src | awk -F '::' '{print $1}')" else sourcename="$(echo $src | rev | cut -d / -f 1 | rev)" fi - SOURCE_NAMES+=($sourcename) + echo $sourcename >> "$keepcachesrc" fi done fi done fi done + grep -Fxv -f "$keepcachepkg" "$allcachepkg" > "$diffcachepkg" + grep -Fxv -f "$keepcachesrc" "$allcachesrc" > "$diffcachesrc" - for i in ${PORT_PACKAGES[@]}; do - for pkg in ${!ALL_PACKAGES[@]}; do - if [ "${ALL_PACKAGES[pkg]}" = "$i" ]; then - unset 'ALL_PACKAGES[pkg]' - break - fi - done - done - - for a in ${SOURCE_NAMES[@]}; do - for src in ${!ALL_SOURCES[@]}; do - if [ "${ALL_SOURCES[src]}" = "$a" ]; then - unset 'ALL_SOURCES[src]' - break - fi - done - done -} - -scratch_cache() { - getpkgcache + cat $diffcachepkg + cat $diffcachesrc - if [ ${#ALL_PACKAGES[@]} -gt 0 ]; then - ALL_PACKAGES_SIZE=$(pushd "$PACKAGE_DIR" && du -ch ${ALL_PACKAGES[@]} | grep total | awk '{print $1}' && popd) + if [ -s "$diffcachepkg" ]; then + cd "$PACKAGE_DIR" + sizepkg=$(du -ch $(cat $diffcachepkg) | grep total | awk '{print $1}') + cd - >/dev/null else - ALL_PACKAGES_SIZE=0M + sizepkg=0M fi - if [ ${#ALL_SOURCES[@]} -gt 0 ]; then - ALL_SOURCES_SIZE=$(pushd "$SOURCE_DIR" && du -ch ${ALL_SOURCES[@]} | grep total | awk '{print $1}' && popd) + if [ -s "$diffcachesrc" ]; then + cd "$SOURCE_DIR" + sizesrc=$(du -ch $(cat $diffcachesrc) | grep total | awk '{print $1}') + cd - >/dev/null else - ALL_SOURCES_SIZE=0M + sizesrc=0M fi - [ ${#ALL_PACKAGES[@]} -gt 0 ] && (echo ${ALL_PACKAGES[@]} | tr ' ' '\n') - [ ${#ALL_SOURCES[@]} -gt 0 ] && (echo ${ALL_SOURCES[@]} | tr ' ' '\n') - - echo - echo -e "Package caches ($ALL_PACKAGES_SIZE)" - echo -e "Source caches ($ALL_SOURCES_SIZE)" - echo + echo "Total package cache size: $sizepkg" + echo "Total source cache size : $sizesrc" - if [ ${#ALL_PACKAGES[@]} -gt 0 ] || [ ${#ALL_SOURCES[@]} -gt 0 ]; then - confirm "Clear old caches?" "Old caches is keep." - needroot "Clear old caches" - clearpkgcache + if [ -s "$diffcachepkg" ] || [ -s "$diffcachesrc" ]; then + echo + confirm "Clear old caches?" "Old caches is kept." && { + for i in $(cat $diffcachepkg); do + [ -e "$PACKAGE_DIR/$i" ] && rm -v "$PACKAGE_DIR/$i" + done + for i in $(cat $diffcachesrc); do + [ -e "$SOURCE_DIR/$i" ] && rm -v "$SOURCE_DIR/$i" + done + } fi -} - -scratch_path() { - needarg $@ - if PPATH=$(getportpath "$1"); then - echo "$PPATH" - else - msgerr "Port '$1' not exist." - exit 1 - fi -} - -scratch_dup() { - dup=$(find ${PORT_REPO[@]} -type d -print | grep -Exv "($(echo ${PORT_REPO[@]} | tr ' ' '|'))" | \ - rev | cut -d '/' -f1 | rev | sort | uniq -d) - - if [ "$dup" ]; then - for dp in $dup; do - for repo in ${PORT_REPO[@]}; do - [ -d $repo/$dp ] && echo "$repo/$dp" - done - done - else - msg "No duplicate ports found." - fi + rm -f \ + "$allcachepkg" \ + "$allcachesrc" \ + "$keepcachepkg" \ + "$keepcachesrc" \ + "$diffcachepkg" \ + "$diffcachesrc" } scratch_deplist() { + OLDIFS=$IFS + IFS=, while [ "$1" ]; do case $1 in - -q) quick=1;; - --exclude=*) IFS=, read -r -a exclude <<< ${1#*=};; + -q|--quick) quick=1;; + --exclude=*) for i in ${1#*=}; do exclude="$exclude $i"; done;; -*) ;; - *) PKG+=($1);; + *) PKG="$PKG $1";; esac shift done - - if [ "${#PKG[@]}" -gt 0 ]; then - for p in ${PKG[@]}; do - deplist $p - done - else + IFS=$OLDIFS + [ "$PKG" ] || { + echo "Please specify package(s) to list dependencies." return 1 - fi + } + for p in $PKG; do + if [ "$(getportpath $p)" ]; then + PPKG="$PPKG $p" + else + [ "$quick" = 1 ] || msgerr "Package '$p' not exist." + fi + done - [[ ${DEP[@]} ]] || return 0 + for p in $PPKG; do + deplist $p + done + + [ "$DEP" ] || return 0 if [ "$quick" = 1 ]; then - echo ${DEP[@]} | tr ' ' '\n' + echo $DEP | tr ' ' '\n' else - for p in ${DEP[@]}; do + for p in $DEP; do if isinstalled $p; then echo "[*] $p" else echo "[-] $p" fi done - if [ "${#MISSINGDEP[@]}" -gt 0 ]; then - for m in ${MISSINGDEP[@]}; do + if [ "$MISSINGDEP" ]; then + for m in $MISSINGDEP; do echo "Missing deps: $m" | sed 's/(/ (/' done fi @@ -1379,28 +1114,29 @@ scratch_deplist() { deplist() { # skip excluded dependencies - if [[ $(echo ${exclude[@]} | tr " " "\n" | grep -x $1) ]]; then + if echo $exclude | tr " " "\n" | grep -qx $1; then return 0 fi - # check currently process package for loop - if [ ${#CHECK[@]} -gt 0 ]; then - if [[ "$(echo ${CHECK[@]} | tr " " "\n" | grep -x $1)" == "$1" ]]; then + # check currently process for circular dependencies + # for circular dependencies, found first will take precedence + [ "$CHECK" ] && { + if echo $CHECK | tr " " "\n" | grep -qx $1; then return 0 fi - fi + } # add package to currently process - CHECK+=($1) + CHECK="$CHECK $1" # check dependencies for i in $(get_depends $1); do if [ "$quick" = 1 ] && isinstalled $i; then continue else - if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "" ]]; then + if ! echo $DEP | tr " " "\n" | grep -qx $i; then if ! getportpath $i >/dev/null; then - MISSINGDEP+=("$i($1)") + MISSINGDEP="$MISSINGDEP $i($1)" else deplist $i fi @@ -1409,248 +1145,322 @@ deplist() { done # add dependency to list checked dep - if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $1) = "" ]]; then - if [ "$quick" != 1 ]; then - DEP+=($1) + if ! echo $DEP | tr " " "\n" | grep -qx $1; then + if [ "$quick" = 1 ]; then + isinstalled $1 || DEP="$DEP $1" else - isinstalled $1 || DEP+=($1) + DEP="$DEP $1" fi fi - # delete process package array - for i in "${!CHECK[@]}"; do - if [[ ${CHECK[i]} = "$1" ]]; then - unset 'CHECK[i]' + # delete item from loop process + CHECK=$(echo $CHECK | sed "s/$1//") +} + +scratch_cat() { + needarg $@ + if PPATH=$(getportpath "$1"); then + cat "$PPATH/$BUILD_SCRIPT" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_dependent() { + needarg $@ + if [ "$(getportpath $1)" ]; then + grep -R "# depends[[:blank:]]*:" $PORT_REPO \ + | sed "s,:# depends[[:blank:]]*:[[:blank:]]*,#|,;s, ,|,g;s,$,|,g" \ + | grep "|$1|" \ + | awk -F "#" '{print $1}' \ + | rev \ + | awk -F / '{print $2}' \ + | rev + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_depends() { + needarg $@ + if getportpath "$1" >/dev/null; then + depends=$(get_depends $1) + else + msgerr "Port '$1' not exist." + return 1 + fi + + for dep in $depends; do + if isinstalled $dep; then + msginst "$dep" + elif getportpath $dep >/dev/null; then + msgnoinst "$dep" + else + msgmiss "$dep" fi done } -usage_extra() { - cat << EOF -Usage: - $(basename $0) [ ] - -Operation: - depends show depends of a package - search search packages in port's repos - lock lock packages from upgrade - unlock unlock packages from upgrade - cat view a package build scripts - dependent show package's dependent - own show package's owner of file - files show list files of installed package - path show package's buildscripts path - readme print readme file if exist - info print ports info - sync update port's repo - dup print duplicate ports in repo - listinst list installed package in system - listorphan list orphan package - integrity check integrity of package's files - outdate check for outdated packages - cache print leftover cache - missingdep check for mising dependency of installed package - foreignpkg print package installed without port in repo - listlocked print locked packages - -EOF +scratch_dup() { + dup=$(find $PORT_REPO -type d -print | grep -Exv "($(echo $PORT_REPO | tr ' ' '|'))" | \ + rev | cut -d '/' -f1 | rev | sort | uniq -d) + + if [ "$dup" ]; then + for dp in $dup; do + for repo in $PORT_REPO; do + [ -d $repo/$dp ] && echo "$repo/$dp" + done + done + else + msg "No duplicate ports found." + fi } -usage_build() { - cat << EOF -Usage: - $(basename $0) build [ ] - -Options: - -f, --force-rebuild force rebuild - -m, --skip-mdsum skip md5sum check for sources - -x, --extract extract only - -w, --keep-work keep woring directory - -o, --download download source files only - -l, --log log build process - --redownload re-download source files - --srcdir= override default SOURCE_DIR - --pkgdir= override default PACKAGE_DIR - --logdir= override default LOG_DIR - --workdir= override default WORK_DIR - -EOF +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" + fi + unset iname iversion irelease + done } -usage_upgrade() { - cat << EOF -Usage: - $(basename $0) upgrade [ ] - -Options: - -d, --no-dep skip installing dependencies (new dependencies) - -c, --ignore-conflict skip file conflict check - -v, --verbose print install process - -y, --yes dont ask confirmation - -l, --log log build process - --exclude= exclude dependencies, comma separated - --no-backup skip backup configuration file - --no-preupgrade skip pre-upgrade script - --no-postupgrade skip post-upgrade script - --srcdir= override default SOURCE_DIR - --pkgdir= override default PACKAGE_DIR - --logdir= override default LOG_DIR - --workdir= override default WORK_DIR - -EOF +scratch_info() { + needarg $@ + ppath=$(getportpath $1) || return 1 + + . $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:]]*//') + deps=$(get_depends $1 | tr '\n' ' ') + + echo "Name: $1" + echo "Path: $ppath" + echo "Version: $version" + echo "Release: $release" + echo "Description: $desc" + echo "Maintainer: $maint" + echo "Dependencies: $deps" } -usage_sysup() { - cat << EOF -Usage: - $(basename $0) sysup - -Options: - -d, --no-dep skip installing dependencies (new dependencies) - -c, --ignore-conflict skip file conflict check - -v, --verbose print install process - -s, --sync sync ports before upgrades - -y, --yes dont ask confirmation - -l, --log log build process - --exclude= exclude dependencies, comma separated - --no-backup skip backup configuration file - --no-preupgrade skip pre-upgrade script - --no-postupgrade skip post-upgrade script - --srcdir= override default SOURCE_DIR - --pkgdir= override default PACKAGE_DIR - --logdir= override default LOG_DIR - --workdir= override default WORK_DIR - -EOF +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 + done } -usage_remove() { - cat << EOF -Usage: - $(basename $0) remove [ ] - -Options: - -v, --verbose print removed files - -y, --yes dont ask confirmation - --no-preremove skip pre-remove script - --no-postremove skip post-remove script - -EOF +scratch_missingdep() { + for pkg in $(allinstalled); do + if getportpath "$pkg" >/dev/null; then + depends=$(get_depends $pkg) + fi + if [ "$depends" ]; then + for d in $depends; do + if ! isinstalled $d; then + if [ -z "$msd" ]; then + msd="$d" + else + msd="$msd $d" + fi + fi + done + fi + [ "$msd" ] && echo "$pkg: $msd" + unset depends msd + done } -usage_install() { - cat << EOF -Usage: - $(basename $0) install [ ] - -Options: - -d, --no-dep skip installing dependencies - -c, --ignore-conflict skip file conflict check - -r, --reinstall reinstall installed package - -v, --verbose print install files - -l, --log log build process - -y, --yes dont ask confirmation - --exclude= exclude dependencies, comma separated - --no-backup skip backup configuration file (use with -r/--reinstall) - --no-preinstall skip pre-install script - --no-postinstall skip post-install script - --srcdir= override default SOURCE_DIR - --pkgdir= override default PACKAGE_DIR - --logdir= override default LOG_DIR - --workdir= override default WORK_DIR - -EOF +scratch_locked() { + for pkg in $(allinstalled); do + [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" + done } -usage_deplist() { - cat << EOF -Usage: - $(basename $0) deplist [ ] - -Options: - -q, --quick print only not-installed pkg in quick format - --exclude= exclude dependencies, comma separated - -EOF +scratch_orphan() { + tmpallpkg="/tmp/.pkgquery_allpkg.$$" + tmpalldep="/tmp/.pkgquery_alldep.$$" + for pkg in $(allinstalled); do + echo $pkg >> $tmpallpkg + dep="$dep $(get_depends $pkg)" + done + echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep" + grep -xvF -f "$tmpalldep" "$tmpallpkg" + rm "$tmpalldep" "$tmpallpkg" +} + +scratch_path() { + needarg $@ + if PPATH=$(getportpath "$1"); then + echo "$PPATH" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_provide() { + needarg $@ + arg=$(echo $1 | sed "s/^\///") + grep -R "$arg" $PKGDB_DIR/*/.files \ + | sed "s:$PKGDB_DIR/::" \ + | sed "s:/.files::" \ + | tr : " " \ + | column -t } +scratch_readme() { + needarg $@ + if PPATH=$(getportpath "$1"); then + if [ -f "$PPATH/readme" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + +scratch_files() { + needarg $@ + if isinstalled $1; then + cat "$PKGDB_DIR/$1/.files" + else + msg "Package '$1' not installed." + fi +} -usage_help() { +scratch_help() { cat << EOF Usage: - $(basename $0) help - -Operations: - build build package - install install packages - upgrade upgrade packages - sysup full system upgrades - remove remove packages - deplist list all dependencies - extra various extra options + $(basename $0) [] +Options: + install install ports (use pkgbuild arg, except '-i' & '-u') + -r|--reinstall reinstall + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + upgrade upgrade ports (use pkgbuild arg, except '-i' & '-r') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + remove remove installed ports (use pkgdel arg) + -y|--yes skip ask user permission + + sysup full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + deplist print all dependencies for ports + -q|--quick skip installed ports + --exclude=* exclude dependencies, comma separated + + build build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') + --log log build process (/var/log/pkgbuild.log) + + lock locking ports prevent upgrade + unlock unlock locked ports + trigger [ports] run system trigger + search find ports in repo + cat print spkgbuild + depends print dependencies + dependent print dependent + path print path in repo + provide print port's provided files + readme print readme file, if exist + files print files installed + info print information + locate print location of files in ports repo + sync update ports database + outdate print outdated ports + cache print and clear old pkg and src caches + 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 + help print this help msg + Global options: - --repo= add custom local repo path - --root= use custom root path - --nocolor disable colour output - + --append-repo= append custom repo path + --prepend-repo= prepend custom repo path + --repo-file= use custom repo file (default: $REPO_FILE) + --nocolor disable colour for output + EOF } -scratch_help() { - if [ -z "$1" ]; then - usage_help - return 0 - else - if [ "$(type -t usage_$1)" ]; then - usage_$1 - else - usage_help - fi - fi - return 0 +print_runhelp_msg() { + echo "Run '$(basename $0) help' to see available options." + exit 2 } -main() { - if [ "$(type -t scratch_$mode)" = "function" ]; then - scratch_$mode $@ - else - echo "Run 'scratch help' to see available operations and options" - return 5 - fi - return $? +# check for 'pkgadd', required for package database path +command -v pkgadd >/dev/null 2>&1 || { + echo "'pkgadd' not found in \$PATH!" + exit 1 } mode=$1 + +[ "$mode" ] || { + print_runhelp_msg +} + shift for opt in $@; do case $opt in - --nocolor) nocolor;; - --repo=*) PORT_REPO+=(${opt#*=});; - --root=*) ROOT_DIR=(${opt#*=});; - --*) MAINOPTS+=($opt);; - -*) for (( i=1; i<${#opt}; i++ )); do MAINOPTS+=(-${opt:$i:1}); done;; - *) MAINOPTS+=($opt);; + --nocolor) nocolor;; + --repo=*) PORT_REPO="$PORT_REPO ${opt#*=}";; + --repo-file=*) REPO_FILE="${opt#*=}";; + --alias-file=*) ALIAS_FILE="${opt#*=}";; + --*) MAINOPTS="$MAINOPTS $opt";; + -*) char=${#opt}; count=1 + while [ "$count" != "$char" ]; do + count=$((count+1)) + MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)" + done;; + *) MAINOPTS="$MAINOPTS $opt";; esac + shift done BUILD_SCRIPT="spkgbuild" -INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" -REPO_FILE="/etc/scratchpkg.repo" +PKGDB_DIR="$(pkgadd --print-dbdir)" +REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" +ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" +MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" +# default value from pkgbuild SOURCE_DIR="/var/cache/scratchpkg/sources" PACKAGE_DIR="/var/cache/scratchpkg/packages" +COMPRESSION_MODE="xz" if [ -f "$REPO_FILE" ]; then - while read -r repodir repourl junk; do - case $repodir in - ""|"#"*) continue ;; - esac - PORT_REPO+=($repodir) - done < "$REPO_FILE" + for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do + PORT_REPO="$PORT_REPO $repodir" + done fi -main ${MAINOPTS[@]} +if [ "$(command -v scratch_$mode)" ]; then + scratch_$mode $MAINOPTS +else + print_runhelp_msg +fi exit $? From 4a0296951874a648036f24c0eb22933b345ec30f Mon Sep 17 00:00:00 2001 From: Voncloft Date: Sun, 7 Mar 2021 16:06:06 -0500 Subject: [PATCH 04/13] Minor Updates --- scratch | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scratch b/scratch index ad411be..cd3beab 100644 --- a/scratch +++ b/scratch @@ -82,10 +82,13 @@ getportpath() { vercomp() { if [ "$1" = "$2" ]; then return 0 # same version - elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then + #elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then + elif [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then return 1 # $1 lower than $2 + #echo "1" else return 2 # $1 higher than $2 + #echo "2" fi } @@ -910,24 +913,26 @@ scratch_outdate() { if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then ITSLOCK="[masked]" fi - outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" - newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + #outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" + #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" + newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" if [ "$version" != "$iversion" ]; then vercomp $version $iversion if [ $? = 2 ]; then - echo "$outdatemsg" + echo -e "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo "$newerinstmsg" + echo -e "$newerinstmsg" OUTDATE=yes fi elif [ "$release" != "$irelease" ]; then vercomp $release $irelease if [ $? = 2 ]; then - echo "$outdatemsg" + echo -e "$outdatemsg" OUTDATE=yes elif [ $? = 1 ]; then - echo "$newerinstmsg" + echo -e "$newerinstmsg" OUTDATE=yes fi fi From 6762ce8b1ef53ac012780d81617ad3fb56aa9501 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Sun, 7 Mar 2021 16:15:39 -0500 Subject: [PATCH 05/13] Minor Updates --- pkgbuild | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgbuild b/pkgbuild index 25fe385..d8eb96f 100755 --- a/pkgbuild +++ b/pkgbuild @@ -445,9 +445,9 @@ check_buildscript() { if [ -z "$name" ]; then msgerr "'name' is empty!" exit 1 - elif [ "$(echo $name | grep -oP "\w*[A-Z]+\w*")" ]; then - msgerr "Capital letters for port name not allowed!" - exit 1 + #elif [ "$(echo $name | grep -oP "\w*[A-Z]+\w*")" ]; then + # msgerr "Capital letters for port name not allowed!" + # exit 1 elif [ "$(basename $(pwd))" != "$name" ]; then msgerr "Port name and Directory name is different!" exit 1 From d8c52810f37eea802c599100354f6d4721bc10fa Mon Sep 17 00:00:00 2001 From: Voncloft Date: Thu, 18 Mar 2021 09:17:07 -0400 Subject: [PATCH 06/13] Minor Updates --- old/scratch | 1471 +++++++++++++++++++++++++++++++++++++++++++++++++++ scratch | 24 + 2 files changed, 1495 insertions(+) create mode 100755 old/scratch mode change 100644 => 100755 scratch diff --git a/old/scratch b/old/scratch new file mode 100755 index 0000000..cd3beab --- /dev/null +++ b/old/scratch @@ -0,0 +1,1471 @@ +#!/bin/sh +# +# scratchpkg +# +# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +RED='\e[0;31m' +GREEN='\e[0;32m' +YELLOW='\e[0;33m' +CYAN='\e[0;36m' +PURPLE='\e[0;35m' +CRESET='\e[0m' + +nocolor() { + RED= + GREEN= + YELLOW= + CYAN= + PURPLE= + CRESET= +} + +msg() { + printf "${GREEN}==>${CRESET} %s\n" "$1" +} + +msginst() { + printf "[${GREEN}i${CRESET}] %s\n" "$1" +} + +msgmiss() { + printf "[${YELLOW}m${CRESET}] %s\n" "$1" +} + +msgnoinst() { + printf "[-] %s\n" "$1" +} + +msgerr() { + printf "${RED}==> ERROR:${CRESET} %s\n" "$1" >&2 +} + +msgwarn() { + printf "${YELLOW}==> WARNING:${CRESET} %s\n" "$1" >&2 +} + +needroot() { + if [ "$(id -u)" != 0 ]; then + if [ "$#" -eq 0 ]; then + needroot "This operation" + else + msgerr "$* need root access!" + fi + exit 1 + fi +} + +getportpath() { + for repo in $PORT_REPO; do + if [ -f "$repo/$1/$BUILD_SCRIPT" ]; then + dirname "$repo/$1/$BUILD_SCRIPT" + return 0 + fi + done + return 1 +} + +vercomp() { + if [ "$1" = "$2" ]; then + return 0 # same version + #elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then + elif [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then + return 1 # $1 lower than $2 + #echo "1" + else + return 2 # $1 higher than $2 + #echo "2" + fi +} + +installed_pkg_info() { + if isinstalled $2; then + grep ^$1 $PKGDB_DIR/$2/.pkginfo 2>/dev/null | cut -d " " -f3- + fi +} + +allinstalled() { + grep ^name "$PKGDB_DIR"/*/.pkginfo 2>/dev/null | awk '{print $3}' +} + +deps_alias() { + [ -f "$ALIAS_FILE" ] || { + echo $@ + return + } + while [ "$1" ]; do + if [ "$(grep -w ^$1 $ALIAS_FILE)" ]; then + getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}') + [ "$getalias" ] && echo "$getalias" + else + echo "$1" + fi + shift + unset getalias + done +} + +get_depends() { + ppath=$(getportpath $1) || return 0 + deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ + | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ + | tr ' ' '\n' \ + | awk '!a[$0]++' \ + | sed 's/,//') + deps_alias $deps +} + +confirm() { + printf "$1 (Y/n) " + read -r response + case "$response" in + [Nn][Oo]|[Nn]) echo "$2"; return 2 ;; + *) : ;; + esac + return 0 +} + +checktool() { + if ! command -v $1 >/dev/null; then + msgerr "'$1' not exist in your system!" + exit 1 + fi +} + +needarg() { + [ "$*" ] || { + msgerr "This operation required an arguments!" + exit 1 + } +} + +isinstalled() { + if [ -s "$PKGDB_DIR/$1/.pkginfo" ] && [ "$(grep $1 $PKGDB_DIR/$1/.pkginfo)" ]; then + return 0 + else + return 1 + fi +} + +settermtitle() { + printf "\033]0;$*\a" +} + +scratch_integrity() { + if [ "$1" ]; then + cd / + if [ -f $PKGDB_DIR/$1/.files ]; then + cat $PKGDB_DIR/$1/.files | while read -r line; do + if [ ! -e "$line" ]; then + if [ -L "$line" ]; then + printf "${YELLOW}broken symlink${CRESET} $1: /$line" + else + printf "${RED}file missing${CRESET} $1: /$line" + fi + fi + done + else + echo "Package '$1' not installed." + exit 1 + fi + cd - >/dev/null + else + cd / + for pkg in $(allinstalled); do + cat $PKGDB_DIR/$pkg/.files | while read -r line; do + if [ ! -e "$line" ]; then + if [ -L "$line" ]; then + echo "broken symlink $pkg: /$line" + else + echo "missing file $pkg: /$line" + fi + fi + done + done + cd - >/dev/null + 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 + grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' | column -t + 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 + if depend=$(get_depends $pkg); then + for dep in $depend; do + if [ $dep = $1 ]; then + return 1 + fi + done + fi + unset depend dep + done + return 0 +} + +scratch_sync() { + checktool httpup + needroot "Updating ports" + + if [ ! -e "$REPO_FILE" ]; then + msgerr "Repo file not found! ($REPO_FILE)" + exit 1 + fi + + grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do + if [ "$repodir" ] && [ "$repourl" ]; then + httpup sync $repourl $repodir || { + msgerr "Failed sync from $repourl" + exit 1 + } + fi + done +} + +scratch_trigger() { + needroot "Run trigger" + if [ -z "$*" ]; then + for i in $(seq 12); do + eval trig_$i=1 + done + else + pre_triggers $@ + fi + post_triggers +} + +post_triggers() { + if [ "$trig_12" = 1 ]; then + echo "trigger: Running mkdirs..." + for mkd in $PKGDB_DIR/*/.pkgmkdirs; do + [ -s $mkd ] || continue + grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do + if [ -e "$dir" ]; then + if [ "$uid" != '-' ]; then + getent passwd $uid >/dev/null && chown "$uid" "$dir" + fi + if [ "$gid" != '-' ]; then + getent group $gid >/dev/null && chgrp "$gid" "$dir" + fi + if [ "$mode" != '-' ]; then + chmod "$mode" "$dir" + fi + fi + done + done + fi + + if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then + echo "trigger: Updating fontconfig cache..." + fc-cache -s + fi + + 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 ] && [ $(command -v gio-querymodules) ]; then + echo "trigger: Updating GIO module cache..." + gio-querymodules /usr/lib/gio/modules + fi + + 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 ] && [ $(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 ] && [ $(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 ] && [ $(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 + gtk-update-icon-cache -q $dir 2>/dev/null + else + rm -f $dir/icon-theme.cache + rmdir --ignore-fail-on-non-empty $dir + fi + done + fi + + if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then + echo "trigger: Updating hardware database..." + udevadm hwdb --update + fi + + 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 \)); do + rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid + rmdir --ignore-fail-on-non-empty $dir + [ -d "$dir" ] || continue + mkfontdir $dir + mkfontscale $dir + done + fi + + 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 ] && [ $(command -v update-mime-database) ]; then + echo "trigger: Updating the MIME type database..." + update-mime-database /usr/share/mime + fi +} + +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 + trig_1=1 + break + fi + done + fi + + # 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 + trig_2=1 + break + fi + done + fi + + # 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 + trig_3=1 + break + fi + done + fi + + # 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 + trig_4=1 + break + fi + done + fi + + # 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 + trig_5=1 + break + fi + done + fi + + # 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 + trig_6=1 + break + fi + done + fi + + # 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 + trig_7=1 + break + fi + done + fi + + # 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 + trig_8=1 + break + fi + done + fi + + # 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 + trig_9=1 + break + fi + done + fi + + # 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 + trig_10=1 + break + fi + done + fi + + # 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 + trig_11=1 + break + fi + done + fi + + # makedirs + if [ "$trig_12" != "1" ]; then + for pkg in $@; do + if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then + trig_12=1 + break + fi + done + fi +} + +scratch_build() { + while [ "$1" ]; do + case $1 in + -i|-u|-r|-g|-p) ;; + --log) LOG=1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to build." + return 1 + } + for pkg in $PKGNAME; do + ppath=$(getportpath $pkg) || { + echo "Package '$pkg' not found." + return 1 + } + cd $ppath + settermtitle "Building $pkg..." + if [ "$LOG" ]; then + pkgbuild $OPTS | tee /var/log/pkgbuild.log || { + settermtitle "Building $pkg failed." + return 1 + } + else + pkgbuild $OPTS || { + settermtitle "Building $pkg failed." + return 1 + } + fi + settermtitle "Building $pkg done." + cd - >/dev/null + done +} + +scratch_install() { + needroot "Installing package" + while [ "$1" ]; do + case $1 in + -i|-u) ;; + -r|--reinstall) REINSTALL=1;; + -y|--yes) NOCONFIRM=1;; + -n|--no-dep) NO_DEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to install." + return 1 + } + # if reinstall, dont calculate dep, just reinstall it then exit + if [ "$REINSTALL" = 1 ]; then + error=0 + for ii in $PKGNAME; do + if [ ! $(getportpath $ii) ]; then + echo "Package '$ii' not found." + elif ! isinstalled $ii; then + echo "Package '$ii' not installed." + else + cd $(getportpath $ii) + settermtitle "Reinstalling $ii..." + pkgbuild $OPTS -r || { + error=1 + break + } + done_pkg="$done_pkg $ii" + cd - >/dev/null + fi + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Reinstalling done." + return "$error" + fi + if [ "$NO_DEP" = 1 ]; then + error=0 + for ii in $PKGNAME; do + if [ ! $(getportpath $ii) ]; then + echo "Package '$ii' not found." + elif isinstalled $ii; then + echo "Package '$ii' already installed." + continue + else + cd $(getportpath $ii) + settermtitle "Installing $ii..." + pkgbuild -i $OPTS || { + error=1 + break + } + done_pkg="$done_pkg $ii" + cd - >/dev/null + fi + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Installing done." + return "$error" + fi + for i in $PKGNAME; do + if [ ! $(getportpath $i) ]; then + echo "Package '$i' not found." + elif isinstalled $i; then + echo "Package '$i' already installed." + else + IPKG="$IPKG $i" + fi + done + [ "$IPKG" ] || return 0 + echo "Resolving dependencies..." + INST="$(scratch_deplist -q $IPKG $EXOPT)" + if [ "$INST" ]; then + echo + pkgcount=0 + for pkg in $INST; do + pkgcount=$(( pkgcount + 1 )) + printf "[${GREEN}i${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount install )" + echo + if [ ! "$NOCONFIRM" ]; then + confirm "Continue install package(s)?" "Package installation cancelled." || exit $? + echo + fi + error=0 + count=0 + total=$(echo $INST | wc -w) + for int in $INST; do + count=$(( count + 1 )) + if portpathh=$(getportpath $int); then + cd $portpathh + settermtitle "[ $count/$total ] installing $int..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + done_pkg="$done_pkg $int" + cd - >/dev/null + else + msgwarn "Skipping missing package: $int" + fi + unset portpathh + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) installed." + return "$error" + fi +} + +scratch_remove() { + needroot "Removing package" + while [ "$1" ]; do + case $1 in + -y|--yes) NOCONFIRM=1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to remove." + return 1 + } + for i in $PKGNAME; do + if ! isinstalled $i; then + echo "Package '$i' not installed." + else + IPKG="$IPKG $i" + fi + done + [ "$IPKG" ] || return 0 + echo "Removing packages..." + echo + pkgcount=0 + count=0 + for pkg in $IPKG; do + pkgcount=$(( pkgcount + 1 )) + printf "[${RED}x${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount remove )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue remove package(s)?" "Package removing cancelled." || exit $? + echo + } + for pkg in $IPKG; do + count=$(( count + 1 )) + pre_triggers $pkg + settermtitle "[ $count/$pkgcount ] Removing $pkg..." + pkgdel $pkg $OPTS || { + error=1 + break + } + done + settermtitle "Triggering remove hook..." + post_triggers + settermtitle "$pkgcount package(s) removed." +} + +outdatepkg() { + for pkg in $(allinstalled); do + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -w $pkg) ]; then + continue + fi + [ -e "$PKGDB_DIR/$pkg/.lock" ] && continue + getportpath $pkg >/dev/null || continue + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then + echo $name + fi + unset iversion irelease version release + done +} + +scratch_sysup() { + needroot "Upgrading package" + while [ "$1" ]; do + case $1 in + -i|-u|-r) ;; + -y|--yes) NOCONFIRM=1;; + -n|--no-dep) NODEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + esac + shift + done + echo "Checking for outdated packages..." + PKGOUTDATE=$(outdatepkg) + [ "$PKGOUTDATE" ] || { + echo "All packages are up to date." + return 0 + } + [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && { + echo + msgerr "Please upgrade 'scratchpkg' first." + return 1 + } + UPGPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then + echo "Resolving dependencies..." + DEP=$(scratch_deplist $PKGOUTDATE $EXOPT | awk '{print $2}') + echo + for d in $DEP; do + if [ "$(echo $PKGOUTDATE | 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 + else + echo + for dd in $PKGOUTDATE; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" + UPGPKG=$(( UPGPKG + 1 )) + done + fi + echo; echo + echo "( $UPGPKG upgrade, $NEWPKG new install )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + echo + } + error=0 + 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 $inst) + if ! isinstalled $inst; then + settermtitle "[ $count/$total ] Installing $inst..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + else + settermtitle "[ $count/$total ] Upgrading $inst..." + pkgbuild -u $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + fi + cd - >/dev/null + done_pkg="$done_pkg $inst" + done + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" +} + +scratch_upgrade() { + needroot "Upgrading package" + while [ "$1" ]; do + case $1 in + -i|-r) ;; + -y|--yes) NOCONFIRM=1;; + -d|--no-dep) NO_DEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to upgrade." + return 1 + } + for pkg in $PKGNAME; do + if ! isinstalled $pkg; then + echo "Package '$pkg' not installed." + continue + elif [ ! $(getportpath $pkg) ]; then + 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 + echo "Package '$pkg' is up to date." + continue + fi + fi + upkg="$upkg $pkg" + done + [ "$upkg" ] || return 0 + + UPGPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then + echo "Resolving dependencies..." + DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') + 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 + else + echo + for dd in $upkg; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" + UPGPKG=$(( UPGPKG + 1 )) + done + fi + echo; echo + echo "( $UPGPKG upgrade, $NEWPKG new install )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + echo + } + error=0 + 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 $inst) + if ! isinstalled $inst; then + settermtitle "[ $count/$total ] Installing $inst..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + else + settermtitle "[ $count/$total ] Upgrading $inst..." + pkgbuild -u $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + fi + cd - >/dev/null + done_pkg="$done_pkg $inst" + done + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" +} + +scratch_outdate() { + for pkg in $(allinstalled); do + if [ "$(getportpath $pkg)" ]; then + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then + ITSLOCK="[masked]" + fi + #outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" + #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" + newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" + if [ "$version" != "$iversion" ]; then + vercomp $version $iversion + if [ $? = 2 ]; then + echo -e "$outdatemsg" + OUTDATE=yes + elif [ $? = 1 ]; then + echo -e "$newerinstmsg" + OUTDATE=yes + fi + elif [ "$release" != "$irelease" ]; then + vercomp $release $irelease + if [ $? = 2 ]; then + echo -e "$outdatemsg" + OUTDATE=yes + elif [ $? = 1 ]; then + echo -e "$newerinstmsg" + OUTDATE=yes + fi + fi + unset ITSLOCK name version + fi + done + + [ ! "$OUTDATE" ] && msg "All packages are up to date." +} + +scratch_search() { + needarg $@ + arg=$* + for repo in $PORT_REPO; do + [ -d $repo ] || continue + out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}' | sort) + [ "$out" ] || continue + found=1 + for line in $out; do + repo=$(echo $line | rev | awk -F / '{print $3}' | rev) + desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') + . $line + if isinstalled $name; then + ins="[${GREEN}*${CRESET}]" + else + ins="[ ]" + fi + printf "$ins ${PURPLE}($repo)${CRESET} $name ${CYAN}$version-$release${CRESET}: $desc\n" + unset repo desc name version release build + done + unset out + done + if [ ! "$found" ]; then + msg "No matching package found." + fi +} + +scratch_cache() { + needroot "Clear old caches" + + allcachepkg=/tmp/.allcachepkg.$$ + allcachesrc=/tmp/.allcachesrc.$$ + keepcachepkg=/tmp/.keepcachepkg.$$ + keepcachesrc=/tmp/.keepcachesrc.$$ + diffcachepkg=/tmp/.diffcachepkg.$$ + diffcachesrc=/tmp/.diffcachesrc.$$ + + [ -f /etc/scratchpkg.conf ] && . /etc/scratchpkg.conf + + touch \ + $allcachepkg \ + $allcachesrc \ + $keepcachepkg \ + $keepcachesrc \ + $diffcachepkg \ + $diffcachesrc + + if [ "$(find $PACKAGE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$PACKAGE_DIR"/*; do + basename $list >> "$allcachepkg" + done + fi + + if [ "$(find $SOURCE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$SOURCE_DIR"/*; do + basename $list >> "$allcachesrc" + done + fi + + for repo in $PORT_REPO; do + if [ "$(find $repo/*/ -mindepth 1 -print -quit 2>/dev/null)" ]; then # check directory if its not empty + for port in $repo/*/$BUILD_SCRIPT; do + . $port + echo "$name-$version-$release.spkg.tar.$COMPRESSION_MODE" >> "$keepcachepkg" + if [ "$source" ]; then + for src in $source; do + if echo $src | grep -Eq "(ftp|http|https)://"; then + if echo $src | grep -Eq "::(ftp|http|https)://"; then + sourcename="$(echo $src | awk -F '::' '{print $1}')" + else + sourcename="$(echo $src | rev | cut -d / -f 1 | rev)" + fi + echo $sourcename >> "$keepcachesrc" + fi + done + fi + done + fi + done + grep -Fxv -f "$keepcachepkg" "$allcachepkg" > "$diffcachepkg" + grep -Fxv -f "$keepcachesrc" "$allcachesrc" > "$diffcachesrc" + + cat $diffcachepkg + cat $diffcachesrc + + if [ -s "$diffcachepkg" ]; then + cd "$PACKAGE_DIR" + sizepkg=$(du -ch $(cat $diffcachepkg) | grep total | awk '{print $1}') + cd - >/dev/null + else + sizepkg=0M + fi + + if [ -s "$diffcachesrc" ]; then + cd "$SOURCE_DIR" + sizesrc=$(du -ch $(cat $diffcachesrc) | grep total | awk '{print $1}') + cd - >/dev/null + else + sizesrc=0M + fi + + echo "Total package cache size: $sizepkg" + echo "Total source cache size : $sizesrc" + + if [ -s "$diffcachepkg" ] || [ -s "$diffcachesrc" ]; then + echo + confirm "Clear old caches?" "Old caches is kept." && { + for i in $(cat $diffcachepkg); do + [ -e "$PACKAGE_DIR/$i" ] && rm -v "$PACKAGE_DIR/$i" + done + for i in $(cat $diffcachesrc); do + [ -e "$SOURCE_DIR/$i" ] && rm -v "$SOURCE_DIR/$i" + done + } + fi + + rm -f \ + "$allcachepkg" \ + "$allcachesrc" \ + "$keepcachepkg" \ + "$keepcachesrc" \ + "$diffcachepkg" \ + "$diffcachesrc" +} + +scratch_deplist() { + OLDIFS=$IFS + IFS=, + while [ "$1" ]; do + case $1 in + -q|--quick) quick=1;; + --exclude=*) for i in ${1#*=}; do exclude="$exclude $i"; done;; + -*) ;; + *) PKG="$PKG $1";; + esac + shift + done + IFS=$OLDIFS + [ "$PKG" ] || { + echo "Please specify package(s) to list dependencies." + return 1 + } + for p in $PKG; do + if [ "$(getportpath $p)" ]; then + PPKG="$PPKG $p" + else + [ "$quick" = 1 ] || msgerr "Package '$p' not exist." + fi + done + + for p in $PPKG; do + deplist $p + done + + [ "$DEP" ] || return 0 + + if [ "$quick" = 1 ]; then + echo $DEP | tr ' ' '\n' + else + for p in $DEP; do + if isinstalled $p; then + echo "[*] $p" + else + echo "[-] $p" + fi + done + if [ "$MISSINGDEP" ]; then + for m in $MISSINGDEP; do + echo "Missing deps: $m" | sed 's/(/ (/' + done + fi + fi +} + +deplist() { + # skip excluded dependencies + if echo $exclude | tr " " "\n" | grep -qx $1; then + return 0 + fi + + # check currently process for circular dependencies + # for circular dependencies, found first will take precedence + [ "$CHECK" ] && { + if echo $CHECK | tr " " "\n" | grep -qx $1; then + return 0 + fi + } + + # add package to currently process + CHECK="$CHECK $1" + + # check dependencies + for i in $(get_depends $1); do + if [ "$quick" = 1 ] && isinstalled $i; then + continue + else + if ! echo $DEP | tr " " "\n" | grep -qx $i; then + if ! getportpath $i >/dev/null; then + MISSINGDEP="$MISSINGDEP $i($1)" + else + deplist $i + fi + fi + fi + done + + # add dependency to list checked dep + if ! echo $DEP | tr " " "\n" | grep -qx $1; then + if [ "$quick" = 1 ]; then + isinstalled $1 || DEP="$DEP $1" + else + DEP="$DEP $1" + fi + fi + + # delete item from loop process + CHECK=$(echo $CHECK | sed "s/$1//") +} + +scratch_cat() { + needarg $@ + if PPATH=$(getportpath "$1"); then + cat "$PPATH/$BUILD_SCRIPT" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_dependent() { + needarg $@ + if [ "$(getportpath $1)" ]; then + grep -R "# depends[[:blank:]]*:" $PORT_REPO \ + | sed "s,:# depends[[:blank:]]*:[[:blank:]]*,#|,;s, ,|,g;s,$,|,g" \ + | grep "|$1|" \ + | awk -F "#" '{print $1}' \ + | rev \ + | awk -F / '{print $2}' \ + | rev + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_depends() { + needarg $@ + if getportpath "$1" >/dev/null; then + depends=$(get_depends $1) + else + msgerr "Port '$1' not exist." + return 1 + fi + + for dep in $depends; do + if isinstalled $dep; then + msginst "$dep" + elif getportpath $dep >/dev/null; then + msgnoinst "$dep" + else + msgmiss "$dep" + fi + done +} + +scratch_dup() { + dup=$(find $PORT_REPO -type d -print | grep -Exv "($(echo $PORT_REPO | tr ' ' '|'))" | \ + rev | cut -d '/' -f1 | rev | sort | uniq -d) + + if [ "$dup" ]; then + for dp in $dup; do + for repo in $PORT_REPO; do + [ -d $repo/$dp ] && echo "$repo/$dp" + done + done + else + msg "No duplicate ports found." + fi +} + +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" + fi + unset iname iversion irelease + done +} + +scratch_info() { + needarg $@ + ppath=$(getportpath $1) || return 1 + + . $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:]]*//') + deps=$(get_depends $1 | tr '\n' ' ') + + echo "Name: $1" + echo "Path: $ppath" + echo "Version: $version" + echo "Release: $release" + echo "Description: $desc" + echo "Maintainer: $maint" + echo "Dependencies: $deps" +} + +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 + done +} + +scratch_missingdep() { + for pkg in $(allinstalled); do + if getportpath "$pkg" >/dev/null; then + depends=$(get_depends $pkg) + fi + if [ "$depends" ]; then + for d in $depends; do + if ! isinstalled $d; then + if [ -z "$msd" ]; then + msd="$d" + else + msd="$msd $d" + fi + fi + done + fi + [ "$msd" ] && echo "$pkg: $msd" + unset depends msd + done +} + +scratch_locked() { + for pkg in $(allinstalled); do + [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" + done +} + +scratch_orphan() { + tmpallpkg="/tmp/.pkgquery_allpkg.$$" + tmpalldep="/tmp/.pkgquery_alldep.$$" + for pkg in $(allinstalled); do + echo $pkg >> $tmpallpkg + dep="$dep $(get_depends $pkg)" + done + echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep" + grep -xvF -f "$tmpalldep" "$tmpallpkg" + rm "$tmpalldep" "$tmpallpkg" +} + +scratch_path() { + needarg $@ + if PPATH=$(getportpath "$1"); then + echo "$PPATH" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_provide() { + needarg $@ + arg=$(echo $1 | sed "s/^\///") + grep -R "$arg" $PKGDB_DIR/*/.files \ + | sed "s:$PKGDB_DIR/::" \ + | sed "s:/.files::" \ + | tr : " " \ + | column -t +} + +scratch_readme() { + needarg $@ + if PPATH=$(getportpath "$1"); then + if [ -f "$PPATH/readme" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + +scratch_files() { + needarg $@ + if isinstalled $1; then + cat "$PKGDB_DIR/$1/.files" + else + msg "Package '$1' not installed." + fi +} + +scratch_help() { + cat << EOF +Usage: + $(basename $0) [] + +Options: + install install ports (use pkgbuild arg, except '-i' & '-u') + -r|--reinstall reinstall + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + upgrade upgrade ports (use pkgbuild arg, except '-i' & '-r') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + remove remove installed ports (use pkgdel arg) + -y|--yes skip ask user permission + + sysup full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + deplist print all dependencies for ports + -q|--quick skip installed ports + --exclude=* exclude dependencies, comma separated + + build build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') + --log log build process (/var/log/pkgbuild.log) + + lock locking ports prevent upgrade + unlock unlock locked ports + trigger [ports] run system trigger + search find ports in repo + cat print spkgbuild + depends print dependencies + dependent print dependent + path print path in repo + provide print port's provided files + readme print readme file, if exist + files print files installed + info print information + locate print location of files in ports repo + sync update ports database + outdate print outdated ports + cache print and clear old pkg and src caches + 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 + help print this help msg + +Global options: + --append-repo= append custom repo path + --prepend-repo= prepend custom repo path + --repo-file= use custom repo file (default: $REPO_FILE) + --nocolor disable colour for output + +EOF +} + +print_runhelp_msg() { + echo "Run '$(basename $0) help' to see available options." + exit 2 +} + +# check for 'pkgadd', required for package database path +command -v pkgadd >/dev/null 2>&1 || { + echo "'pkgadd' not found in \$PATH!" + exit 1 +} + +mode=$1 + +[ "$mode" ] || { + print_runhelp_msg +} + +shift + +for opt in $@; do + case $opt in + --nocolor) nocolor;; + --repo=*) PORT_REPO="$PORT_REPO ${opt#*=}";; + --repo-file=*) REPO_FILE="${opt#*=}";; + --alias-file=*) ALIAS_FILE="${opt#*=}";; + --*) MAINOPTS="$MAINOPTS $opt";; + -*) char=${#opt}; count=1 + while [ "$count" != "$char" ]; do + count=$((count+1)) + MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)" + done;; + *) MAINOPTS="$MAINOPTS $opt";; + esac + shift +done + +BUILD_SCRIPT="spkgbuild" +PKGDB_DIR="$(pkgadd --print-dbdir)" +REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" +ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" +MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" + +# default value from pkgbuild +SOURCE_DIR="/var/cache/scratchpkg/sources" +PACKAGE_DIR="/var/cache/scratchpkg/packages" +COMPRESSION_MODE="xz" + +if [ -f "$REPO_FILE" ]; then + for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do + PORT_REPO="$PORT_REPO $repodir" + done +fi + +if [ "$(command -v scratch_$mode)" ]; then + scratch_$mode $MAINOPTS +else + print_runhelp_msg +fi + +exit $? diff --git a/scratch b/scratch old mode 100644 new mode 100755 index cd3beab..b512f1a --- a/scratch +++ b/scratch @@ -969,6 +969,29 @@ scratch_search() { msg "No matching package found." fi } +scratch_changelog() { + needarg $@ + arg=$* + for repo in $PORT_REPO; do + #echo $repo/$1 + if [[ -d $repo/$1 ]]; + then + found=1 + if [[ -f $repo/$1/CHANGELOG ]]; + then + cat $repo/$1/CHANGELOG; + else + echo "No Changelog Exists" + fi + break + fi + done + if [ ! "$found" ]; + then + msg "No matching package found" + fi +} + scratch_cache() { needroot "Clear old caches" @@ -1379,6 +1402,7 @@ Options: unlock unlock locked ports trigger [ports] run system trigger search find ports in repo + changelog find changelog in package cat print spkgbuild depends print dependencies dependent print dependent From 69ad8611c2756484211e6764f7302a491b7b1bbc Mon Sep 17 00:00:00 2001 From: Voncloft Date: Tue, 27 Apr 2021 11:33:48 -0400 Subject: [PATCH 07/13] Minor Updates --- scratch-test.save | 1486 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1486 insertions(+) create mode 100755 scratch-test.save diff --git a/scratch-test.save b/scratch-test.save new file mode 100755 index 0000000..4be1d19 --- /dev/null +++ b/scratch-test.save @@ -0,0 +1,1486 @@ +#!/bin/sh +# +# scratchpkg +# +# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +RED='\e[0;31m' +GREEN='\e[0;32m' +YELLOW='\e[0;33m' +CYAN='\e[0;36m' +PURPLE='\e[0;35m' +CRESET='\e[0m' + +nocolor() { + RED= + GREEN= + YELLOW= + CYAN= + PURPLE= + CRESET= +} + +msg() { + printf "${GREEN}==>${CRESET} %s\n" "$1" +} + +msginst() { + printf "[${GREEN}i${CRESET}] %s\n" "$1" +} + +msgmiss() { + printf "[${YELLOW}m${CRESET}] %s\n" "$1" +} + +msgnoinst() { + printf "[-] %s\n" "$1" +} + +msgerr() { + printf "${RED}==> ERROR:${CRESET} %s\n" "$1" >&2 +} + +msgwarn() { + printf "${YELLOW}==> WARNING:${CRESET} %s\n" "$1" >&2 +} + +needroot() { + if [ "$(id -u)" != 0 ]; then + if [ "$#" -eq 0 ]; then + needroot "This operation" + else + msgerr "$* need root access!" + fi + exit 1 + fi +} + +getportpath() { + for repo in $PORT_REPO; do + if [ -f "$repo/$1/$BUILD_SCRIPT" ]; then + dirname "$repo/$1/$BUILD_SCRIPT" + return 0 + fi + done + return 1 +} + +vercomp() { + if [ "$1" = "$2" ]; then + return 0 # same version + #elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then + elif [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then + return 1 # $1 lower than $2 + #echo "1" + else + return 2 # $1 higher than $2 + #echo "2" + fi +} + +installed_pkg_info() { + if isinstalled $2; then + grep ^$1 $PKGDB_DIR/$2/.pkginfo 2>/dev/null | cut -d " " -f3- + fi +} + +allinstalled() { + grep ^name "$PKGDB_DIR"/*/.pkginfo 2>/dev/null | awk '{print $3}' +} + +deps_alias() { + [ -f "$ALIAS_FILE" ] || { + echo $@ + return + } + while [ "$1" ]; do + if [ "$(grep -w ^$1 $ALIAS_FILE)" ]; then + getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}') + [ "$getalias" ] && echo "$getalias" + else + echo "$1" + fi + shift + unset getalias + done +} + +get_depends() { + ppath=$(getportpath $1) || return 0 + deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ + | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ + | tr ' ' '\n' \ + | awk '!a[$0]++' \ + | sed 's/,//') + deps_alias $deps +} + +confirm() { + printf "$1 (Y/n) " + read -r response + case "$response" in + [Nn][Oo]|[Nn]) echo "$2"; return 2 ;; + *) : ;; + esac + return 0 +} + +checktool() { + if ! command -v $1 >/dev/null; then + msgerr "'$1' not exist in your system!" + exit 1 + fi +} + +needarg() { + [ "$*" ] || { + msgerr "This operation required an arguments!" + exit 1 + } +} + +isinstalled() { + if [ -s "$PKGDB_DIR/$1/.pkginfo" ] && [ "$(grep $1 $PKGDB_DIR/$1/.pkginfo)" ]; then + return 0 + else + return 1 + fi +} + +settermtitle() { + printf "\033]0;$*\a" +} + +scratch_integrity() { + if [ "$1" ]; then + cd / + if [ -f $PKGDB_DIR/$1/.files ]; then + cat $PKGDB_DIR/$1/.files | while read -r line; do + if [ ! -e "$line" ]; then + if [ -L "$line" ]; then + printf "${YELLOW}broken symlink${CRESET} $1: /$line" + else + printf "${RED}file missing${CRESET} $1: /$line" + fi + fi + done + else + echo "Package '$1' not installed." + exit 1 + fi + cd - >/dev/null + else + cd / + for pkg in $(allinstalled); do + cat $PKGDB_DIR/$pkg/.files | while read -r line; do + if [ ! -e "$line" ]; then + if [ -L "$line" ]; then + echo "broken symlink $pkg: /$line" + else + echo "missing file $pkg: /$line" + fi + fi + done + done + cd - >/dev/null + 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 + grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' | column -t + 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 + if depend=$(get_depends $pkg); then + for dep in $depend; do + if [ $dep = $1 ]; then + return 1 + fi + done + fi + unset depend dep + done + return 0 +} + +scratch_sync() { + checktool httpup + needroot "Updating ports" + + if [ ! -e "$REPO_FILE" ]; then + msgerr "Repo file not found! ($REPO_FILE)" + exit 1 + fi + + grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do + if [ "$repodir" ] && [ "$repourl" ]; then + httpup sync $repourl $repodir || { + msgerr "Failed sync from $repourl" + exit 1 + } + fi + done +} + +scratch_trigger() { + needroot "Run trigger" + if [ -z "$*" ]; then + for i in $(seq 12); do + eval trig_$i=1 + done + else + pre_triggers $@ + fi + post_triggers +} + +post_triggers() { + if [ "$trig_12" = 1 ]; then + echo "trigger: Running mkdirs..." + for mkd in $PKGDB_DIR/*/.pkgmkdirs; do + [ -s $mkd ] || continue + grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do + if [ -e "$dir" ]; then + if [ "$uid" != '-' ]; then + getent passwd $uid >/dev/null && chown "$uid" "$dir" + fi + if [ "$gid" != '-' ]; then + getent group $gid >/dev/null && chgrp "$gid" "$dir" + fi + if [ "$mode" != '-' ]; then + chmod "$mode" "$dir" + fi + fi + done + done + fi + + if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then + echo "trigger: Updating fontconfig cache..." + fc-cache -s + fi + + 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 ] && [ $(command -v gio-querymodules) ]; then + echo "trigger: Updating GIO module cache..." + gio-querymodules /usr/lib/gio/modules + fi + + 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 ] && [ $(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 ] && [ $(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 ] && [ $(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 + gtk-update-icon-cache -q $dir 2>/dev/null + else + rm -f $dir/icon-theme.cache + rmdir --ignore-fail-on-non-empty $dir + fi + done + fi + + if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then + echo "trigger: Updating hardware database..." + udevadm hwdb --update + fi + + 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 \)); do + rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid + rmdir --ignore-fail-on-non-empty $dir + [ -d "$dir" ] || continue + mkfontdir $dir + mkfontscale $dir + done + fi + + 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 ] && [ $(command -v update-mime-database) ]; then + echo "trigger: Updating the MIME type database..." + update-mime-database /usr/share/mime + fi +} + +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 + trig_1=1 + break + fi + done + fi + + # 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 + trig_2=1 + break + fi + done + fi + + # 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 + trig_3=1 + break + fi + done + fi + + # 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 + trig_4=1 + break + fi + done + fi + + # 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 + trig_5=1 + break + fi + done + fi + + # 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 + trig_6=1 + break + fi + done + fi + + # 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 + trig_7=1 + break + fi + done + fi + + # 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 + trig_8=1 + break + fi + done + fi + + # 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 + trig_9=1 + break + fi + done + fi + + # 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 + trig_10=1 + break + fi + done + fi + + # 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 + trig_11=1 + break + fi + done + fi + + # makedirs + if [ "$trig_12" != "1" ]; then + for pkg in $@; do + if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then + trig_12=1 + break + fi + done + fi +} + +scratch_build() { + while [ "$1" ]; do + case $1 in + -i|-u|-r|-g|-p) ;; + --log) LOG=1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to build." + return 1 + } + for pkg in $PKGNAME; do + ppath=$(getportpath $pkg) || { + echo "Package '$pkg' not found." + return 1 + } + cd $ppath + settermtitle "Building $pkg..." + if [ "$LOG" ]; then + pkgbuild $OPTS | tee /var/log/pkgbuild.log || { + settermtitle "Building $pkg failed." + return 1 + } + else + pkgbuild $OPTS || { + settermtitle "Building $pkg failed." + return 1 + } + fi + settermtitle "Building $pkg done." + cd - >/dev/null + done +} + +scratch_install() { + needroot "Installing package" + while [ "$1" ]; do + case $1 in + -i|-u) ;; + -r|--reinstall) REINSTALL=1;; + -y|--yes) NOCONFIRM=1;; + -n|--no-dep) NO_DEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to install." + return 1 + } + # if reinstall, dont calculate dep, just reinstall it then exit + if [ "$REINSTALL" = 1 ]; then + error=0 + for ii in $PKGNAME; do + if [ ! $(getportpath $ii) ]; then + echo "Package '$ii' not found." + elif ! isinstalled $ii; then + echo "Package '$ii' not installed." + else + cd $(getportpath $ii) + settermtitle "Reinstalling $ii..." + pkgbuild $OPTS -r || { + error=1 + break + } + done_pkg="$done_pkg $ii" + cd - >/dev/null + fi + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Reinstalling done." + return "$error" + fi + if [ "$NO_DEP" = 1 ]; then + error=0 + for ii in $PKGNAME; do + if [ ! $(getportpath $ii) ]; then + echo "Package '$ii' not found." + elif isinstalled $ii; then + echo "Package '$ii' already installed." + continue + else + cd $(getportpath $ii) + settermtitle "Installing $ii..." + pkgbuild -i $OPTS || { + error=1 + break + } + done_pkg="$done_pkg $ii" + cd - >/dev/null + fi + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "Installing done." + return "$error" + fi + for i in $PKGNAME; do + if [ ! $(getportpath $i) ]; then + echo "Package '$i' not found." + elif isinstalled $i; then + echo "Package '$i' already installed." + else + IPKG="$IPKG $i" + fi + done + [ "$IPKG" ] || return 0 + echo "Resolving dependencies..." + INST="$(scratch_deplist -q $IPKG $EXOPT)" + if [ "$INST" ]; then + echo + pkgcount=0 + for pkg in $INST; do + pkgcount=$(( pkgcount + 1 )) + printf "[${GREEN}i${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount install )" + echo + if [ ! "$NOCONFIRM" ]; then + confirm "Continue install package(s)?" "Package installation cancelled." || exit $? + echo + fi + error=0 + count=0 + total=$(echo $INST | wc -w) + for int in $INST; do + count=$(( count + 1 )) + if portpathh=$(getportpath $int); then + cd $portpathh + settermtitle "[ $count/$total ] installing $int..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + done_pkg="$done_pkg $int" + cd - >/dev/null + else + msgwarn "Skipping missing package: $int" + fi + unset portpathh + done + settermtitle "Triggering install hook..." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) installed." + return "$error" + fi +} + +scratch_remove() { + needroot "Removing package" + while [ "$1" ]; do + case $1 in + -y|--yes) NOCONFIRM=1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to remove." + return 1 + } + for i in $PKGNAME; do + if ! isinstalled $i; then + echo "Package '$i' not installed." + else + IPKG="$IPKG $i" + fi + done + [ "$IPKG" ] || return 0 + echo "Removing packages..." + echo + pkgcount=0 + count=0 + for pkg in $IPKG; do + pkgcount=$(( pkgcount + 1 )) + printf "[${RED}x${CRESET}] $pkg " + done + echo; echo + echo "( $pkgcount remove )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue remove package(s)?" "Package removing cancelled." || exit $? + echo + } + for pkg in $IPKG; do + count=$(( count + 1 )) + pre_triggers $pkg + settermtitle "[ $count/$pkgcount ] Removing $pkg..." + pkgdel $pkg $OPTS || { + error=1 + break + } + done + settermtitle "Triggering remove hook..." + post_triggers + settermtitle "$pkgcount package(s) removed." +} + +outdatepkg() { + for pkg in $(allinstalled); do + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep -w $pkg) ]; then + continue + fi + [ -e "$PKGDB_DIR/$pkg/.lock" ] && continue + getportpath $pkg >/dev/null || continue + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then + echo $name + fi + unset iversion irelease version release + done +} + +scratch_sysup() { + needroot "Upgrading package" + while [ "$1" ]; do + case $1 in + -i|-u|-r) ;; + -y|--yes) NOCONFIRM=1;; + -n|--no-dep) NODEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + esac + shift + done + echo "Checking for outdated packages..." + PKGOUTDATE=$(outdatepkg) + [ "$PKGOUTDATE" ] || { + echo "All packages are up to date." + return 0 + } + [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x scratchpkg)" ] && { + echo + msgerr "Please upgrade 'scratchpkg' first." + return 1 + } + UPGPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then + echo "Resolving dependencies..." + DEP=$(scratch_deplist $PKGOUTDATE $EXOPT | awk '{print $2}') + echo + for d in $DEP; do + if [ "$(echo $PKGOUTDATE | 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 + else + echo + for dd in $PKGOUTDATE; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" + UPGPKG=$(( UPGPKG + 1 )) + done + fi + echo; echo + echo "( $UPGPKG upgrade, $NEWPKG new install )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + echo + } + error=0 + 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 $inst) + if ! isinstalled $inst; then + settermtitle "[ $count/$total ] Installing $inst..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + else + settermtitle "[ $count/$total ] Upgrading $inst..." + pkgbuild -u $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + fi + cd - >/dev/null + done_pkg="$done_pkg $inst" + done + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" +} + +scratch_upgrade() { + needroot "Upgrading package" + while [ "$1" ]; do + case $1 in + -i|-r) ;; + -y|--yes) NOCONFIRM=1;; + -d|--no-dep) NO_DEP=1;; + --exclude=*) EXOPT=$1;; + -*) OPTS="$OPTS $1";; + *) PKGNAME="$PKGNAME $1";; + esac + shift + done + [ "$PKGNAME" ] || { + echo "Please specify package(s) to upgrade." + return 1 + } + for pkg in $PKGNAME; do + if ! isinstalled $pkg; then + echo "Package '$pkg' not installed." + continue + elif [ ! $(getportpath $pkg) ]; then + 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 + echo "Package '$pkg' is up to date." + continue + fi + fi + upkg="$upkg $pkg" + done + [ "$upkg" ] || return 0 + + UPGPKG=0 + NEWPKG=0 + if [ "$NODEP" != 1 ]; then + echo "Resolving dependencies..." + DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') + 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 + else + echo + for dd in $upkg; do + printf "[${GREEN}u${CRESET}] $dd " + WILLINSTALL="$WILLINSTALL $dd" + UPGPKG=$(( UPGPKG + 1 )) + done + fi + echo; echo + echo "( $UPGPKG upgrade, $NEWPKG new install )" + echo + [ "$NOCONFIRM" ] || { + confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? + echo + } + error=0 + 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 $inst) + if ! isinstalled $inst; then + settermtitle "[ $count/$total ] Installing $inst..." + pkgbuild -i $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + else + settermtitle "[ $count/$total ] Upgrading $inst..." + pkgbuild -u $OPTS || { + error=1 + count=$(( count - 1 )) + break + } + fi + cd - >/dev/null + done_pkg="$done_pkg $inst" + done + settermtitle "Triggering install hook." + [ "$done_pkg" ] && scratch_trigger $done_pkg + settermtitle "$count/$total package(s) upgraded." + return "$error" +} + +scratch_outdate() { + for pkg in $(allinstalled); do + if [ "$(getportpath $pkg)" ]; then + . $(getportpath $pkg)/$BUILD_SCRIPT + if [ -z "$name" ] || [ -z "$version" ]; then + continue + fi + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" + if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then + ITSLOCK="[masked]" + fi + #outdatemsg="$name $iversion-$irelease => $version-$release $ITSLOCK" + #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" + outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" + newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" + if [ "$version" != "$iversion" ]; then + vercomp $version $iversion + if [ $? = 2 ]; then + echo -e "$outdatemsg" + OUTDATE=yes + elif [ $? = 1 ]; then + echo -e "$newerinstmsg" + OUTDATE=yes + fi + elif [ "$release" != "$irelease" ]; then + vercomp $release $irelease + if [ $? = 2 ]; then + echo -e "$outdatemsg" + OUTDATE=yes + elif [ $? = 1 ]; then + echo -e "$newerinstmsg" + OUTDATE=yes + fi + fi + unset ITSLOCK name version + fi + done + + [ ! "$OUTDATE" ] && msg "All packages are up to date." +} + +scratch_search() { + needarg $@ + arg=$* + for repo in $PORT_REPO; do + [ -d $repo ] || continue + out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}' | sort) + [ "$out" ] || continue + found=1 + for line in $out; do + repo=$(echo $line | rev | awk -F / '{print $3}' | rev) + desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') + . $line + if isinstalled $name; then + ins="[${GREEN}*${CRESET}]" + else + ins="[ ]" + fi + printf "$ins ${PURPLE}($repo)${CRESET} $name ${CYAN}$version-$release${CRESET}: $desc\n" + unset repo desc name version release build + done + unset out + done + if [ ! "$found" ]; then + msg "No matching package found." + fi +} +scratch_changelog() { + needarg $@ + echo $PORT_REPO $! + if PPATH=$($PORT_REPO "$1"); then + if [ -f "$PPATH/CHANGELOG" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + + +scratch_cache() { + needroot "Clear old caches" + + allcachepkg=/tmp/.allcachepkg.$$ + allcachesrc=/tmp/.allcachesrc.$$ + keepcachepkg=/tmp/.keepcachepkg.$$ + keepcachesrc=/tmp/.keepcachesrc.$$ + diffcachepkg=/tmp/.diffcachepkg.$$ + diffcachesrc=/tmp/.diffcachesrc.$$ + + [ -f /etc/scratchpkg.conf ] && . /etc/scratchpkg.conf + + touch \ + $allcachepkg \ + $allcachesrc \ + $keepcachepkg \ + $keepcachesrc \ + $diffcachepkg \ + $diffcachesrc + + if [ "$(find $PACKAGE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$PACKAGE_DIR"/*; do + basename $list >> "$allcachepkg" + done + fi + + if [ "$(find $SOURCE_DIR -mindepth 1 -print -quit 2>/dev/null)" ]; then + for list in "$SOURCE_DIR"/*; do + basename $list >> "$allcachesrc" + done + fi + + for repo in $PORT_REPO; do + if [ "$(find $repo/*/ -mindepth 1 -print -quit 2>/dev/null)" ]; then # check directory if its not empty + for port in $repo/*/$BUILD_SCRIPT; do + . $port + echo "$name-$version-$release.spkg.tar.$COMPRESSION_MODE" >> "$keepcachepkg" + if [ "$source" ]; then + for src in $source; do + if echo $src | grep -Eq "(ftp|http|https)://"; then + if echo $src | grep -Eq "::(ftp|http|https)://"; then + sourcename="$(echo $src | awk -F '::' '{print $1}')" + else + sourcename="$(echo $src | rev | cut -d / -f 1 | rev)" + fi + echo $sourcename >> "$keepcachesrc" + fi + done + fi + done + fi + done + grep -Fxv -f "$keepcachepkg" "$allcachepkg" > "$diffcachepkg" + grep -Fxv -f "$keepcachesrc" "$allcachesrc" > "$diffcachesrc" + + cat $diffcachepkg + cat $diffcachesrc + + if [ -s "$diffcachepkg" ]; then + cd "$PACKAGE_DIR" + sizepkg=$(du -ch $(cat $diffcachepkg) | grep total | awk '{print $1}') + cd - >/dev/null + else + sizepkg=0M + fi + + if [ -s "$diffcachesrc" ]; then + cd "$SOURCE_DIR" + sizesrc=$(du -ch $(cat $diffcachesrc) | grep total | awk '{print $1}') + cd - >/dev/null + else + sizesrc=0M + fi + + echo "Total package cache size: $sizepkg" + echo "Total source cache size : $sizesrc" + + if [ -s "$diffcachepkg" ] || [ -s "$diffcachesrc" ]; then + echo + confirm "Clear old caches?" "Old caches is kept." && { + for i in $(cat $diffcachepkg); do + [ -e "$PACKAGE_DIR/$i" ] && rm -v "$PACKAGE_DIR/$i" + done + for i in $(cat $diffcachesrc); do + [ -e "$SOURCE_DIR/$i" ] && rm -v "$SOURCE_DIR/$i" + done + } + fi + + rm -f \ + "$allcachepkg" \ + "$allcachesrc" \ + "$keepcachepkg" \ + "$keepcachesrc" \ + "$diffcachepkg" \ + "$diffcachesrc" +} + +scratch_deplist() { + OLDIFS=$IFS + IFS=, + while [ "$1" ]; do + case $1 in + -q|--quick) quick=1;; + --exclude=*) for i in ${1#*=}; do exclude="$exclude $i"; done;; + -*) ;; + *) PKG="$PKG $1";; + esac + shift + done + IFS=$OLDIFS + [ "$PKG" ] || { + echo "Please specify package(s) to list dependencies." + return 1 + } + for p in $PKG; do + if [ "$(getportpath $p)" ]; then + PPKG="$PPKG $p" + else + [ "$quick" = 1 ] || msgerr "Package '$p' not exist." + fi + done + + for p in $PPKG; do + deplist $p + done + + [ "$DEP" ] || return 0 + + if [ "$quick" = 1 ]; then + echo $DEP | tr ' ' '\n' + else + for p in $DEP; do + if isinstalled $p; then + echo "[*] $p" + else + echo "[-] $p" + fi + done + if [ "$MISSINGDEP" ]; then + for m in $MISSINGDEP; do + echo "Missing deps: $m" | sed 's/(/ (/' + done + fi + fi +} + +deplist() { + # skip excluded dependencies + if echo $exclude | tr " " "\n" | grep -qx $1; then + return 0 + fi + + # check currently process for circular dependencies + # for circular dependencies, found first will take precedence + [ "$CHECK" ] && { + if echo $CHECK | tr " " "\n" | grep -qx $1; then + return 0 + fi + } + + # add package to currently process + CHECK="$CHECK $1" + + # check dependencies + for i in $(get_depends $1); do + if [ "$quick" = 1 ] && isinstalled $i; then + continue + else + if ! echo $DEP | tr " " "\n" | grep -qx $i; then + if ! getportpath $i >/dev/null; then + MISSINGDEP="$MISSINGDEP $i($1)" + else + deplist $i + fi + fi + fi + done + + # add dependency to list checked dep + if ! echo $DEP | tr " " "\n" | grep -qx $1; then + if [ "$quick" = 1 ]; then + isinstalled $1 || DEP="$DEP $1" + else + DEP="$DEP $1" + fi + fi + + # delete item from loop process + CHECK=$(echo $CHECK | sed "s/$1//") +} + +scratch_cat() { + needarg $@ + if PPATH=$(getportpath "$1"); then + cat "$PPATH/$BUILD_SCRIPT" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_dependent() { + needarg $@ + if [ "$(getportpath $1)" ]; then + grep -R "# depends[[:blank:]]*:" $PORT_REPO \ + | sed "s,:# depends[[:blank:]]*:[[:blank:]]*,#|,;s, ,|,g;s,$,|,g" \ + | grep "|$1|" \ + | awk -F "#" '{print $1}' \ + | rev \ + | awk -F / '{print $2}' \ + | rev + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_depends() { + needarg $@ + if getportpath "$1" >/dev/null; then + depends=$(get_depends $1) + else + msgerr "Port '$1' not exist." + return 1 + fi + + for dep in $depends; do + if isinstalled $dep; then + msginst "$dep" + elif getportpath $dep >/dev/null; then + msgnoinst "$dep" + else + msgmiss "$dep" + fi + done +} + +scratch_dup() { + dup=$(find $PORT_REPO -type d -print | grep -Exv "($(echo $PORT_REPO | tr ' ' '|'))" | \ + rev | cut -d '/' -f1 | rev | sort | uniq -d) + + if [ "$dup" ]; then + for dp in $dup; do + for repo in $PORT_REPO; do + [ -d $repo/$dp ] && echo "$repo/$dp" + done + done + else + msg "No duplicate ports found." + fi +} + +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" + fi + unset iname iversion irelease + done +} + +scratch_info() { + needarg $@ + ppath=$(getportpath $1) || return 1 + + . $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:]]*//') + deps=$(get_depends $1 | tr '\n' ' ') + + echo "Name: $1" + echo "Path: $ppath" + echo "Version: $version" + echo "Release: $release" + echo "Description: $desc" + echo "Maintainer: $maint" + echo "Dependencies: $deps" +} + +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 + done +} + +scratch_missingdep() { + for pkg in $(allinstalled); do + if getportpath "$pkg" >/dev/null; then + depends=$(get_depends $pkg) + fi + if [ "$depends" ]; then + for d in $depends; do + if ! isinstalled $d; then + if [ -z "$msd" ]; then + msd="$d" + else + msd="$msd $d" + fi + fi + done + fi + [ "$msd" ] && echo "$pkg: $msd" + unset depends msd + done +} + +scratch_locked() { + for pkg in $(allinstalled); do + [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" + done +} + +scratch_orphan() { + tmpallpkg="/tmp/.pkgquery_allpkg.$$" + tmpalldep="/tmp/.pkgquery_alldep.$$" + for pkg in $(allinstalled); do + echo $pkg >> $tmpallpkg + dep="$dep $(get_depends $pkg)" + done + echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep" + grep -xvF -f "$tmpalldep" "$tmpallpkg" + rm "$tmpalldep" "$tmpallpkg" +} + +scratch_path() { + needarg $@ + if PPATH=$(getportpath "$1"); then + echo "$PPATH" + else + msgerr "Port '$1' not exist." + return 1 + fi +} + +scratch_provide() { + needarg $@ + arg=$(echo $1 | sed "s/^\///") + grep -R "$arg" $PKGDB_DIR/*/.files \ + | sed "s:$PKGDB_DIR/::" \ + | sed "s:/.files::" \ + | tr : " " \ + | column -t +} + +scratch_readme() { + needarg $@ + if PPATH=$(getportpath "$1"); then + if [ -f "$PPATH/readme" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." + exit 1 + fi +} + +scratch_files() { + needarg $@ + if isinstalled $1; then + cat "$PKGDB_DIR/$1/.files" + else + msg "Package '$1' not installed." + fi +} + +scratch_help() { + cat << EOF +Usage: + $(basename $0) [] + +Options: + install install ports (use pkgbuild arg, except '-i' & '-u') + -r|--reinstall reinstall + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + upgrade upgrade ports (use pkgbuild arg, except '-i' & '-r') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + remove remove installed ports (use pkgdel arg) + -y|--yes skip ask user permission + + sysup full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u') + -n|--no-dep skip dependencies + -y|--yes skip ask user permission + --exclude=* exclude dependencies, comma separated + + deplist print all dependencies for ports + -q|--quick skip installed ports + --exclude=* exclude dependencies, comma separated + + build build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') + --log log build process (/var/log/pkgbuild.log) + + lock locking ports prevent upgrade + unlock unlock locked ports + trigger [ports] run system trigger + search find ports in repo + cat print spkgbuild + depends print dependencies + dependent print dependent + path print path in repo + provide print port's provided files + readme print readme file, if exist + files print files installed + info print information + locate print location of files in ports repo + sync update ports database + outdate print outdated ports + cache print and clear old pkg and src caches + 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 + help print this help msg + +Global options: + --append-repo= append custom repo path + --prepend-repo= prepend custom repo path + --repo-file= use custom repo file (default: $REPO_FILE) + --nocolor disable colour for output + +EOF +} + +print_runhelp_msg() { + echo "Run '$(basename $0) help' to see available options." + exit 2 +} + +# check for 'pkgadd', required for package database path +command -v pkgadd >/dev/null 2>&1 || { + echo "'pkgadd' not found in \$PATH!" + exit 1 +} + +mode=$1 + +[ "$mode" ] || { + print_runhelp_msg +} + +shift + +for opt in $@; do + case $opt in + --nocolor) nocolor;; + --repo=*) PORT_REPO="$PORT_REPO ${opt#*=}";; + --repo-file=*) REPO_FILE="${opt#*=}";; + --alias-file=*) ALIAS_FILE="${opt#*=}";; + --*) MAINOPTS="$MAINOPTS $opt";; + -*) char=${#opt}; count=1 + while [ "$count" != "$char" ]; do + count=$((count+1)) + MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)" + done;; + *) MAINOPTS="$MAINOPTS $opt";; + esac + shift +done + +BUILD_SCRIPT="spkgbuild" +PKGDB_DIR="$(pkgadd --print-dbdir)" +REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" +ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" +MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" + +# default value from pkgbuild +SOURCE_DIR="/var/cache/scratchpkg/sources" +PACKAGE_DIR="/var/cache/scratchpkg/packages" +COMPRESSION_MODE="xz" + +if [ -f "$REPO_FILE" ]; then + for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do + PORT_REPO="$PORT_REPO $repodir" + done +fi + +if [ "$(command -v scratch_$mode)" ]; then + scratch_$mode $MAINOPTS +else + print_runhelp_msg +fi + +exit $? From 9eab2b34c9a7640a3e9f9417ba853eaa35d5bd01 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Wed, 28 Apr 2021 19:28:29 -0400 Subject: [PATCH 08/13] Minor Updates --- scratchpkg.repo | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/scratchpkg.repo b/scratchpkg.repo index 4be77ea..1d2b881 100644 --- a/scratchpkg.repo +++ b/scratchpkg.repo @@ -4,7 +4,45 @@ # format: # # -# example: -# /usr/ports/core https://raw.githubusercontent.com/emmett1/ports/master/core -# /usr/ports/localports -# \ No newline at end of file + +#Core +/usr/Voncloft-OS/core https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/core +/usr/Voncloft-OS/hardware https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/hardware +#/usr/Voncloft-OS/multilib https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/multilib + +#DE +/usr/Voncloft-OS/cinnamon https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/cinnamon +/usr/Voncloft-OS/displaym https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/displaym +/usr/Voncloft-OS/kde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde +/usr/Voncloft-OS/kf5 https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kf5 +/usr/Voncloft-OS/lxde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/lxde +/usr/Voncloft-OS/mate https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/mate +/usr/Voncloft-OS/plasma https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/plasma +/usr/Voncloft-OS/qt https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/qt +/usr/Voncloft-OS/xfce https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xfce +/usr/Voncloft-OS/xorg https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xorg + + +#Programming +/usr/Voncloft-OS/compilers https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/compilers +/usr/Voncloft-OS/libs https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/libs +/usr/Voncloft-OS/perl https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/perl +/usr/Voncloft-OS/python https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/python +/usr/Voncloft-OS/ruby-gems https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/ruby-gems + +#Router +/usr/Voncloft-OS/boot-scripts-server https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/boot-scripts-server +/usr/Voncloft-OS/firewall https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/firewall +/usr/Voncloft-OS/networking https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/networking +/usr/Voncloft-OS/server https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/server + +#Programs +/usr/Voncloft-OS/extra https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/extra +/usr/Voncloft-OS/fonts https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/fonts +/usr/Voncloft-OS/kde-apps https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde-apps +/usr/Voncloft-OS/media https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/media +/usr/Voncloft-OS/nonfree https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/nonfree + +#Personal and misc +/usr/Voncloft-OS/personal-repository http://voncloft.dnsfor.me/software/Voncloft-OS/programs +/usr/Voncloft-OS/working_on/extra-working_on https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/working_on/sort_later From b66991a51c0e1476a5c8ab5194ba4ccd1888ae02 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Wed, 28 Apr 2021 20:08:12 -0400 Subject: [PATCH 09/13] Minor Updates --- scratchpkg.repo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scratchpkg.repo b/scratchpkg.repo index 1d2b881..559b88f 100644 --- a/scratchpkg.repo +++ b/scratchpkg.repo @@ -42,7 +42,3 @@ /usr/Voncloft-OS/kde-apps https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde-apps /usr/Voncloft-OS/media https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/media /usr/Voncloft-OS/nonfree https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/nonfree - -#Personal and misc -/usr/Voncloft-OS/personal-repository http://voncloft.dnsfor.me/software/Voncloft-OS/programs -/usr/Voncloft-OS/working_on/extra-working_on https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/working_on/sort_later From c8e821cbfdb67b3d29f9f8d742342dd5dbcc7e03 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Tue, 25 May 2021 12:16:14 -0400 Subject: [PATCH 10/13] Minor Updates --- scratchpkg.repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scratchpkg.repo b/scratchpkg.repo index 559b88f..efbf10c 100644 --- a/scratchpkg.repo +++ b/scratchpkg.repo @@ -13,6 +13,7 @@ #DE /usr/Voncloft-OS/cinnamon https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/cinnamon /usr/Voncloft-OS/displaym https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/displaym +/usr/Voncloft-OS/gnome https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/gnome /usr/Voncloft-OS/kde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde /usr/Voncloft-OS/kf5 https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kf5 /usr/Voncloft-OS/lxde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/lxde @@ -22,7 +23,6 @@ /usr/Voncloft-OS/xfce https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xfce /usr/Voncloft-OS/xorg https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xorg - #Programming /usr/Voncloft-OS/compilers https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/compilers /usr/Voncloft-OS/libs https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/libs From 393ebdf0c3bd23e0adceefcbdf55be0fb56a39ad Mon Sep 17 00:00:00 2001 From: Voncloft Date: Tue, 25 May 2021 12:23:09 -0400 Subject: [PATCH 11/13] Minor Updates --- INSTALL.sh | 4 +- pkgadd | 107 ++++-------- pkgbuild | 442 ++++++++++++++++++------------------------------ pkgdel | 78 ++------- pkgfix | 15 +- portcreate | 2 +- portsync | 137 +++++++++++++++ revdep | 13 +- scratch | 257 ++++++++++++++-------------- scratchpkg.conf | 31 +--- scratchpkg.mask | 9 +- scratchpkg.repo | 5 +- 12 files changed, 506 insertions(+), 594 deletions(-) create mode 100755 portsync diff --git a/INSTALL.sh b/INSTALL.sh index 92d273e..6831908 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -16,8 +16,8 @@ install -dm777 ${DESTDIR}${CACHE_DIR}/packages install -dm777 ${DESTDIR}${CACHE_DIR}/sources install -dm777 ${DESTDIR}${CACHE_DIR}/work -install -m755 xchroot revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf \ +install -m755 xchroot revdep pkgadd pkgdel pkgbuild scratch updateconf portsync \ pkgbase pkgdepends pkgrebuild pkgfix portcreate ${DESTDIR}${BINDIR} -install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias ${DESTDIR}${CONFDIR} +install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias scratchpkg.mask ${DESTDIR}${CONFDIR} install -m644 revdep.conf ${DESTDIR}${REVDEPCONF} diff --git a/pkgadd b/pkgadd index 8e8c898..7823f4a 100755 --- a/pkgadd +++ b/pkgadd @@ -114,7 +114,7 @@ ret() { } isinstalled() { - if [ -s "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo"; then + if [ -s "$ROOT_DIR/$PKGDB_DIR/$1" ]; then return 0 else return 1 @@ -132,7 +132,8 @@ run_scripts() { parse_opts $(extract_opts "$@") SCRATCHPKG_DIR="var/lib/scratchpkg" -PKGDB_DIR="$SCRATCHPKG_DIR/index" +PKGDB_DIR="$SCRATCHPKG_DIR/db" +PKGDBPERMS_DIR="$PKGDB_DIR.perms" LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock" ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash @@ -149,25 +150,25 @@ ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash } [ -d "$ROOT_DIR/$PKGDB_DIR" ] || { - msgerr "Package's database directory not exist: $ROOT_DIR/$PKGDB_DIR" + msgerr "Package's database directory does not exist: $ROOT_DIR/$PKGDB_DIR" ret 1 } # check for root access [ "$(id -u)" = "0" ] || { - msgerr "Installing package need root access!" + msgerr "Installing packages requires root access!" ret 1 } # check for lock file [ -f "$ROOT_DIR/$LOCK_FILE" ] && { - msgerr "Cant install/remove package simultaneously." + msgerr "Cannot 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 || { - msgerr "Cant create lock file in '$ROOT_DIR/$LOCK_FILE'." + msgerr "Cannot create lock file in '$ROOT_DIR/$LOCK_FILE'." exit 1 } @@ -175,7 +176,7 @@ BASEPKGNAME=$(basename $PKGNAME) # check existence of package file [ -f "$PKGNAME" ] || { - msgerr "Package '$1' not exist!" + msgerr "Package '$1' does not exist!" ret 1 } @@ -187,8 +188,8 @@ name=${noextname%-*} # get package information if installed if isinstalled $name; then - iversion=$(grep ^version $ROOT_DIR/$PKGDB_DIR/$name/.pkginfo | cut -d " " -f3-) - irelease=$(grep ^release $ROOT_DIR/$PKGDB_DIR/$name/.pkginfo | cut -d " " -f3-) + iversion=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $1}') + irelease=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $2}') ALREADYINSTALLED=yes fi @@ -216,7 +217,7 @@ TMP_PKGINSTALL="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkginstall" TMP_CONFLICT="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_conflict" # check integrity of package and save list file/dirs to install in the meantime -tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || { +tar -tvf $PKGNAME > $TMP_PKGADD 2>/dev/null || { msgerr "Package '$1' is corrupted!" ret 1 } @@ -230,13 +231,13 @@ echo "$opr: $name-$version-$release..." # check for file conflict if [ ! "$IGNORE_CONFLICT" ]; then - grep -Ev "^.pkg*" "$TMP_PKGADD" | grep -v '/$' | while read -r line; do + grep -v '/$' "$TMP_PKGADD" | awk '{print $6}' | while read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then line=${line%.*} fi if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - if ! grep -Fqx "$line" "$ROOT_DIR/$PKGDB_DIR/$name/.files"; then + if ! grep -Fqx "$line" "$ROOT_DIR/$PKGDB_DIR/$name"; then echo "$line" touch "$TMP_CONFLICT" fi @@ -253,32 +254,10 @@ if [ ! "$IGNORE_CONFLICT" ]; then fi fi -# pre-install and pre-upgrade script -if grep -qx .pkginstall $TMP_PKGADD; then - TMP_PKGINSTALL_SCRIPT="$SCRATCHPKG_DIR/pkgadd_installscript" - tar -xf "$PKGNAME" .pkginstall -O > "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT" - if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-install "$version" - ) - fi - if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion" - ) - fi - rm -f "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT" -fi - -# exclude .pkg* files when extract into system -for i in $(grep "^.pkg*" $TMP_PKGADD); do - excludefile="$excludefile --exclude=$i" -done - rm -f $TMP_PKGINSTALL # extract package into ROOT_DIR -tar --keep-directory-symlink -p -x -v -f "$PKGNAME" -C "$ROOT_DIR"/ $excludefile | while read -r line; do +tar -xvhpf "$PKGNAME" -C "$ROOT_DIR"/ | while read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then line=${line%.*} if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then @@ -295,53 +274,25 @@ done # remove old files from old package that not exist in new package if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - rmlist_file="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_file" - rmlist_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_dir" - reserve_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.reserve_dir" - rmlist_all="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_all" - grep '/$' $ROOT_DIR/$PKGDB_DIR/*/.files \ - | grep -v $ROOT_DIR/$PKGDB_DIR/$name/.files \ - | awk -F : '{print $2}' \ - | sort \ - | uniq > $reserve_dir # get list reserved dirs - grep -Fxv -f "$TMP_PKGINSTALL" $ROOT_DIR/$PKGDB_DIR/$name/.files > $rmlist_all # get list files and dirs to remove - grep -v '/$' "$rmlist_all" | tac > "$rmlist_file" # get files only to remove - grep -Fxv -f "$reserve_dir" "$rmlist_all" | grep '/$' | tac > "$rmlist_dir" # get dirs only (safe) to remove - (cd "$ROOT_DIR"/ - [ -s $rmlist_file ] && xargs -a $rmlist_file -d'\n' rm $VERBOSE_INSTALL - [ -s $rmlist_dir ] && xargs -a $rmlist_dir -d'\n' rmdir $VERBOSE_INSTALL - ) - rm -f "$rmlist_file" "$rmlist_dir" "$reserve_dir" "$rmlist_all" + tail -n+2 "$ROOT_DIR/$PKGDB_DIR/$name" | tac | while read -r line; do + case $line in + */) grep "^$line$" $ROOT_DIR/$PKGDB_DIR/* "$TMP_PKGINSTALL" 2>/dev/null | grep -qv "$ROOT_DIR/$PKGDB_DIR/$name" || rmdir $([ "$VERBOSE_INSTALL" ] && echo -v) "$ROOT_DIR/$line";; + *) grep -q "^$line$" "$TMP_PKGINSTALL" || rm $([ "$VERBOSE_INSTALL" ] && echo -v) "$ROOT_DIR/$line";; + esac + done fi # register package into database -rm -fr "$ROOT_DIR/$PKGDB_DIR/$name" -mkdir "$ROOT_DIR/$PKGDB_DIR/$name" -echo "name = $name" > "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo" -echo "version = $version" >> "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo" -echo "release = $release" >> "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo" -install -m644 "$TMP_PKGINSTALL" "$ROOT_DIR/$PKGDB_DIR/$name/.files" - -for ii in $(grep ^.pkg* $TMP_PKGADD); do - pkgfiles="$pkgfiles $ii" -done - -if [ "$pkgfiles" ]; then - tar -x -f "$PKGNAME" -C "$ROOT_DIR/$PKGDB_DIR/$name" $pkgfiles >/dev/null 2>&1 -fi - -if [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then - if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$PKGDB_DIR/$name/.pkginstall" post-install "$version" - ) +echo "$version $release" > "$ROOT_DIR/$PKGDB_DIR/$name" +cat "$TMP_PKGINSTALL" >> "$ROOT_DIR/$PKGDB_DIR/$name" +mkdir -p "$ROOT_DIR/$PKGDBPERMS_DIR" +rm -f "$ROOT_DIR/$PKGDBPERMS_DIR/$name" +grep '/$' $TMP_PKGADD | while read -r perms own junk1 junk2 junk3 dir; do + if [ "$perms" != drwxr-xr-x ] || [ "$own" != root/root ]; then + echo "$perms $own $dir" >> "$ROOT_DIR/$PKGDBPERMS_DIR/$name" + [ -s "$ROOT_DIR/$PKGDBPERMS_DIR/$name" ] || rm "$ROOT_DIR/$PKGDBPERMS_DIR/$name" fi - if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$PKGDB_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion" - ) - fi -fi +done # running ldconfig if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then diff --git a/pkgbuild b/pkgbuild index d8eb96f..d936713 100755 --- a/pkgbuild +++ b/pkgbuild @@ -34,33 +34,20 @@ msgwarn() { echo "==> WARNING: $1" >&2 } -updatemdsum() { - for s in $(getsourcelist); do - if [ ! -f $s ]; then - msgerr "Source file '$s' not found." +pkg_genchecksums() { + for i in $(get_filepath); do + [ -f "$i" ] || { + msgerr "File missing: $i" err=1 - fi + } done [ "$err" = 1 ] && abort 1 generatemdsum > .checksums msg "Checksums updated." } -getsourcelist() { - for s in $source; do - if echo $s | grep -qE "::(ftp|http|https)://"; then - FILENAME=$SOURCE_DIR/$(echo $s | awk -F '::' '{print $1}') - elif echo $s | grep -qE "(ftp|http|https)://"; then - FILENAME=$SOURCE_DIR/$(basename $s) - else - FILENAME=$PWD/$s - fi - echo $FILENAME - done -} - generatemdsum() { - for s in $(getsourcelist); do + for s in $(get_filepath); do if [ -f $s ]; then needupdatechecksum="$needupdatechecksum $s" fi @@ -72,14 +59,16 @@ generatemdsum() { fi } -checkmdsum() { - [ "$CHECK_MDSUM" = 0 ] || [ "$IGNORE_MDSUM" = yes ] && return 0 +pkg_checksum() { + if [ "$IGNORE_MDSUM" = "yes" ] || [ "$IGNORE_MDSUM" = 1 ]; then + return 0 + fi TMPCHECKSUM=$WORK_DIR/checksumstmp.$$ ORICHECKSUM=$WORK_DIR/checksumsori.$$ DIFCHECKSUM=$WORK_DIR/checksumsdiff.$$ if [ ! -f .checksums ]; then - updatemdsum + pkg_genchecksums else msg "Checking checksums..." generatemdsum > "$TMPCHECKSUM" @@ -102,51 +91,37 @@ checkmdsum() { [ "$mismatch" = 1 ] && abort 1 } -download_src() { - for FILE in $source; do - if echo $FILE | grep -Eq '::(http|https|ftp)://'; then - FILENAME=$(echo $FILE | awk -F '::' '{print $1}') - SRCURL=$(echo $FILE | awk -F '::' '{print $2}') - else - 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;; +get_filepath() { + for i in $source; do + case $i in + *::*) echo $SOURCE_DIR/${i%::*};; + *://*) echo $SOURCE_DIR/${i##*/};; + *) echo $PWD/$i;; esac - if [ "$FILENAME" != "$FILE" ]; then - if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then - [ "$REDOWNLOAD_SOURCE" ] && rm -f "$SOURCE_DIR/$FILENAME.partial" - if [ -f "$SOURCE_DIR/$FILENAME.partial" ]; then - msg "Resuming '$SRCURL'." - else - msg "Downloading '$SRCURL'." - fi - $DLCMD $SRCURL - if [ $? = 0 ]; then - [ "$REDOWNLOAD_SOURCE" ] && rm -f "$SOURCE_DIR/$FILENAME" - mv $SOURCE_DIR/$FILENAME.partial $SOURCE_DIR/$FILENAME - else - msgerr "Failed downloading '$FILENAME'." - abort 1 - fi - fi - else - if [ ! -f "$FILENAME" ]; then - msgerr "Source '$FILENAME' not found." - abort 1 - fi - fi done } -prepare_src() { +pkg_fetch() { + for i in $source; do + case $i in + *::*) filepath="$SOURCE_DIR/${i%::*}"; url=${i#*::};; + *://*) filepath="$SOURCE_DIR/${i##*/}"; url=$i;; + *) continue;; + esac + [ -f "$filepath" ] && { + msg "Source found: $filepath" + continue + } + msg "Fetching: $i" + curl -C - -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $filepath.partial $CURL_OPTS $url || { + msgerr "Fetching failed: $i" + abort 1 + } + mv $filepath.partial $filepath + done +} + +pkg_unpack() { SRC=$WORK_DIR/$name/src PKG=$WORK_DIR/$name/pkg @@ -156,77 +131,59 @@ prepare_src() { mkdir -p $SRC $PKG - if [ "$source" ]; then - for FILE in $source; do - if echo $FILE | grep -Eq '::(http|https|ftp)://'; then - FILENAME=$SOURCE_DIR/$(echo $FILE | awk -F '::' '{print $1}') - elif echo $FILE | grep -Eq '^(http|https|ftp)://'; then - FILENAME=$SOURCE_DIR/$(basename $FILE) - else - FILENAME=$PWD/$(basename $FILE) - fi - for NOEXT in $noextract; do - if [ "$NOEXT" = "$(basename $FILENAME)" ]; then - nxt=1 - break - fi - done - if [ ! -f $FILENAME ]; then - msgerr "File source '$FILENAME' not found." - err=1 - continue - fi - 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 [ $(command -v bsdtar) ]; then - COMMAND="bsdtar -p -o -C $SRC -xf $FILENAME" - else - COMMAND="tar -p -o -C $SRC -xf $FILENAME" - fi - MODE="Unpacking" ;; - *) - COMMAND="cp $FILENAME $SRC" - MODE="Preparing" ;; - esac - msg "$MODE '$(basename $FILENAME)'..." - $COMMAND || { - msgerr "$MODE '$FILENAME' failed." - abort 1 - } - else - MODE="Preparing" - msg "$MODE '$(basename $FILENAME)'..." - cp "$FILENAME" "$SRC" || { - msgerr "$MODE '$FILENAME' failed." + TAR=tar + [ $(command -v bsdtar) ] && TAR=bsdtar + + for i in $(get_filepath); do + if [ ! -f "$i" ]; then + msgerr "Source missing: $i" + abort 1 + fi + for n in $noextract; do + if [ ${i##*/} = $n ]; then + msg "Preparing: $i" + cp $i $SRC || { + msgerr "Preparing failed: $i" abort 1 } + continue 2 fi - unset nxt done - fi + case $i in + *.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tar.lz|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm) + msg "Unpacking: $i" + $TAR -p -o -C $SRC -xf $i;; + *) + msg "Preparing: $i" + cp $i $SRC;; + esac + [ $? = 0 ] || { + msgerr "Unpacking/Preparing failed: $i" + abort 1 + } + done } -run_build() { +pkg_build() { [ "$(id -u)" = 0 ] || { msgerr "You must build package as root, or use fakeroot." abort 1 } - msg "Start build '$name-$version-$release'." - - [ "$MAKE_FLAGS" = 1 ] && export MAKEFLAGS || unset MAKEFLAGS - [ "$BUILD_FLAGS" = 1 ] && export CFLAGS CXXFLAGS || unset CFLAGS CXXFLAGS + msg "Build start: $name-$version-$release" cd $SRC >/dev/null - - (set -e -x; build 2>&1) + if [ "$QUIET" ]; then + (set -e -x; build) 2> /dev/null + else + (set -e -x; build 2>&1) + fi if [ $? != 0 ]; then - msgerr "Build '$name-$version-$release' failed." + msgerr "Build failed: $name-$version-$release" abort 1 else - msg "Build '$name-$version-$release' success." + msg "Build success: $name-$version-$release" fi cd - >/dev/null @@ -237,14 +194,14 @@ pkglint() { # cant package empty PKG if [ ! "$(find $PKG/* -maxdepth 1 -type d 2>/dev/null)" ]; then - msgerr "PKG is empty." + msgerr "PKG is empty" abort 1 fi # check for backup file for f in $backup; do if [ ! -f $PKG/$f ]; then - msgerr "Backup file '$f' not exist in PKG!" + msgerr "Backup file '$f' does not exist in PKG!" linterror=1 fi done @@ -254,14 +211,6 @@ pkglint() { fi } -removeemptydirs() { - find . -type d -empty -delete -} - -removelibtool() { - find . ! -type d -name "*.la" -delete -} - strip_files() { if [ "$nostrip" ]; then for i in $nostrip; do @@ -323,42 +272,10 @@ compressinfomanpages() { fi } -backupconf() { - for FILE in $backup; do - mv $FILE $FILE.spkgnew - done -} - -removedocs() { - for i in doc gtk-doc info; do - rm -fr \ - usr/share/$i \ - usr/$i \ - usr/local/$i \ - usr/local/share/$i - done -} - -removelocales() { - rm -fr \ - usr/share/locale \ - usr/locale \ - usr/local/locale \ - usr/local/share/locale \ - usr/lib/locale -} - -packaging() { +pkg_package() { # lint $PKG before packaging pkglint - for FILE in $INCLUDEINPKG; do - if [ -f $FILE ]; then - install -m644 $FILE $PKG/.pkg$FILE - addtotar="$addtotar .pkg$FILE" - fi - done - cd $PKG >/dev/null # remove possible conflict junks @@ -369,15 +286,28 @@ packaging() { find usr/share/fonts \( -name fonts.dir -o -name fonts.scale \) -delete } - [ "$KEEP_EMPTYDIR" = 0 ] && removeemptydirs - [ "$KEEP_LIBTOOL" = 0 ] && removelibtool - [ "$STRIP_BINARY" = 1 ] && strip_files - [ "$ZIP_MAN" = 1 ] && compressinfomanpages - [ "$KEEP_DOCS" = 0 ] && removedocs - [ "$KEEP_LOCALES" = 0 ] && removelocales + if [ "$KEEP_LIBTOOL" = 0 ] || [ "$KEEP_LIBTOOL" = "no" ]; then + find . ! -type d -name "*.la" -delete + fi + + if [ "$KEEP_LOCALE" = 0 ] || [ "$KEEP_LOCALE" = "no" ]; then + rm -fr usr/share/locale usr/locale usr/lib/locale + fi - if [ "${#backup[@]}" -gt 0 ]; then - backupconf + if [ "$KEEP_DOC" = 0 ] || [ "$KEEP_DOC" = "no" ]; then + rm -fr usr/share/doc usr/share/gtk-doc usr/doc usr/gtk-doc + fi + + if [ "$NO_STRIP" = 0 ] || [ "$NO_STRIP" = "no" ]; then + strip_files + fi + + compressinfomanpages + + if [ "$backup" ]; then + for FILE in $backup; do + mv $FILE $FILE.spkgnew + done fi [ "$FORCE_REBUILD" ] && rm -f "$PACKAGE_DIR/$PKGNAME" @@ -390,117 +320,64 @@ packaging() { tar -c $COMPRESS -f $PACKAGE_DIR/$PKGNAME * $addtotar || { rm -f $PACKAGE_DIR/$PKGNAME - msgerr "Packaging '$PKGNAME' failed." + msgerr "Packaging failed: $PKGNAME" abort 1 } tar -tvf $PACKAGE_DIR/$PKGNAME | sort -k 6 - msg "Successfully created package '$PKGNAME'. ($(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}'))" + msg "Packaging success: $PKGNAME ($(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}'))" cd - >/dev/null - [ -f .pkgfiles ] || generate_pkgfiles + [ -f .pkgfiles ] || pkg_genpkgfiles } -generate_pkgfiles() { +pkg_genpkgfiles() { [ -f "$PACKAGE_DIR/$PKGNAME" ] || { - msgerr "Package '$PKGNAME' not found." + msgerr "Package not found: $PKGNAME" exit 1 } - for i in $INCLUDEINPKG; do - excludefile="$excludefile --exclude=.pkg$i" - done + echo "$name-$version-$release" > .pkgfiles - tar -tvf "$PACKAGE_DIR/$PKGNAME" $excludefile \ + tar -tvf "$PACKAGE_DIR/$PKGNAME" \ | awk '{$3=$4=$5=""; print $0}' \ | sed "s,lib/modules/$(uname -r),lib/modules/,g" \ - | sort -k 3 > .pkgfiles + | sort -k 3 >> .pkgfiles msg "Pkgfiles updated." } -cleanup() { +pkg_clean() { [ -e "$PACKAGE_DIR/$PKGNAME" ] && { - msg "Removing $PACKAGE_DIR/$PKGNAME" rm -f "$PACKAGE_DIR/$PKGNAME" + msg "Package removed: $PACKAGE_DIR/$PKGNAME" } - for src in $source; do - if echo $src | grep -qE "::(ftp|http|https)://"; then - FILENAME=$SOURCE_DIR/$(echo $src | awk -F '::' '{print $1}') - elif echo $src | grep -qE "^(ftp|http|https)://"; then - FILENAME=$SOURCE_DIR/$(basename $src) - else - FILENAME=$src - fi - if [ -e "$FILENAME" ] && [ "$FILENAME" != "$src" ]; then - msg "Removing $FILENAME" - rm -f "$FILENAME" - fi + for i in $(get_filepath); do + rm -f "$i" + msg "File removed: $i" done } check_buildscript() { # check the required field in buildscript - if [ -z "$name" ]; then - msgerr "'name' is empty!" - exit 1 - #elif [ "$(echo $name | grep -oP "\w*[A-Z]+\w*")" ]; then - # msgerr "Capital letters for port name not allowed!" - # exit 1 - elif [ "$(basename $(pwd))" != "$name" ]; then - msgerr "Port name and Directory name is different!" - exit 1 - elif [ -z "$version" ]; then - msgerr "'version' is empty!" - exit 1 - elif [ -z "$release" ]; then - msgerr "'release' is empty!" - exit 1 - elif [ ! "$(command -v build)" ]; then - msgerr "'build' function not exist!" - exit 1 - elif echo "$version" | grep -q '-'; then - msgerr "'version' should not contain '-'." - exit 1 - elif echo "$release" | grep -q '-'; then - msgerr "'release' should not contain '-'." - exit 1 - elif [ -z "$description" ]; then - msgerr "'description' cant empty." - exit 1 - fi -} - -set_options() { - for OPT in $OPTIONS $options; do - case $OPT in - libtool) KEEP_LIBTOOL=1 ;; - !libtool) KEEP_LIBTOOL=0 ;; - emptydirs) KEEP_EMPTYDIR=1;; - !emptydirs) KEEP_EMPTYDIR=0;; - strip) STRIP_BINARY=1 ;; - !strip) STRIP_BINARY=0 ;; - zipman) ZIP_MAN=1 ;; - !zipman) ZIP_MAN=0 ;; - buildflags) BUILD_FLAGS=1 ;; - !buildflags) BUILD_FLAGS=0 ;; - makeflags) MAKE_FLAGS=1 ;; - !makeflags) MAKE_FLAGS=0 ;; - checksum) CHECK_MDSUM=1 ;; - !checksum) CHECK_MDSUM=0 ;; - docs) KEEP_DOCS=1 ;; - !docs) KEEP_DOCS=0 ;; - locales) KEEP_LOCALES=1 ;; - !locales) KEEP_LOCALES=0 ;; - esac - done + [ "$name" ] || { msgerr "'name' is empty!"; exit 1; } + case $name in + *[A-Z]*) msgerr "Capital letters for port name are not allowed!"; exit 1;; + esac + [ "$(basename $(pwd))" = "$name" ] || { msgerr "Port name and Directory name is different!"; exit 1; } + [ "$version" ] || { msgerr "'version' is empty!"; exit 1; } + [ "$release" ] || { msgerr "'release' is empty!"; exit 1; } + [ "$(command -v build)" ] || { msgerr "'build' function not exist!"; exit 1; } + [ "$(echo "$version" | grep '-')" ] && { msgerr "'version' should not contain '-'."; exit 1; } + [ "$(echo "$release" | grep '-')" ] && { msgerr "'release' should not contain '-'."; exit 1; } + [ "$description" ] || { msgerr "'description' is empty!"; exit 1; } } checkdir() { for DIR in "$@"; do if [ ! -d $DIR ]; then - msgerr "Directory '$DIR' not exist." + msgerr "Directory '$DIR' does not exist." exit 1 elif [ ! -w $DIR ]; then msgerr "Directory '$DIR' not writable." @@ -512,10 +389,10 @@ checkdir() { done } -clearworkdir() { +pkg_cleanup() { if [ ! "$KEEP_WORK" ]; then if [ "$name" ]; then - rm -fr $WORK_DIR/$name + rm -fr "$WORK_DIR/$name" fi fi } @@ -527,13 +404,14 @@ interrupted() { abort() { rm -f "$LOCK_FILE" - clearworkdir + pkg_cleanup exit $1 } parse_opts() { while [ "$1" ]; do case $1 in + -q | --quiet) QUIET=yes ;; -i | --install) INSTALL_PKG=yes ;; -u | --upgrade) UPGRADE_PKG=yes; OPTS="$OPTS $1" ;; -r | --reinstall) REINSTALL_PKG=yes; OPTS="$OPTS $1" ;; @@ -548,13 +426,8 @@ parse_opts() { -p | --pkgfiles) GENPKGFILES=yes ;; -h | --help) SHOWHELP=yes ;; --clean) CLEANUP=yes ;; - --root=*) OPTS="$OPTS $1" ;; - --no-preinstall) OPTS="$OPTS $1" ;; - --no-postinstall) OPTS="$OPTS $1" ;; - --no-preupgrade) OPTS="$OPTS $1" ;; - --no-postupgrade) OPTS="$OPTS $1" ;; --no-backup) OPTS="$OPTS $1" ;; - --redownload) REDOWNLOAD_SOURCE=yes ;; + --root=*) OPTS="$OPTS $1" ;; --config=*) PKGBUILD_CONF="${1#*=}" ;; --srcdir=*) CUSTOM_SOURCE_DIR="${1#*=}" ;; --pkgdir=*) CUSTOM_PACKAGE_DIR="${1#*=}" ;; @@ -571,6 +444,7 @@ Usage: $(basename $0) [ ] Options: + -q --quiet show only status messages and errors -i, --install install package into system -u, --upgrade upgrade package -r, --reinstall reinstall package @@ -589,12 +463,7 @@ Options: --srcdir= override directory path for sources --pkgdir= override directory path for compiled package --workdir= override directory path for working dir - --no-preinstall skip preinstall script before 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 configuration file when upgrading package - --redownload re-download source file EOF } @@ -646,40 +515,39 @@ main() { fi check_buildscript - set_options case $COMPRESSION_MODE in gz|bz2|xz) PKGNAME="$name-$version-$release.spkg.tar.$COMPRESSION_MODE" ;; - *) msgerr "Invalid compression mode. ($COMPRESSION_MODE)"; exit 1 ;; + *) msgerr "Invalid compression mode: $COMPRESSION_MODE"; exit 1 ;; esac # generate .pkgfiles [ "$GENPKGFILES" ] && { - generate_pkgfiles + pkg_genpkgfiles exit 0 } # download source only [ "$DOWNLOAD_ONLY" ] && { - download_src + pkg_fetch exit 0 } # extract source only [ "$EXTRACT_ONLY" ] && { - prepare_src + pkg_unpack exit 0 } # update md5sum [ "$UPDATE_MDSUM" ] && { - updatemdsum + pkg_genchecksums exit 0 } # remove source and package [ "$CLEANUP" ] && { - cleanup + pkg_clean exit 0 } @@ -687,31 +555,41 @@ main() { # check for lock file [ -f "$LOCK_FILE" ] && { - msgerr "Cant build same package simultaneously." + msgerr "Cannot build same package simultaneously." msgerr "remove '$LOCK_FILE' if no build process for '$name'." exit 1 } # create lock file touch "$LOCK_FILE" 2>/dev/null || { - msgerr "Cant create lock file in '$LOCK_FILE'." + msgerr "Cannot create lock file in '$LOCK_FILE'." exit 1 } # build package if [ -f "$PACKAGE_DIR/$PKGNAME" ] && [ ! "$FORCE_REBUILD" ]; then if [ ! "$INSTALL_PKG" ] && [ ! "$REINSTALL_PKG" ] && [ ! "$UPGRADE_PKG" ]; then - echo "Package '$PKGNAME' is up-to-date." + msg "Package is up-to-date: $PKGNAME" abort 0 fi else - msg "Building '$name-$version-$release'..." - download_src - checkmdsum - prepare_src - run_build - packaging - clearworkdir + if [ "$QUIET" ]; then + msg "Building: $name-$version-$release" + pkg_fetch 2> /dev/null + pkg_checksum > /dev/null + pkg_unpack > /dev/null + pkg_build > /dev/null + pkg_package > /dev/null + pkg_cleanup > /dev/null + else + msg "Building: $name-$version-$release" + pkg_fetch + pkg_checksum + pkg_unpack + pkg_build + pkg_package + pkg_cleanup + fi fi # install package @@ -732,11 +610,11 @@ PKGBUILD_BSCRIPT="spkgbuild" SOURCE_DIR="/var/cache/scratchpkg/sources" PACKAGE_DIR="/var/cache/scratchpkg/packages" WORK_DIR="/var/cache/scratchpkg/work" -DOWNLOAD_PROG="auto" COMPRESSION_MODE="xz" - -OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales" - -INCLUDEINPKG="install readme mkdirs" +NO_STRIP="no" +IGNORE_MDSUM="no" +KEEP_LIBTOOL="no" +KEEP_LOCALE="no" +KEEP_DOC="no" main "$@" diff --git a/pkgdel b/pkgdel index a2424e0..4c7f962 100755 --- a/pkgdel +++ b/pkgdel @@ -51,8 +51,6 @@ Usage: Options: -h, --help show this help message -v, --verbose print removed files - --no-preremove don't run pre-remove script - --no-postremove don't run post-remove script --root= remove package from custom root directory EOF @@ -82,8 +80,6 @@ parse_opts() { case $1 in -h | --help) SHOWHELP=yes ;; -v | --verbose) VERBOSE_REMOVE="-v" ;; - --no-preremove) NO_PREREMOVE=yes ;; - --no-postremove) NO_POSTREMOVE=yes ;; --root=*) ROOT_DIR="${1#*=}" ;; -*) msg "Invalid option: ($1)"; exit 1 ;; *) RMNAME=$1 ;; @@ -95,26 +91,18 @@ parse_opts() { ret() { # remove lock file on exit - rm -f "$ROOT_DIR/$LOCK_FILE" "$reserve" "$dirs" "$remove" "$files" + rm -f "$ROOT_DIR/$LOCK_FILE" exit $1 } isinstalled() { - if [ -s "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo"; then + if [ -s "$ROOT_DIR/$PKGDB_DIR/$1" ]; then return 0 else return 1 fi } -run_scripts() { - if [ "$ROOT_DIR" ]; then - xchroot "$ROOT_DIR" sh $@ - else - sh $@ - fi -} - command -v pkgadd >/dev/null 2>&1 || { msgerr "'pkgadd' not found in \$PATH!" exit 1 @@ -124,6 +112,7 @@ parse_opts $(extract_opts "$@") PKGDB_DIR="$(pkgadd --print-dbdir)" PKGDB_DIR="${PKGDB_DIR##/}" # remove leading / +PKGDBPERMS_DIR="$PKGDB_DIR.perms" LOCK_FILE="var/lib/scratchpkg/spkg.lock" # show help page @@ -140,13 +129,13 @@ LOCK_FILE="var/lib/scratchpkg/spkg.lock" # check for lock file [ -f "$ROOT_DIR/$LOCK_FILE" ] && { - msgerr "Cant install/remove package simultaneously." + msgerr "Cannot 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 || { - msgerr "Cant create lock file in '$ROOT_DIR/$LOCK_FILE'" + msgerr "Cannot create lock file in '$ROOT_DIR/$LOCK_FILE'" exit 1 } @@ -155,56 +144,25 @@ if ! isinstalled "$RMNAME"; then ret 1 fi -name=$(grep ^name $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) -version=$(grep ^version $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) -release=$(grep ^release $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) +name=$RMNAME +version=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $1}') +release=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $2}') -if [ -z "$name" ] && [ -z "$version" ] && [ -z "$release" ]; then - msgerr "Package '$RMNAME' not installed but exist in database." +if [ -z "$version" ] && [ -z "$release" ]; then + msgerr "Package '$RMNAME' is not installed but exists in database." ret 1 fi -# create list for reserve and remove (dirs and files) -reserve="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_reserve" -remove="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_remove" -dirs="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_dirs" -files="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_files" - -grep '/$' $ROOT_DIR/$PKGDB_DIR/*/.files \ - | grep -v "$ROOT_DIR/$PKGDB_DIR/$name" \ - | awk -F : '{print $2}' \ - | sort \ - | uniq > "$reserve" -grep '/$' "$ROOT_DIR/$PKGDB_DIR/$name/.files" > "$remove" -grep -Fxv -f "$reserve" "$remove" | tac > "$dirs" -grep -v '/$' "$ROOT_DIR/$PKGDB_DIR/$name/.files" | tac >> "$files" - -echo "remove: $name-$version-$release..." - -# pre-remove script -if [ ! "$NO_PREREMOVE" ] && [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$PKGDB_DIR/$name/.pkginstall" pre-remove "$version" - ) -fi - -# remove files and dirs -(cd "$ROOT_DIR"/ - [ -s $files ] && xargs -a $files -d'\n' rm $VERBOSE_REMOVE - [ -s $dirs ] && xargs -a $dirs -d'\n' rmdir $VERBOSE_REMOVE -) - -rm -f "$reserve" "$dirs" "$remove" "$files" - -# post-remove script -if [ ! "$NO_POSTREMOVE" ] && [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then - (cd "$ROOT_DIR"/ - run_scripts "$PKGDB_DIR/$name/.pkginstall" post-remove "$version" - ) -fi +tail -n+2 "$ROOT_DIR/$PKGDB_DIR"/$name | tac | while read -r line; do + case $line in + */) grep "^$line$" "$ROOT_DIR/$PKGDB_DIR"/* 2>/dev/null | grep -qv "$ROOT_DIR/$PKGDB_DIR"/$name: || rmdir $([ "$VERBOSE_REMOVE" ] && echo -v) "$ROOT_DIR/$line";; + *) rm $([ "$VERBOSE_REMOVE" ] && echo -v) "$ROOT_DIR/$line";; + esac +done # remove from database -rm -rf "$ROOT_DIR/$PKGDB_DIR/$name" +rm -f "$ROOT_DIR/$PKGDB_DIR/$name" +rm -f "$ROOT_DIR/$PKGDBPERMS_DIR/$name" # running ldconfig if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then diff --git a/pkgfix b/pkgfix index 14caf52..6f89f12 100755 --- a/pkgfix +++ b/pkgfix @@ -22,6 +22,16 @@ export LANG=C +get_pythonmodules() { + command -v python3 >/dev/null || return + pylibpath=$(python3 -c "import sys; print(':'.join(x for x in sys.path if x))" | tr ':' '\n' | sort | head -n1) + for i in /usr/lib/python3.*; do + [ -d "$i" ] || continue + [ "$i" = "$pylibpath" ] && continue + brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')" + done +} + get_perlmodules() { command -v perl >/dev/null || return perlpath=$(dirname $(perl -V:sitearch | grep -o "'.*'" | sed "s/'//g")) @@ -111,6 +121,7 @@ fi get_modules get_perlmodules get_rubygem +get_pythonmodules if [ "$brokenpkg" ]; then sort_modules @@ -122,10 +133,10 @@ fi if [ "$REBUILD" = 1 ]; then [ "$YES" ] || { echo - echo "Package will be rebuild & reinstall by this order:" + echo "Package will be rebuilt & reinstalled in this order:" echo " $order" echo - confirm "Continue rebuild & reinstall broken packages?" "Operation cancelled." + confirm "Continue rebuild & reinstall of broken packages?" "Operation cancelled." } for p in $order; do scratch build -f $p || exit 1 diff --git a/portcreate b/portcreate index 7a5c8d7..d1a7414 100755 --- a/portcreate +++ b/portcreate @@ -24,12 +24,12 @@ if [ -d "$1" ]; then else mkdir "$1" echo "# description : +# homepage : # depends : name=$1 version= release=1 -options=\"\" noextract=\"\" backup=\"\" source=\"\" diff --git a/portsync b/portsync new file mode 100755 index 0000000..0fb79a7 --- /dev/null +++ b/portsync @@ -0,0 +1,137 @@ +#!/bin/sh +# +# scratchpkg +# +# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +cmp_copy() { + # usage: + # cmp_copy + # + reponame=${2##*/} + echo "Updating repository $(basename $reponame)" + for p in $1/*; do + [ -d $p ] || continue + pname=${p##*/} + if [ ! -d $2/$pname ]; then + mkdir -p $2/$pname + for f in $p/* $p/.pkgfiles $p/.checksums; do + [ -f $f ] || continue + case $f in + */update) continue;; + esac + fname=${f##*/} + echo " New: $reponame/$pname/$fname" + cp $f $2/$pname/$fname + done + else + for f in $p/* $p/.pkgfiles $p/.checksums; do + [ -f $f ] || continue + case $f in + */update) continue;; + esac + fname=${f##*/} + cmp -s $f $2/$pname/$fname || { + echo " Edit: $reponame/$pname/$fname" + cp $f $2/$pname/$fname + } + done + fi + done + for p in $2/*; do + [ -d $p ] || continue + pname=${p##*/} + for f in $p/* $p/.pkgfiles $p/.checksums; do + [ -f $f ] || continue + fname=${f##*/} + if [ ! -f $1/$pname/$fname ]; then + echo " Removed: $reponame/$pname/$fname" + rm $2/$pname/$fname + fi + done + if [ ! -d $1/$pname ]; then + rmdir $2/$pname + fi + done + echo "Finished successfully" +} + +github_sync() { + # usage: + # github_sync + # + dir=$2 + repo=${dir##*/} + url=$(echo $1 | cut -d / -f -5) + branch=$(echo $1 | cut -d / -f 7) + tarball=/tmp/$repo + echo "Fetching from $1" + curl --silent -LJ -o $tarball.tar.xz $url/tarball/$branch || { + echo "Failed fetching repo from $1" + exit 1 + } + tar -tf $tarball.tar.xz >/dev/null 2>&1 || { + echo "Tarball from $1 corrupted" + exit 1 + } + portname=$(tar -tf $tarball.tar.xz 2>/dev/null | head -n1 | cut -d / -f1) + tar -xf $tarball.tar.xz -C /tmp + if [ ! "$portname" ] || [ -d "$repo" ]; then + echo "Failed sync $repo repo" + exit 1 + fi + cmp_copy /tmp/$portname/$repo $dir + rm -f $tarball.tar.xz + rm -fr /tmp/$portname +} + +httpup_sync() { + # usage: + # httpup_sync + # + command -v httpup >/dev/null 2>&1 || { + echo "httpup not found." + exit 1 + } + httpup sync $1 $2 || { + echo "Failed sync from $1" + exit 1 + } +} + +REPO_FILE=/etc/scratchpkg.repo + +if [ ! -e "$REPO_FILE" ]; then + echo "Repo file not found! ($REPO_FILE)" + exit 1 +fi + +if [ "$(id -u)" != 0 ]; then + echo "This operation need root access." + exit 1 +fi + +grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do + if [ "$repodir" ] && [ "$repourl" ]; then + case $repourl in + *github.com*) github_sync $repourl $repodir;; + *) httpup_sync $repourl $repodir;; + esac + fi +done + +exit 0 diff --git a/revdep b/revdep index 86e5612..7da321e 100755 --- a/revdep +++ b/revdep @@ -270,7 +270,7 @@ echo "Checking for broken linkage..." while read -r line; do count=$(( count + 1 )) - libname=$(basename "$line") + libname=${line##*/} printf " $(( 100*count/total ))%% $libname\033[0K\r" case "$(file -bi "$line")" in *application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*) @@ -281,13 +281,12 @@ while read -r line; do NEW_LIB_NAME="$NEW_LIB_NAME $l" fi done + [ "$NEW_LIB_NAME" ] || continue LIB_NAME=$NEW_LIB_NAME - [ "$LIB_NAME" ] || continue - PKG_NAME=$(echo $line | sed 's#^/##') - PKG_NAME=$(grep -Rx $PKG_NAME "$PKGDB_DIR"/*/.files | cut -d : -f1) + PKG_NAME=${line#?} # remove leading slash + PKG_NAME=$(grep -Rx $PKG_NAME "$PKGDB_DIR"/* | awk -F : '{print $1}') [ "$PKG_NAME" ] || continue - PKG_NAME=$(dirname $PKG_NAME) - PKG_NAME=$(basename $PKG_NAME) + PKG_NAME=${PKG_NAME##*/} echo $expkg | tr ' ' '\n' | grep -qx $PKG_NAME && continue REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ') for i in $LIB_NAME; do @@ -319,7 +318,7 @@ if [ "$ALLPKG" ]; then rebuild fi else - echo "All packages is doing fine." + echo "All packages are doing fine." fi cleanup diff --git a/scratch b/scratch index b512f1a..57ef696 100755 --- a/scratch +++ b/scratch @@ -18,12 +18,12 @@ # along with this program. If not, see . # -RED='\e[0;31m' -GREEN='\e[0;32m' -YELLOW='\e[0;33m' -CYAN='\e[0;36m' -PURPLE='\e[0;35m' -CRESET='\e[0m' +RED='\033[31m' +GREEN='\033[32m' +YELLOW='\033[33m' +CYAN='\033[36m' +PURPLE='\033[35m' +CRESET='\033[0m' nocolor() { RED= @@ -85,21 +85,23 @@ vercomp() { #elif [ "$1" = "$(echo "$1\n$2" | sort -V | head -n1)" ]; then elif [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then return 1 # $1 lower than $2 - #echo "1" else return 2 # $1 higher than $2 - #echo "2" 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() { @@ -154,7 +156,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 @@ -168,8 +170,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" @@ -186,7 +188,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" @@ -200,39 +202,13 @@ 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 - grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' | column -t + grep -R $@ $repo/*/.pkgfiles 2>/dev/null | sed 's/:/ /;s/\/\.pkgfiles//' | awk '{print $1,$4}' 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 @@ -249,21 +225,48 @@ scratch_isorphan() { } scratch_sync() { - checktool httpup - needroot "Updating ports" - - if [ ! -e "$REPO_FILE" ]; then - msgerr "Repo file not found! ($REPO_FILE)" - exit 1 - fi + portsync +} - grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1,$2}' | while read -r repodir repourl; do - if [ "$repodir" ] && [ "$repourl" ]; then - httpup sync $repourl $repodir || { - msgerr "Failed sync from $repourl" - exit 1 - } - fi +cvperms() { + # converts symbolic to numeric permissions + # required an input (symbolic, eg: drwxr-xr-x) + s=0; n=0; count=0 + for i in $(echo "$1" | sed -e 's/\(.\)/\1\n/g'); do + count=$((count+1)) + case $i in + d) ;; + r) n=$((n+4));; + w) n=$((n+2));; + x) n=$((n+1));; + s) [ $count = 4 ] && s=$((s+4)) || s=$((s+2)); n=$((n+1));; + t) s=$((s+1));n=$((n+1));; + S) s=$((s+2));; + T) s=$((s+1));; + esac + [ "$count" = 4 ] && { + user=$n; n=0 + } + [ "$count" = 7 ] && { + group=$n; n=0 + } + [ "$count" = 10 ] && { + other=$n; n=0 + } + done + echo "$s$user$group$other" +} + +fixperms() { + needroot "Fix permissions" + for i in $PKGDBPERMS_DIR/*; do + [ -s $i ] || continue + while read -r perms own dir; do + chmod $(cvperms $perms) /$dir + echo $own | while IFS=/ read -r o g; do + chown $o:$g /$dir + done + done < $i done } @@ -279,27 +282,7 @@ scratch_trigger() { post_triggers } -post_triggers() { - if [ "$trig_12" = 1 ]; then - echo "trigger: Running mkdirs..." - for mkd in $PKGDB_DIR/*/.pkgmkdirs; do - [ -s $mkd ] || continue - grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do - if [ -e "$dir" ]; then - if [ "$uid" != '-' ]; then - getent passwd $uid >/dev/null && chown "$uid" "$dir" - fi - if [ "$gid" != '-' ]; then - getent group $gid >/dev/null && chgrp "$gid" "$dir" - fi - if [ "$mode" != '-' ]; then - chmod "$mode" "$dir" - fi - fi - done - done - fi - +post_triggers() { if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then echo "trigger: Updating fontconfig cache..." fc-cache -s @@ -367,13 +350,15 @@ post_triggers() { echo "trigger: Updating the MIME type database..." update-mime-database /usr/share/mime fi + + fixperms } 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 @@ -383,7 +368,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 @@ -393,7 +378,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 @@ -403,7 +388,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 @@ -413,7 +398,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 @@ -423,7 +408,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 @@ -433,7 +418,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 @@ -443,7 +428,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 @@ -453,7 +438,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 @@ -463,7 +448,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 @@ -473,22 +458,12 @@ 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 done fi - - # makedirs - if [ "$trig_12" != "1" ]; then - for pkg in $@; do - if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then - trig_12=1 - break - fi - done - fi } scratch_build() { @@ -628,11 +603,17 @@ scratch_install() { if portpathh=$(getportpath $int); then cd $portpathh settermtitle "[ $count/$total ] installing $int..." + [ -f ./pre-install.sh ] && { + sh ./pre-install.sh + } pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break } + [ -f ./post-install.sh ] && { + sh ./post-install.sh + } done_pkg="$done_pkg $int" cd - >/dev/null else @@ -709,8 +690,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 @@ -781,18 +762,30 @@ scratch_sysup() { cd $(getportpath $inst) if ! isinstalled $inst; then settermtitle "[ $count/$total ] Installing $inst..." + [ -f ./pre-install.sh ] && { + sh ./pre-install.sh + } pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break } + [ -f ./post-install.sh ] && { + sh ./post-install.sh + } else settermtitle "[ $count/$total ] Upgrading $inst..." + [ -f ./pre-upgrade.sh ] && { + sh ./pre-upgrade.sh + } pkgbuild -u $OPTS || { error=1 count=$(( count - 1 )) break } + [ -f ./post-upgrade.sh ] && { + sh ./post-upgrade.sh + } fi cd - >/dev/null done_pkg="$done_pkg $inst" @@ -829,7 +822,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 @@ -878,18 +871,30 @@ scratch_upgrade() { cd $(getportpath $inst) if ! isinstalled $inst; then settermtitle "[ $count/$total ] Installing $inst..." + [ -f ./pre-install.sh ] && { + sh ./pre-install.sh + } pkgbuild -i $OPTS || { error=1 count=$(( count - 1 )) break } + [ -f ./post-install.sh ] && { + sh ./post-install.sh + } else settermtitle "[ $count/$total ] Upgrading $inst..." + [ -f ./pre-upgrade.sh ] && { + sh ./pre-upgrade.sh + } pkgbuild -u $OPTS || { error=1 count=$(( count - 1 )) break } + [ -f ./post-upgrade.sh ] && { + sh ./post-upgrade.sh + } fi cd - >/dev/null done_pkg="$done_pkg $inst" @@ -907,9 +912,8 @@ scratch_outdate() { if [ -z "$name" ] || [ -z "$version" ]; then continue fi - iversion=$(installed_pkg_info version $pkg) - irelease=$(installed_pkg_info release $pkg) - [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" + iversion=$(get_iver $pkg) + irelease=$(get_irelease $pkg) if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then ITSLOCK="[masked]" fi @@ -917,6 +921,7 @@ scratch_outdate() { #newerinstmsg="$name $iversion-$irelease => $version-$release [newer installed] $ITSLOCK" outdatemsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${CYAN}$ITSLOCK${CRESET}" newerinstmsg="$name ${RED}$iversion-$irelease${CRESET} => ${GREEN}$version-$release${CRESET} ${YELLOW}[newer installed]${CRESET} ${CYAN}$ITSLOCK${CRESET}" + if [ "$version" != "$iversion" ]; then vercomp $version $iversion if [ $? = 2 ]; then @@ -948,7 +953,7 @@ scratch_search() { arg=$* for repo in $PORT_REPO; do [ -d $repo ] || continue - out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}' | sort) + out=$(grep -R "# description" $repo/*/$BUILD_SCRIPT | grep -i "$arg" | awk -F : '{print $1}' | sort) [ "$out" ] || continue found=1 for line in $out; do @@ -991,8 +996,6 @@ scratch_changelog() { msg "No matching package found" fi } - - scratch_cache() { needroot "Clear old caches" @@ -1249,12 +1252,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 } @@ -1265,6 +1267,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" @@ -1273,14 +1276,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 } @@ -1305,12 +1308,6 @@ scratch_missingdep() { done } -scratch_locked() { - for pkg in $(allinstalled); do - [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" - done -} - scratch_orphan() { tmpallpkg="/tmp/.pkgquery_allpkg.$$" tmpalldep="/tmp/.pkgquery_alldep.$$" @@ -1336,11 +1333,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 : " " \ - | column -t + | tr : "\t" } scratch_readme() { @@ -1360,7 +1355,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 @@ -1398,8 +1393,6 @@ Options: build build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') --log log build process (/var/log/pkgbuild.log) - lock locking ports prevent upgrade - unlock unlock locked ports trigger [ports] run system trigger search find ports in repo changelog find changelog in package @@ -1418,7 +1411,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 @@ -1471,6 +1463,7 @@ done BUILD_SCRIPT="spkgbuild" PKGDB_DIR="$(pkgadd --print-dbdir)" +PKGDBPERMS_DIR=${PKGDB_DIR}.perms REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" diff --git a/scratchpkg.conf b/scratchpkg.conf index 37207b0..b336bda 100644 --- a/scratchpkg.conf +++ b/scratchpkg.conf @@ -2,32 +2,17 @@ # Configuration file for scratchpkg # -# CFLAGS="-O2 -march=x86-64 -pipe" -# CXXFLAGS="${CFLAGS}" -# MAKEFLAGS="-j$(nproc)" +# export CFLAGS="-O2 -march=x86-64 -pipe" +# export CXXFLAGS="${CFLAGS}" +# export MAKEFLAGS="-j$(nproc)" # SOURCE_DIR="/var/cache/scratchpkg/sources" # PACKAGE_DIR="/var/cache/scratchpkg/packages" # WORK_DIR="/var/cache/scratchpkg/work" -# DOWNLOAD_PROG="auto" -# WGET_OPTS="" # CURL_OPTS="" # COMPRESSION_MODE="xz" - -# -# GLOBAL PACKAGE OPTIONS -# -# -- libtool: Keep libtool file (*.la) in packages -# -- emptydirs: Keep empty directories in packages -# -- strip: Strip symbols from binaries/libraries -# -- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip -# -- buildflags: Enable buildflags (CFLAGS and CXXFLAGS) -# -- makeflags: Enable makeflags (MAKEFLAGS) -# -- checksum: Enable checking checksum -# -- docs: Keep docs -# -- locales: Keep locales -# -# -- These are default values for the options="" settings -# -- add '!' in front of this option to disable it -# -# OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales" +# NO_STRIP="no" +# IGNORE_MDSUM="no" +# KEEP_LIBTOOL="no" +# KEEP_LOCALE="no" +# KEEP_DOC="no" diff --git a/scratchpkg.mask b/scratchpkg.mask index 4beda9c..8a7e346 100644 --- a/scratchpkg.mask +++ b/scratchpkg.mask @@ -1,6 +1,3 @@ -# exclude packages from sysup - -glibc -gcc -linux-api-headers -binutils +# +# /etc/scratchpkg.mask : exclude packages from sysup +# diff --git a/scratchpkg.repo b/scratchpkg.repo index efbf10c..aadfdb2 100644 --- a/scratchpkg.repo +++ b/scratchpkg.repo @@ -13,7 +13,6 @@ #DE /usr/Voncloft-OS/cinnamon https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/cinnamon /usr/Voncloft-OS/displaym https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/displaym -/usr/Voncloft-OS/gnome https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/gnome /usr/Voncloft-OS/kde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde /usr/Voncloft-OS/kf5 https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kf5 /usr/Voncloft-OS/lxde https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/lxde @@ -23,6 +22,7 @@ /usr/Voncloft-OS/xfce https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xfce /usr/Voncloft-OS/xorg https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/xorg + #Programming /usr/Voncloft-OS/compilers https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/compilers /usr/Voncloft-OS/libs https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/libs @@ -42,3 +42,6 @@ /usr/Voncloft-OS/kde-apps https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/kde-apps /usr/Voncloft-OS/media https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/media /usr/Voncloft-OS/nonfree https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/nonfree + +#personal +/usr/Voncloft-OS/personal-repository http://voncloft.dnsfor.me/packages/Voncloft-OS/programs From b7700651ee418d0e8af3883a3c21a7126282d301 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Tue, 25 May 2021 12:25:58 -0400 Subject: [PATCH 12/13] Minor Updates --- scratchpkg.mask | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scratchpkg.mask b/scratchpkg.mask index 8a7e346..8692f07 100644 --- a/scratchpkg.mask +++ b/scratchpkg.mask @@ -1,3 +1,7 @@ # # /etc/scratchpkg.mask : exclude packages from sysup # +gcc +binutils +glibc +linux-api-headers From cc3f14e8f865d0d351f4d1101bab4c8cd88cea73 Mon Sep 17 00:00:00 2001 From: Voncloft Date: Tue, 25 May 2021 12:26:31 -0400 Subject: [PATCH 13/13] Minor Updates --- scratchpkg.repo | 2 -- 1 file changed, 2 deletions(-) diff --git a/scratchpkg.repo b/scratchpkg.repo index aadfdb2..6236b04 100644 --- a/scratchpkg.repo +++ b/scratchpkg.repo @@ -43,5 +43,3 @@ /usr/Voncloft-OS/media https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/media /usr/Voncloft-OS/nonfree https://raw.githubusercontent.com/voncloft/Voncloft-OS/master/nonfree -#personal -/usr/Voncloft-OS/personal-repository http://voncloft.dnsfor.me/packages/Voncloft-OS/programs