Skip to content

Instantly share code, notes, and snippets.

@Judas
Created August 2, 2016 10:00
Show Gist options
  • Save Judas/9846446dc7e8a8f3e8aefd6c70c64fe6 to your computer and use it in GitHub Desktop.
Save Judas/9846446dc7e8a8f3e8aefd6c70c64fe6 to your computer and use it in GitHub Desktop.
Custom script to manage local/remote development environment
#!/bin/sh
function sync {
if ! [ -e "/usr/local/bin/repo" ] ; then
echo "[repoid] ==> Downloading repo script"
curl -s https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
fi
echo "[repoid] ==> Initializing repositories"
repo init -u https://github.com/yourorg/yourproject.git -b develop
echo "[repoid] ==> Starting sync"
repo sync
echo "[repoid] ==> Setting up modules"
for module in modules/*/ ; do
cd ${module}
echo "[repoid] ==> Initializing ${module}"
git checkout master
git pull origin master
git checkout develop
git pull origin develop
git flow init -d
cd ~-
done
echo "[repoid] ==> Sync completed!"
}
function buildGradleLocal {
echo "[repoid] ==> Updating build.gradle for $1"
sed -i '' "s/com.iadvize.android.debug://" $1/build.gradle
sed -i '' "s/com.iadvize.android.release://" $1/build.gradle
sed -i '' "s/ { transitive = true }//" $1/build.gradle
sed -i '' "s/:.*@aar')$/')/" $1/build.gradle
sed -i '' "s/:.*@aar'$/'/" $1/build.gradle
sed -i '' "s/debugCompile('\(.*\)')$/debugCompile project(path: ':\1', configuration: 'debug')/" $1/build.gradle
sed -i '' "s/debugCompile '\(.*\)'$/debugCompile project(path: ':\1', configuration: 'debug')/" $1/build.gradle
sed -i '' "s/releaseCompile('\(.*\)')$/releaseCompile project(path: ':\1', configuration: 'release')/" $1/build.gradle
sed -i '' "s/releaseCompile '\(.*\)'$/releaseCompile project(path: ':\1', configuration: 'release')/" $1/build.gradle
}
function setupLocal {
echo "[repoid] ==> Setting up modules to LOCAL architecture"
echo "[repoid] ==> Updating settings.gradle"
rm settings.gradle
touch settings.gradle
printf "include ':community-app'" >> settings.gradle
for module in modules/*/ ; do
moduleShort=`echo "${module}" | sed -e "s/modules\///g" | sed -e "s/\/$//"`
printf ",':${moduleShort}'" >> settings.gradle
moduleShortSample="${moduleShort}-sample"
if [ -d "${module}${moduleShortSample}" ] ; then
printf ",':${moduleShortSample}'" >> settings.gradle
fi
done
echo "" >> settings.gradle
for module in modules/*/ ; do
moduleShort=`echo "${module}" | sed -e "s/modules\///g" | sed -e "s/\/$//"`
echo "project(':${moduleShort}').projectDir = new File('${module}${moduleShort}')" >> settings.gradle
moduleShortSample="${moduleShort}-sample"
if [ -d "${module}${moduleShortSample}" ] ; then
echo "project(':${moduleShortSample}').projectDir = new File('${module}${moduleShortSample}')" >> settings.gradle
fi
done
echo "[repoid] ==> Updating build.gradle"
while read line ; do
if [[ ${line} == *"google"* ]] ; then
sed -i '' "s/dependencies {/dependencies { ${line}/" build.gradle
fi
done < modules/notification-service/build.gradle
buildGradleLocal community-app
for module in modules/*/ ; do
moduleShort=`echo "${module}" | sed -e "s/modules\///g" | sed -e "s/\/$//"`
buildGradleLocal ${module}${moduleShort}
moduleShortSample="${moduleShort}-sample"
if [ -d "${module}${moduleShortSample}" ] ; then
buildGradleLocal ${module}${moduleShortSample}
fi
done
echo "[repoid] ==> You are now in LOCAL architecture"
}
function gitStatus {
git status | sed -e "/^$(printf '\t')\(.*\)$/! d" | sed -e "s/^$(printf '\t')\(.*\)$/[$1] \1/g"
}
function status {
echo "================================================================"
gitStatus community-app
for module in modules/*/ ; do
moduleShort=`echo "${module}" | sed -e "s/modules\///g" | sed -e "s/\/$//"`
cd ${module}${moduleShort}
gitStatus ${moduleShort}
cd ~-
done
echo "================================================================"
}
function setupRemote {
echo "[repoid] ==> Setting up modules to REMOTE architecture..."
git checkout settings.gradle
git checkout build.gradle
git checkout community-app/build.gradle
for module in modules/*/ ; do
moduleShort=`echo "${module}" | sed -e "s/modules\///g" | sed -e "s/\/$//"`
cd ${module}${moduleShort}
git checkout build.gradle
cd ~-
moduleShortSample="${moduleShort}-sample"
if [ -d "${module}${moduleShortSample}" ] ; then
cd ${module}${moduleShortSample}
git checkout build.gradle
cd ~-
fi
done
echo "[repoid] ==> You are now in REMOTE architecture"
status
}
function printHelp {
echo ""
echo "USAGE: repoid [command]"
echo " help Shows this help message."
echo " sync Synchronizes the dependencies project, initializing them if needed."
echo " status Prints the status of all current repositories"
echo " local Updates projects dependencies to use local modules."
echo " remote Updates projects dependencies to use remote module artifacts."
}
case $1 in
"sync")
sync
;;
"local")
setupLocal
;;
"remote")
setupRemote
;;
"status")
status
;;
"help")
printHelp
;;
*)
echo "[repoid] ==> Wrong argument"
printHelp
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment