diff --git a/repos.sh b/repos.sh new file mode 100755 index 0000000..ba1facd --- /dev/null +++ b/repos.sh @@ -0,0 +1,189 @@ +#!/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 "," "\n")) + 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=":'\n" + ADDED_REPOS="" + NOT_ADDED_REPOS="" + for i in "${ADD_ADDON_REPOS[@]}"; do + printf "repo '$i'" + + # Defaults + CREATE_LINKS=1 + + + j=($(printf "$i" | tr "~!~" "\n")) + if [ ${j[1]} ]; then + i=${j[0]} + if [ ${j[1]} = "CREATE_LINKS=2" ]; then + CREATE_LINKS=2 + fi + fi + + j=($(printf "$i" | tr ":" "\n")) + 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+='\n' + + 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\n${REPO}/$n\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 "/" "\n")) + 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:\n---------------\n' + "$ADDED_REPOS" + '\n' + elif [ "$ADDED_REPOS" != "" ]; then + printf "$ADDED_REPOS\n" >> 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 \ No newline at end of file