Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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