Blame view

repos.sh 5.04 KB
16572de04   mj   [IMP] ADD repos.s...
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  #!/bin/bash
  
  # export ADD_REMOTE="NO"
  # export REMOTE_BRANCH="8.0"
  # export PATH_PREFIX=".repos"
  # export PATH_START="addons"
  # export SYMLINKS_PATH="odoo-addons"
  # export ADHOC_PATH="addons-adhoc"
  # export CREATE_LINKS=1
  # export DEF_REPO="XX"
  
  # Build environment from env.txt file
  while read line; do
  	export "$line"
  done < env.txt
  
  export GIT_EDITOR=true
  
  read -e -p "Enter a list of github repos, separated by comma; or enter for update: " -i "" ACTION
  
  if [ "$ACTION" != "" ]; then
  	ADD_ADDON_REPOS=($(printf "$ACTION" | tr "," "
  "))
  	ACTION=""
  else
  	UPDATE="1"
  	i=0
  	j=0
  	while read line; do
      	if [ "$i" -gt "6" ] && [ "$line" != "" ]; then
      		if [ "$line" != "Unsorted (inserted by repos.sh)" ] && [ "$line" != "===============================" ]; then
      			ADD_ADDON_REPOS[$j]=$line
      			j=$[j+1]
      		fi
      	fi
      	i=$[i+1]
  	done < ADD.md
  	# set some vars for updating:
  	ADD_REMOTE="NO"
  	read -e -p "Trying to update $[j+1] repos; enter to continue, input to quit: " -i "" ACTION
  fi
  
  if [ "$ACTION" != "" ]; then
  	exit 0
  else
  	printf "...................................................START..................................................."
  	if [ "$DEF_REPO" ]; then
  		if [ "$DEF_REPO" != "XX" ]; then
  			printf "set var 'ADD_ADDON_REPOS'"
  			ADD_ADDON_REPOS=("$DEF_REPO")
  		fi
  	fi
  	if [ ! "$REMOTE_BRANCH" ]; then
  		REMOTE_BRANCH="8.0"
  	fi
  	if [ ! "$SYMLINKS_PATH" ]; then
  		SYMLINKS_PATH="odoo-addons"
  	fi
  	if [ ! "$PATH_START" ]; then
  		PATH_START="addons"
  	fi
  	if [ ! "$PATH_PREFIX" ]; then
  		PATH_PREFIX=".repos"
  	fi
  	if [ ! "$ADD_REMOTE" ]; then
  		ADD_REMOTE="YES"
  	fi
  	if [ ! "$CREATE_LINKS" ]; then
  		CREATE_LINKS=1
  	fi
  	# :' = Multiline Comment
  	# ADDED_REPOS=":'
  "
  	ADDED_REPOS=""
  	NOT_ADDED_REPOS=""
  	for i in "${ADD_ADDON_REPOS[@]}"; do
  		printf "repo '$i'"
  
  		# Defaults
  		CREATE_LINKS=1
  
  
  		j=($(printf "$i" | tr "~!~" "
  "))
  		if [ ${j[1]} ]; then
  			i=${j[0]}
  			if [ ${j[1]} = "CREATE_LINKS=2" ]; then
  				CREATE_LINKS=2
  			fi
  		fi
  
  		j=($(printf "$i" | tr ":" "
  "))
  		if [ ${j[1]} ]; then
  			i=${j[0]}
  			REMOTE_BRANCH=${j[1]}
  		fi
  		printf "using branch $REMOTE_BRANCH"
  
  		REPO=${i} && REPL="--" && REMOTE=${REPO/\//$REPL}
  		if [ "$UPDATE" = "1" ]; then
  			git fetch --no-tags remote--${REMOTE}
  			SUBTREE_CMD="pull"
  			git subtree ${SUBTREE_CMD} --prefix=${PATH_PREFIX}/${REPO} remote--${REMOTE} ${REMOTE_BRANCH} --squash -q
  
  			while read line; do
  				if [[ ${REPO} == ${line} ]]; then
  					printf "++++++ MATCH ++++++"
  					CREATE_LINKS=0
  				fi
  				printf "+++++ NOMATCH +++++"
  				printf ${REPO}
  			done < ignore.txt
  
  		elif [ "$ADD_REMOTE" = "YES" ]; then
  			git remote add -f --no-tags remote--${REMOTE} https://github.com/${REPO}.git
  			SUBTREE_CMD="add"
  			git subtree ${SUBTREE_CMD} --prefix=${PATH_PREFIX}/${REPO} remote--${REMOTE}/${REMOTE_BRANCH} --squash
  		fi
  		ADDED_REPOS+=${REPO}
  		ADDED_REPOS+='
  '
  
  		if [ "$CREATE_LINKS" != 0 ]; then
  			if [ "$CREATE_LINKS" = 1 ]; then
  				for j in ${PATH_PREFIX}/${REPO}/* ; do
  					if [ -d "$j" ]; then
  						n=${j##*/}
  						if [ $n != "__unported__" ]; then
  							if [ -h ${SYMLINKS_PATH}/$n ]; then
  								printf "symlink exists '${REPO}/$n'"
  								if [ "$ADD_REMOTE" = "YES" ]; then
  									NOT_ADDED_REPOS="$NOT_ADDED_REPOS
  ${REPO}/$n
  "
  								fi
  							else
  								printf "create symlink 1: '${REPO}/$n'"
  								ln -s "../../${PATH_PREFIX}/${REPO}/$n" "${SYMLINKS_PATH}/$n"
  							fi
  							if [ -h ${ADHOC_PATH}/$n ]; then
  								printf "delete adhoc"
  								rm ${ADHOC_PATH}/$n
  							fi
  						fi
  					fi
  				done
  			elif [ "$CREATE_LINKS" = 2 ]; then
  				printf "create symlink 2: '${REPO}/'"
  				REPO_SEP=($(printf "$REPO" | tr "/" "
  "))
  				if [ ${REPO_SEP[1]} ]; then
  					REPO=${REPO_SEP[1]}
  					PATH_PREFIX+="/${REPO_SEP[0]}"
  				fi
  				ln -s ../${PATH_PREFIX}/${REPO} ${SYMLINKS_PATH}/${REPO}
  				PATH_PREFIX=".repos"
  			elif [ "$CREATE_LINKS" = 3 ]; then
  				ln -s ${SYMLINKS_PATH}/${REPO} ${PATH_START}/
  			else
  				ln -s ${SYMLINKS_PATH}/${REPO} ${PATH_START}/${CREATE_LINKS}
  			fi
  			CREATE_LINKS=1
  		fi
  		printf "..................................................DONE................................................."
  	done
  	if [ "$UPDATE" = "1" ]; then
  		printf 'Repos updated:
  ---------------
  ' + "$ADDED_REPOS" + '
  '
  	elif [ "$ADDED_REPOS" != "" ]; then
  		printf "$ADDED_REPOS
  " >> ADD.md
  	fi
  	if [ "$NOT_ADDED_REPOS" != "" ]; then
  		printf "$NOT_ADDED_REPOS" >> exists.txt
  	fi
  	find -name "*.pyc" -delete
  	find -name "*.pyo" -delete
  	find -name "*.pyd" -delete
  	find -name "*.py~" -delete
  	find -name "*.mo" -delete
  	find -name "pip-log.txt" -delete
  	find -name "pip-delete-this-directory.txt" -delete
  	find -name "Thumbs.db" -delete
  	find -name ".directory" -delete
  	find -name ".DS_Store" -delete
  	find -name ".*.kate-swp" -delete
  	find -name ".swp.*" -delete
  	find -name "*.~1~" -delete
  	find -name "*.egg-info" -delete
  	find -name ".installed.cfg" -delete
  	find -name "*.egg" -delete
  	find -name "*.manifest" -delete
  	find -name "*.spec" -delete
  	find -name "*.so" -delete
  	find -name "__MACOSX" -exec rm -r "{}" \;
  	find -name "__pycache__" -exec rm -r "{}" \;
  	find -name "develop-eggs" -exec rm -r "{}" \;
  fi