diff options
author | kaotisk <kaotisk@arching-kaos.com> | 2021-12-26 06:22:10 +0200 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.com> | 2021-12-26 06:22:10 +0200 |
commit | 52bf926baf3957c799da01d7329db5c8ea07bb22 (patch) | |
tree | 3f9c38a8cd412317a6440981d34e5a8dbb657e1d | |
parent | 0e544652466d338b23ae4356983242d3619445c1 (diff) | |
download | arching-kaos-tools-52bf926baf3957c799da01d7329db5c8ea07bb22.tar.gz arching-kaos-tools-52bf926baf3957c799da01d7329db5c8ea07bb22.tar.bz2 arching-kaos-tools-52bf926baf3957c799da01d7329db5c8ea07bb22.zip |
Added repositories tool
-rwxr-xr-x | bin/repositories | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/bin/repositories b/bin/repositories new file mode 100755 index 0000000..be7c623 --- /dev/null +++ b/bin/repositories @@ -0,0 +1,167 @@ +#!/bin/bash +REPODIR="$HOME/projects" +BAREDIR="$HOME/bare" +REPOSTORE="$HOME/.arching-kaos/repostore" +if [ ! -d $BAREDIR ]; then mkdir $BAREDIR; fi +if [ ! -d $REPODIR ]; then echo "no $REPODIR" && exit; fi +if [ ! -f $REPOSTORE ]; then touch $REPOSTORE; fi +import(){ + REPOS="$(ls -1 $REPODIR)" + for PROJECT in $REPOS + do + cd $BAREDIR + # Can be as well be + # git clone --bare $REPODIR/$PROJECT/.git + # or whatever form git let's you use + git clone --bare http://git.h.kaotisk-hund.com/$PROJECT/.git + if [ $? == 0 ] + then + cd $PROJECT.git + git repack -a + IPFS="$(ipfs add -Qr .)" + ipfs key gen "$PROJECT.git" + ipfs name publish --key="$PROJECT.git" /ipfs/$IPFS + cd $HOME/bare + else + echo "$PROJECT not a git repo" + fi + done +} + +update(){ + if [ ! -z $1 ] + then + USING="$1" + REPO="$REPODIR/$1/.git" + BARE="$BAREDIR/$1.git" + BARENAME="$1.git" + if [ -d $BARE ] + then + cd $BARE + git pull + git repack -a + IPFS="$(ipfs add -Qr .)" + ipfs name publish --key="$BARENAME" /ipfs/$IPFS + echo "DONE" + else + echo "NO BARE TO UPDATE" + echo "updating all..." + fi + else + BARES="$(ls -1 $BAREDIR)" + cd $BAREDIR + for PROJECT in $BARES + do + cd "$PROJECT" + git pull + git repack -a + IPFS="$(ipfs add -Qr .)" + ipfs name publish --key="$PROJECT" /ipfs/$IPFS + cd $BAREDIR + done + fi +} + +append-if-needed(){ + under="$1" + file="$HOME/.arching-kaos/repos" + lines="$(cat $file)" + found="no" + for line in $lines + do + if [ $found == "yes" ] + then + echo "found $found" + break + else + if [ "$line" == "$under" ] + then + found="yes" + echo "found $found" + break + fi + fi + done + if [ $found == "no" ] + then + echo $under > $file + fi +} + + +add(){ + PROJECT="$1" + PROJECTDIR="$REPODIR/$PROJECT" + BAREGITDIR="$BAREDIR/$PROJECT.git" + if [ -d $PROJECTDIR ] + then + cd $HOME/bare + git clone --bare $PROJECTDIR/.git + if [ $? == 0 ] + then + cd $BAREGITDIR + git repack -a + IPFS="$(ipfs add -Qr .)" + try=ipfs key gen "$PROJECT.git" + if [ $? == 0 ] + then + ipfs name publish --key="$PROJECT.git" /ipfs/$IPFS + cat > data <<EOF +{ + "project":"$PROJECT.git", + "ipns":"$try" +} +EOF + pack_z_block "repos/add" data + echo "Done" + fi + fi + else + echo "$PROJECT not a git repo" + fi +} + +index(){ + ipfs key list -l | grep -e '\.git' +} +set-as-profile(){ + IPFS=$(ipfs add -q $REPOSTORE) + if [ $? == 0 ] + then + profile set repositories $IPFS + else + echo error + fi +} + +publish(){ + if [ ! -z $1 ] + then + echo "Filtering for $1..." + index | grep "$1" > $REPOSTORE + set-as-profile + else + echo "Publishing all..." + index > $REPOSTORE + set-as-profile + fi +} + +usage(){ + echo "TODO" + exit +} + +if [ ! -z $1 ] +then + case $1 in + help) usage; exit;; + index) index; exit;; + add) add "$2"; exit;; + publish) publish "$2"; exit;; + update) update "$2"; exit;; + *) echo "No command $1";usage; exit;; + esac +else + usage +fi |