aboutsummaryrefslogtreecommitdiff
path: root/modules/ak-repositories
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-04 18:07:39 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-04 18:07:39 +0300
commit0d1777251dea7d35cd774518959b4377673e1cab (patch)
treeb3d7a15725641c9e3d1d7b45150135e1f8ce9a71 /modules/ak-repositories
parent684dd3e038ae90f0fd1f53211ce4d30141e35bf2 (diff)
downloadarching-kaos-tools-0d1777251dea7d35cd774518959b4377673e1cab.tar.gz
arching-kaos-tools-0d1777251dea7d35cd774518959b4377673e1cab.tar.bz2
arching-kaos-tools-0d1777251dea7d35cd774518959b4377673e1cab.zip
Refactoring, modules directory introduced
- All modules are now stored separately from the rest of the bin/ - You can run them now with `ak -m <module> <args>` - Files affected: * bin/ak-articles -> modules/ak-articles * bin/ak-categories -> modules/ak-categories * bin/ak-comments -> modules/ak-comments * bin/ak-files -> modules/ak-files * bin/ak-folders -> modules/ak-folders * bin/ak-mixtapes -> modules/ak-mixtapes * bin/ak-news -> modules/ak-news * bin/ak-reference -> modules/ak-reference * bin/ak-repositories -> modules/ak-repositories * bin/ak-roadmap -> modules/ak-roadmap * bin/ak-todos -> modules/ak-todos
Diffstat (limited to 'modules/ak-repositories')
-rwxr-xr-xmodules/ak-repositories164
1 files changed, 164 insertions, 0 deletions
diff --git a/modules/ak-repositories b/modules/ak-repositories
new file mode 100755
index 0000000..ffda701
--- /dev/null
+++ b/modules/ak-repositories
@@ -0,0 +1,164 @@
+#!/bin/bash
+source $AK_LIBDIR/_ak_zblock
+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="$(_ak_ipfs_add .)"
+ _ak_ipfs_key_gen "$PROJECT.git"
+ _ak_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="$(_ak_ipfs_add .)"
+ _ak_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="$(_ak_ipfs_add .)"
+ _ak_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="$(_ak_ipfs_add .)"
+ try=_ak_ipfs_key_gen "$PROJECT.git"
+ if [ $? == 0 ]
+ then
+ _ak_ipfs_name_publish --key="$PROJECT.git" /ipfs/$IPFS
+ printf '{"project":"%s.git","ipns":"%s"}' $PROJECT $try > data
+ _ak_zblock_pack "repos/add" $PWD/data
+ echo "Done"
+ fi
+ fi
+ else
+ echo "$PROJECT not a git repo"
+ fi
+}
+
+index(){
+ _ak_ipfs_key_list_full | grep -e '\.git'
+}
+
+set-as-profile(){
+ IPFS=$(_ak_ipfs_add $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 "-h, --help"
+ echo "index | add | publish | update"
+ exit
+}
+
+if [ ! -z $1 ]
+then
+ case $1 in
+ -h | --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