Skip to content

Instantly share code, notes, and snippets.

@kamoljan
Created July 26, 2016 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamoljan/8f78a64a18b34354e03caf416be97896 to your computer and use it in GitHub Desktop.
Save kamoljan/8f78a64a18b34354e03caf416be97896 to your computer and use it in GitHub Desktop.
#!/bin/bash
#read user inputs
echo Git Username:
read GITNAME
echo Git Password:
read GITPASS
echo DCOS URL:
read DCOSURL
echo DCOS Access Token:
read DCOSTKN
echo -e "Enter \n 1 to restore all marathon apps \n 2 to deploy a particular marathon app"
read CHOICE
base_path=$(pwd)
if [ "${CHOICE}" = "1" ]; then
filename="$1"
#filename=git-repos
#dcos package install jenkins --options=jenkins-config.json
echo reading $filename
while read p
do
IFS=',' read -r giturl pathString <<< "$p"
echo "Git-url: $giturl"
git clone https://$GITNAME:$GITPASS@$giturl
repo=${giturl#*/}
repo=${repo#*/}
repo=${repo%.*}
#repo2=$(basename $giturl)
#echo $repo
echo "comma-separated path: $pathString"
IFS=","
for path in $pathString
do
cd $base_path/$repo/
echo "deploying"$path
curl -X POST $DCOSURL/service/marathon/v2/apps -d @$path -H "Content-Type: application/json" -H "Authorization:token=$DCOSTKN";
done
cd $base_path
done < "$filename"
else
echo "Enter the Marathon app config path, Eg: https://github.com/some-repo/marathon.json :"
read appurl
echo "marathon app url:"$appurl
repourl="${appurl#*.com/}"
repo="${repourl%%/*}"
folderurl=${repourl#*/}
folder=${folderurl%%/*}
path=${folderurl#*/}
giturl="github.com/$repo/$folder.git"
echo "Repository="$folder
echo "Path to config file="$path
echo "giturl="$giturl
git clone https://$GITNAME:$GITPASS@$giturl
cd $base_path/$folder
ls -la
curl -X POST $DCOSURL/service/marathon/v2/apps -d @$path -H "Content-Type: application/json" -H "Authorization:token=$DCOSTKN";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment