From d40dc75169ad51debcf43fec76591091f4983274 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Sat, 24 Jul 2021 00:51:04 +0800 Subject: [PATCH] main/scratchpkg: portsync now use git to pull latest port --- main/scratchpkg/.checksums | 1 + main/scratchpkg/.pkgfiles | 2 +- main/scratchpkg/portsync | 111 +++++++++++++++++++++++++++++++++++++ main/scratchpkg/spkgbuild | 8 ++- 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100755 main/scratchpkg/portsync diff --git a/main/scratchpkg/.checksums b/main/scratchpkg/.checksums index 1dbe9df37..32acb3f08 100644 --- a/main/scratchpkg/.checksums +++ b/main/scratchpkg/.checksums @@ -1,3 +1,4 @@ c6182475cd990fb5c63ceec35394933d c254ac0dc62a037f41bc269f1df291f6f53ab239.tar.gz +d973b8d674eb1a65a1a51e452ff82a2b portsync e653273a32632805f9493224fd3af227 scratchpkg.conf ea1fd5e5a7866a32a99c3ee6cef35d29 scratchpkg.repo diff --git a/main/scratchpkg/.pkgfiles b/main/scratchpkg/.pkgfiles index 3f8cfee54..f72ded5c0 100644 --- a/main/scratchpkg/.pkgfiles +++ b/main/scratchpkg/.pkgfiles @@ -1,4 +1,4 @@ -scratchpkg-20210515-1 +scratchpkg-20210702-2 drwxr-xr-x root/root etc/ -rw-r--r-- root/root etc/revdep.conf.spkgnew drwxr-xr-x root/root etc/revdep.d/ diff --git a/main/scratchpkg/portsync b/main/scratchpkg/portsync new file mode 100755 index 000000000..2e4d1e45d --- /dev/null +++ b/main/scratchpkg/portsync @@ -0,0 +1,111 @@ +#!/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##*/} + 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 +} + +github_sync() { + # usage: + # github_sync + # + echo "Updating repo: $2" + dir=$2 + repo=${dir##*/} + url=$(echo $1 | cut -d / -f -5) + branch=$(echo $1 | cut -d / -f 7) + tmprepo=/tmp/tmprepo + echo " fetching $1" + rm -fr $tmprepo + git clone -q -b $branch $url $tmprepo + if [ $? != 0 ] || [ ! -d $tmprepo/$repo ]; then + echo " failed sync repo" + return 1 + fi + cmp_copy $tmprepo/$repo $dir + rm -fr $tmprepo + echo " repo update completed" +} + +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 + github_sync $repourl $repodir + fi +done + +exit 0 diff --git a/main/scratchpkg/spkgbuild b/main/scratchpkg/spkgbuild index c0551f929..8226a0791 100644 --- a/main/scratchpkg/spkgbuild +++ b/main/scratchpkg/spkgbuild @@ -1,9 +1,9 @@ # description : A simple package manager for Linux Distribution -# depends : coreutils libarchive +# depends : coreutils libarchive git name=scratchpkg version=20210702 -release=1 +release=2 backup="etc/scratchpkg.conf etc/scratchpkg.alias etc/scratchpkg.repo @@ -12,7 +12,8 @@ backup="etc/scratchpkg.conf scratchpkg_url=https://github.com/venomlinux/scratchpkg source="https://github.com/venomlinux/scratchpkg/archive/c254ac0dc62a037f41bc269f1df291f6f53ab239.tar.gz $name.repo - $name.conf" + $name.conf + portsync" build() { cd $name-c254ac0dc62a037f41bc269f1df291f6f53ab239 @@ -26,4 +27,5 @@ build() { DESTDIR=$PKG ./INSTALL.sh install -m644 $SRC/$name.repo $PKG/etc/$name.repo install -m644 $SRC/$name.conf $PKG/etc/$name.conf + install -m755 $SRC/portsync $PKG/usr/bin/portsync }