#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'" global configuredClient := ''"" global private := '"0'" ## state of private flag global all := '"0'" ## state of all flag if test -d ~/temp{ rm -rf ~/temp; } ## if the temp folder exists we want to delete it just in case it was left over from a fatal error ## This function determines which http get tool the system has installed and returns an error if there isnt one proc getConfiguredClient { if command -v curl &>/dev/null ; { global configuredClient := '"curl'" } elif command -v wget &>/dev/null ; { global configuredClient := '"wget'" } elif command -v fetch &>/dev/null ; { global configuredClient := '"fetch'" } else { echo "Error: This tool reqires either curl, wget, or fetch to be installed." return 1 } } proc checkInternet { echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null !2 > !1 # query google with a get request if test $Status -eq 0 { #check if the output is 0, if so no errors have occured and we have connected to google successfully return 0 } else { echo "Error: no active internet connection" > !2 #sent to stderr return 1 } } ## Allows to call the users configured client without if statements everywhere proc httpGet { matchstr $configuredClient { curl { curl -A curl -s @Argv} wget { wget -qO- @Argv} fetch { fetch -o "..."} } } proc update { # Author: Alexander Epstein https://github.com/alexanderepstein # Update utility version 1.2.0 # To test the tool enter in the defualt values that are in the examples for each variable global repositoryName := '"Bash-Snippets'" #Name of repostiory to be updated ex. Sandman-Lite global githubUserName := '"alexanderepstein'" #username that hosts the repostiory ex. alexanderepstein global nameOfInstallFile := '"install.sh'" # change this if the installer file has a different name be sure to include file extension if there is one global latestVersion := $[httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+] #always grabs the tag without the v option if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" ]]{ echo "Error: update utility has not been configured correctly." > !2 exit 1 } elif [[ $latestVersion == "" ]]{ echo "Error: no active internet connection" > !2 exit 1 } else { if [[ "$latestVersion" != "$currentVersion" ]] { echo "Version $latestVersion available" echo -n "Do you wish to update $repositoryName [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] { cd ~ || do { echo 'Update Failed' ; exit 1 ; } if [[ -d ~/$repositoryName ]] { rm -r -f $repositoryName || do { echo "Permissions Error: try running the update as sudo"; exit 1; } ; } git clone "https://github.com/$githubUserName/$repositoryName" || do { echo "Couldn't download latest version" ; exit 1; } cd $repositoryName || do { echo 'Update Failed' ; exit 1 ;} git checkout "v$latestVersion" !2 > /dev/null || git checkout $latestVersion !2 > /dev/null || echo "Couldn't git checkout to stable release, updating to latest commit." chmod a+x install.sh #this might be necessary in your case but wasnt in mine. ./$nameOfInstallFile "update" || exit 1 cd .. rm -r -f $repositoryName || do { echo "Permissions Error: update succesfull but cannot delete temp files located at ~/$repositoryName delete this directory with sudo"; exit 1; } } else { exit 1 } } else { echo "$repositoryName is already the latest version" } } } ## This grabs the users bitbucket info could be improved by making sure username exists proc getBitbucketInfo { echo -n 'Enter your Bitbucket username: ' read bbUsername if [[ $bbUsername == "1" ]]{ echo "Using github username as bitbucket username" } echo -n 'Enter your Bitbucket password: ' read -s password # -s flag hides password text; } proc backupRepo { global timestamp := $[date | tr " " _ | tr : _] ## we do this because it takes care of changes bitbucket would have made cd ~/temp/github/$repoName || do { echo "Fatal error"; return 1; } if [[ $private == "1" ]]{ httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp is_private=true > /dev/null echo "private" } else { httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp > /dev/null } global originalRepoName := $repoName global repoName := $[echo $repoName | tr '[:upper:]' '[:lower:]] global timestamp := $[echo $timestamp | tr '[:upper:]' '[:lower:]] git remote set-url origin https://$bbUsername:$password@bitbucket.org/$bbUsername/$repoName$timestamp.git > /dev/null || return 1 ## switch the remote over to bitbucket rather than github echo "Uploading $originalRepoName to bitbucket" git push -q --progress origin --all > /dev/null || return 1 ## pushes al files to github and most of the repo history echo "Uploading the tags for $originalRepoName" git push -q --progress origin --tags > /dev/null || return 1 ## have to push tags here since --tags and --all are mutually exclusive echo "Successfully backedup $originalRepoName" rm -rf ~/temp #if we have succesfully backedup the repo we dion't need this anymore and if we do we will recreate it } ## When cloudup is called with no flags proc getGitHubRepoInfo { echo -n 'Enter the name of the repostiory to backup: ' read repoName } ## This grabs github user info could be improved upon by checking if user exists proc getGitHubUserInfo { echo -n 'Enter your Github username: ' read ghUsername } ## function that handles cloning a repository it uses $ghUsername and $repoName proc cloneGitHubRepo { mkdir ~/temp cd || do { echo "Fatal error"; return 1; } mkdir ~/temp/github || do { echo "Fatal error"; return 1; } cd ~/temp/github || do { echo "Fatal error"; return 1; } echo "Cloning $repoName" git clone -q --progress https://github.com/$ghUsername/$repoName || return 1 echo "Successfully cloned $repoName" } ## Grabs the last 100 updated repos and greps to grab the repository names and puts them in an array called repoNames proc getGithubRepoNames { global response := $[httpGet "https://api.github.com/users/$ghUsername/repos?sort=updated&per_page=100" | grep -Eo '"name": "[ a-Z . \/ \\ 0-9 -- _ ]*' | sed s/'"name": "'/""/g] for repo in [$response] { global repoNames := '("'$repo") } } proc usage { echo "Cloudup" echo "Description: Backs up a users github repositories to your bitbucket account." echo " With no flags cloudup will guide you through backing up a single repository" echo "Usage: cloudup [flags] or cloudup [flags] [listOfGHRepoNamesSplitBySpaces]" echo " -p Upload the repositor(y)(ies) as private to bitbucket (must have private repo ability on bitbucket)" echo " -a Backup all github repositories" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Examples:" echo " cloudup" echo " cloudup -p -a" echo " cloudup -p nameOfRepo1 nameOf Repo2" echo " cloudup nameOfRepo" } getConfiguredClient || exit 1 checkInternet || exit 1 while getopts "pauvh" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } p { global private := '"1'" echo "Feature not added yet, for now all backups must be public (can be manually set to private through bitbucket after backup)" > !2 exit 0 } h { usage exit 0 } a { global all := '"1'" } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $# == "1" ]] { if [[ $1 == "update" ]]{ update exit 0 } elif [[ $1 == "help" ]] { usage exit 0 } } elif test $Argc -ge 1{ getGitHubUserInfo || exit 1 getBitbucketInfo || exit 1 echo if [[ $private != "1" ]]{ for i in [@Argv] { ## if private is not on as a flag start rpping through them global repoName := $i echo "Starting to backup $repoName" cloneGitHubRepo || exit 1 backupRepo || do { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; } echo } exit 0 } else { for i in [$(@:2)] { global repoName := $i echo "Starting to backup $repoName" cloneGitHubRepo || exit 1 backupRepo || do { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; } echo } exit 0 } } if [[ $all == "0" ]]{ if [[ $1 == "" ]]{ getGitHubUserInfo || exit 1 getGitHubRepoInfo || exit 1 getBitbucketInfo || exit 1 echo cloneGitHubRepo || exit 1 backupRepo || do { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; } exit 0 } else { getGitHubUserInfo || exit 1 global repoName := $1 || exit 1 getBitbucketInfo || exit 1 echo cloneGitHubRepo || exit 1 backupRepo || do { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; } exit 0 } } else { getGitHubUserInfo || exit 1 getGithubRepoNames || exit 1 getBitbucketInfo || exit 1 echo for repo in [$(repoNames[@])] { global repoName := $repo echo "Starting to backup $repoName" cloneGitHubRepo || exit 1 backupRepo || do { echo "Error: couldnt backup $repoName to bitbucket"; exit 1; } echo } echo "Successfully backed up all repositories" exit 0 } (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[7])] spids: [7] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredClient) op:Equal rhs:{(DQ )} spids:[12])] spids: [12] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:private) op:Equal rhs:{(DQ (0))} spids:[16])] spids: [16] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:all) op:Equal rhs:{(DQ (0))} spids:[24])] spids: [24] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-d)} {(TildeSubPart prefix:"") (/temp)} {(Lit_Other "]")}) terminator: ) ] action: [ (Sentence child: (C {(rm)} {(-rf)} {(TildeSubPart prefix:"") (/temp)}) terminator: ) ] spids: [-1 43] ) ] spids: [-1 53] ) (FuncDef name: getConfiguredClient body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(curl)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [79] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [87] ) ] spids: [87] ) ] spids: [-1 84] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(wget)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [102] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [110] ) ] spids: [110] ) ] spids: [93 107] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(fetch)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [125] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [133] ) ] spids: [133] ) ] spids: [116 130] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [139 154] ) ] spids: [67] ) spids: [63 66] ) (FuncDef name: checkInternet body: (BraceGroup children: [ (Pipeline children: [ (C {(echo)} {(-e)} { (DQ ("GET http://google.com HTTP/1.0") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) (SimpleCommand words: [{(nc)} {(google.com)} {(80)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [185] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[189]) ] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 209] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[229])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [220 241] ) ] spids: [164] ) spids: [160 163] ) (FuncDef name: httpGet body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredClient"))} arms: [ (case_arm pat_list: [{(curl)}] action: [(C {(curl)} {(-A)} {(curl)} {(-s)} {(DQ ($ VSub_At "$@"))})] spids: [265 266 279 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [282 283 292 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [295 296 305 -1] ) ] spids: [256 262 308] ) ] spids: [253] ) spids: [249 252] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [333] ) ] spids: [333] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [342] ) ] spids: [342] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [351] ) ] spids: [351] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:latestVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//api.github.com/repos/) ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") (/tags) } ) (C {(grep)} {(-Eo)} {(SQ <"\"name\":.*?[^\\\\]\",">)}) (C {(head)} {(-1)}) (C {(grep)} {(-Eo)} {(DQ ("[0-9.]+"))}) ] negated: False ) ] ) left_token: spids: [361 397] ) } spids: [360] ) ] spids: [360] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$currentVersion")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$repositoryName")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$githubUserName")} right: {(DQ )} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$nameOfInstallFile")} right: {(DQ )} ) ) ) ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: update utility has not been configured correctly."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[453])] ) (C {(exit)} {(1)}) ] spids: [-1 444] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$latestVersion")} right: {(DQ )} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[484])] ) (C {(exit)} {(1)}) ] spids: [462 475] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ ($ VSub_Name "$latestVersion"))} right: {(DQ ($ VSub_Name "$currentVersion"))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$latestVersion") (" available"))}) (C {(echo)} {(-n)} { (DQ ("Do you wish to update ") ($ VSub_Name "$repositoryName") (" [Y/n]: ")) } ) (C {(read)} {(-r)} {(answer)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (Y))} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (y))} ) ) ) terminator: ) ] action: [ (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [581] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_d child: {(Lit_Tilde "~") (/) ($ VSub_Name "$repositoryName") } ) ) terminator: ) ] action: [ (Sentence child: (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: try running the update as sudo" ) ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [625] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 613] ) ] spids: [-1 643] ) (AndOr children: [ (C {(git)} {(clone)} { (DQ ("https://github.com/") ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") ) } ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Couldn't download latest version"))}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [659] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cd)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [683] ) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ (v) ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [710] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [724] ) ] ) (C {(echo)} { (DQ ( "Couldn't git checkout to stable release, updating to latest commit." ) ) } ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (C {(chmod)} {(a) (Lit_Other "+") (x)} {(install.sh)}) (AndOr children: [ (C {(./) ($ VSub_Name "$nameOfInstallFile")} {(DQ (update))}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(cd)} {(..)}) (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: update succesfull but cannot delete temp files located at ~/" ) ($ VSub_Name "$repositoryName") (" delete this directory with sudo") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [778] ) ] op_id: Op_DPipe ) ] spids: [-1 572] ) ] else_action: [(C {(exit)} {(1)})] spids: [797 805] ) ] spids: [-1 513] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [808 819] ) ] spids: [493 822] ) ] spids: [318] ) spids: [314 317] ) (FuncDef name: getBitbucketInfo body: (BraceGroup children: [ (C {(echo)} {(-n)} {(SQ <"Enter your Bitbucket username: ">)}) (C {(read)} {(bbUsername)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$bbUsername")} right: {(DQ (1))} ) ) terminator: ) ] action: [(C {(echo)} {(DQ ("Using github username as bitbucket username"))})] spids: [-1 866] ) ] spids: [-1 876] ) (C {(echo)} {(-n)} {(SQ <"Enter your Bitbucket password: ">)}) (C {(read)} {(-s)} {(password)}) ] spids: [835] ) spids: [831 834] ) (FuncDef name: backupRepo body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:timestamp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(date)}) (C {(tr)} {(DQ (" "))} {(_)}) (C {(tr)} {(Lit_Other ":")} {(_)}) ] negated: False ) ] ) left_token: spids: [908 929] ) } spids: [907] ) ] spids: [907] ) (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"") (/temp/github/) ($ VSub_Name "$repoName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Fatal error"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word:{(1)}) terminator: ) ] spids: [943] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$private")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(httpGet)} {(--user)} {($ VSub_Name "$bbUsername") (Lit_Other ":") ($ VSub_Name "$password")} {(https) (Lit_Other ":") (//api.bitbucket.org/1.0/repositories/)} {(--data)} {(Lit_VarLike "name=") ($ VSub_Name "$repoName") ($ VSub_Name "$timestamp")} {(Lit_VarLike "is_private=") (true)} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[998])] ) (C {(echo)} {(DQ (private))}) ] spids: [-1 974] ) ] else_action: [ (SimpleCommand words: [ {(httpGet)} {(--user)} {($ VSub_Name "$bbUsername") (Lit_Other ":") ($ VSub_Name "$password")} {(https) (Lit_Other ":") (//api.bitbucket.org/1.0/repositories/)} {(--data)} {(Lit_VarLike "name=") ($ VSub_Name "$repoName") ($ VSub_Name "$timestamp")} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1031])] ) ] spids: [1010 1036] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:originalRepoName) op: Equal rhs: {($ VSub_Name "$repoName")} spids: [1039] ) ] spids: [1039] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoName) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$repoName")}) (C {(tr)} {(SQ <"[:upper:]">)} {(SQ <"[:lower:]">)}) ] negated: False ) ] ) left_token: spids: [1044 1060] ) } spids: [1043] ) ] spids: [1043] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:timestamp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$timestamp")}) (C {(tr)} {(SQ <"[:upper:]">)} {(SQ <"[:lower:]">)}) ] negated: False ) ] ) left_token: spids: [1064 1080] ) } spids: [1063] ) ] spids: [1063] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(remote)} {(set-url)} {(origin)} {(https) (Lit_Other ":") (//) ($ VSub_Name "$bbUsername") (Lit_Other ":") ($ VSub_Name "$password") (Lit_Other "@") (bitbucket.org/) ($ VSub_Name "$bbUsername") (/) ($ VSub_Name "$repoName") ($ VSub_Name "$timestamp") (.git) } ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1105])] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Uploading ") ($ VSub_Name "$originalRepoName") (" to bitbucket"))}) (AndOr children: [ (SimpleCommand words: [{(git)} {(push)} {(-q)} {(--progress)} {(origin)} {(--all)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1140])] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Uploading the tags for ") ($ VSub_Name "$originalRepoName"))}) (AndOr children: [ (SimpleCommand words: [{(git)} {(push)} {(-q)} {(--progress)} {(origin)} {(--tags)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1174])] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Successfully backedup ") ($ VSub_Name "$originalRepoName"))}) (C {(rm)} {(-rf)} {(TildeSubPart prefix:"") (/temp)}) ] spids: [904] ) spids: [900 903] ) (FuncDef name: getGitHubRepoInfo body: (BraceGroup children: [ (C {(echo)} {(-n)} {(SQ <"Enter the name of the repostiory to backup: ">)}) (C {(read)} {(repoName)}) ] spids: [1217] ) spids: [1213 1216] ) (FuncDef name: getGitHubUserInfo body: (BraceGroup children: [ (C {(echo)} {(-n)} {(SQ <"Enter your Github username: ">)}) (C {(read)} {(ghUsername)}) ] spids: [1243] ) spids: [1239 1242] ) (FuncDef name: cloneGitHubRepo body: (BraceGroup children: [ (C {(mkdir)} {(TildeSubPart prefix:"") (/temp)}) (AndOr children: [ (C {(cd)}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Fatal error"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word:{(1)}) terminator: ) ] spids: [1282] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(mkdir)} {(TildeSubPart prefix:"") (/temp/github)}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Fatal error"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word:{(1)}) terminator: ) ] spids: [1306] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"") (/temp/github)}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Fatal error"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word:{(1)}) terminator: ) ] spids: [1330] ) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Cloning ") ($ VSub_Name "$repoName"))}) (AndOr children: [ (C {(git)} {(clone)} {(-q)} {(--progress)} {(https) (Lit_Other ":") (//github.com/) ($ VSub_Name "$ghUsername") (/) ($ VSub_Name "$repoName") } ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Successfully cloned ") ($ VSub_Name "$repoName"))}) ] spids: [1269] ) spids: [1265 1268] ) (FuncDef name: getGithubRepoNames body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:response) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} { (DQ ("https://api.github.com/users/") ($ VSub_Name "$ghUsername") ("/repos?sort=updated&per_page=100") ) } ) (C {(grep)} {(-Eo)} {(SQ <"\"name\": \"[ a-Z . \\/ \\\\ 0-9 -- _ ]*">)} ) (C {(sed)} {(s/) (SQ <"\"name\": \"">) (/) (DQ ) (/g)}) ] negated: False ) ] ) left_token: spids: [1398 1429] ) } spids: [1397] ) ] spids: [1397] ) (ForEach iter_name: repo iter_words: [{($ VSub_Name "$response")}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoNames) op: PlusEqual rhs: {(ArrayLiteralPart words:[{(DQ ($ VSub_Name "$repo"))}])} spids: [1444] ) ] spids: [1444] ) ] spids: [1441 1452] ) spids: [1437 -1] ) ] spids: [1394] ) spids: [1390 1393] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Cloudup))}) (C {(echo)} {(DQ ("Description: Backs up a users github repositories to your bitbucket account."))} ) (C {(echo)} { (DQ (" With no flags cloudup will guide you through backing up a single repository")) } ) (C {(echo)} {(DQ ("Usage: cloudup [flags] or cloudup [flags] [listOfGHRepoNamesSplitBySpaces]"))} ) (C {(echo)} { (DQ ( " -p Upload the repositor(y)(ies) as private to bitbucket (must have private repo ability on bitbucket)" ) ) } ) (C {(echo)} {(DQ (" -a Backup all github repositories"))}) (C {(echo)} {(DQ (" -u Update Bash-Snippet Tools"))}) (C {(echo)} {(DQ (" -h Show the help"))}) (C {(echo)} {(DQ (" -v Get the tool version"))}) (C {(echo)} {(DQ ("Examples:"))}) (C {(echo)} {(DQ (" cloudup"))}) (C {(echo)} {(DQ (" cloudup -p -a"))}) (C {(echo)} {(DQ (" cloudup -p nameOfRepo1 nameOf Repo2"))}) (C {(echo)} {(DQ (" cloudup nameOfRepo"))}) ] spids: [1461] ) spids: [1457 1460] ) (AndOr children:[(C {(getConfiguredClient)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(checkInternet)})(C {(exit)} {(1)})] op_id:Op_DPipe) (While cond: [(Sentence child:(C {(getopts)} {(DQ (pauvh))} {(opt)}) terminator:)] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$opt")} arms: [ (case_arm pat_list: [{(EscapedLiteralPart token:)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Invalid option: -") ($ VSub_Name "$OPTARG"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1613])] ) (C {(exit)} {(1)}) ] spids: [1602 1603 1622 -1] ) (case_arm pat_list: [{(p)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:private) op: Equal rhs: {(DQ (1))} spids: [1629] ) ] spids: [1629] ) (SimpleCommand words: [ {(echo)} { (DQ ( "Feature not added yet, for now all backups must be public (can be manually set to private through bitbucket after backup)" ) ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1641])] ) (C {(exit)} {(0)}) ] spids: [1625 1626 1650 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1653 1654 1665 -1] ) (case_arm pat_list: [{(a)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:all) op: Equal rhs: {(DQ (1))} spids: [1672] ) ] spids: [1672] ) ] spids: [1668 1669 1678 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1681 1682 1698 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1701 1702 1713 -1] ) (case_arm pat_list: [{(Lit_Other ":")}] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Option -") ($ VSub_Name "$OPTARG") (" requires an argument."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1728])] ) (C {(exit)} {(1)}) ] spids: [1716 1717 1737 -1] ) ] spids: [1595 1599 1740] ) ] spids: [1592 1742] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [-1 1779] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1790 1805] ) ] spids: [-1 1816] ) ] spids: [-1 1762] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-ge)} {(1)} {(Lit_Other "]")}) terminator: ) ] action: [ (AndOr children:[(C {(getGitHubUserInfo)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getBitbucketInfo)})(C {(exit)} {(1)})] op_id:Op_DPipe) (C {(echo)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$private")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (ForEach iter_name: i iter_words: [{(DQ ($ VSub_At "$@"))}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoName) op: Equal rhs: {($ VSub_Name "$i")} spids: [1888] ) ] spids: [1888] ) (C {(echo)} {(DQ ("Starting to backup ") ($ VSub_Name "$repoName"))}) (AndOr children: [(C {(cloneGitHubRepo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (C {(backupRepo)}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ("Error: couldnt backup ") ($ VSub_Name "$originalRepoName") (" to bitbucket") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1913] ) ] op_id: Op_DPipe ) (C {(echo)}) ] spids: [1882 1935] ) spids: [1876 1880] ) (C {(exit)} {(0)}) ] spids: [-1 1868] ) ] else_action: [ (ForEach iter_name: i iter_words: [ { (DQ (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 2)})) spids: [1953 1957] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoName) op: Equal rhs: {($ VSub_Name "$i")} spids: [1964] ) ] spids: [1964] ) (C {(echo)} {(DQ ("Starting to backup ") ($ VSub_Name "$repoName"))}) (AndOr children: [(C {(cloneGitHubRepo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (C {(backupRepo)}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ("Error: couldnt backup ") ($ VSub_Name "$originalRepoName") (" to bitbucket") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1989] ) ] op_id: Op_DPipe ) (C {(echo)}) ] spids: [1961 2011] ) spids: [1951 1959] ) (C {(exit)} {(0)}) ] spids: [1943 2019] ) ] spids: [1818 1830] ) ] spids: [-1 2021] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$all")} right: {(DQ (0))} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Number "$1")} right:{(DQ )}) ) terminator: ) ] action: [ (AndOr children: [(C {(getGitHubUserInfo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [(C {(getGitHubRepoInfo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [(C {(getBitbucketInfo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (C {(echo)}) (AndOr children: [(C {(cloneGitHubRepo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (C {(backupRepo)}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ("Error: couldnt backup ") ($ VSub_Name "$originalRepoName") (" to bitbucket") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [2101] ) ] op_id: Op_DPipe ) (C {(exit)} {(0)}) ] spids: [-1 2055] ) ] else_action: [ (AndOr children: [(C {(getGitHubUserInfo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoName) op: Equal rhs: {($ VSub_Number "$1")} spids: [2137] ) ] spids: [2137] ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (AndOr children: [(C {(getBitbucketInfo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (C {(echo)}) (AndOr children: [(C {(cloneGitHubRepo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (C {(backupRepo)}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ("Error: couldnt backup ") ($ VSub_Name "$originalRepoName") (" to bitbucket") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [2172] ) ] op_id: Op_DPipe ) (C {(exit)} {(0)}) ] spids: [2125 2196] ) ] spids: [-1 2039] ) ] else_action: [ (AndOr children:[(C {(getGitHubUserInfo)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getGithubRepoNames)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getBitbucketInfo)})(C {(exit)} {(1)})] op_id:Op_DPipe) (C {(echo)}) (ForEach iter_name: repo iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [2238 2243] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repoName) op: Equal rhs: {($ VSub_Name "$repo")} spids: [2250] ) ] spids: [2250] ) (C {(echo)} {(DQ ("Starting to backup ") ($ VSub_Name "$repoName"))}) (AndOr children: [(C {(cloneGitHubRepo)}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children: [ (C {(backupRepo)}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ("Error: couldnt backup ") ($ VSub_Name "$repoName") (" to bitbucket") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [2275] ) ] op_id: Op_DPipe ) (C {(echo)}) ] spids: [2247 2297] ) spids: [2236 -1] ) (C {(echo)} {(DQ ("Successfully backed up all repositories"))}) (C {(exit)} {(0)}) ] spids: [2198 2312] ) ] )