aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-repositories
blob: 132d7587f86a1f638acc17e2048a90084d21e9f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/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="$(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-pack_z_block "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 "TODO"
    echo "index | add | publish | update"
	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