#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'" global configuredClient := ''"" global configuredPython := ''"" ## 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 getConfiguredPython { if command -v python2 &>/dev/null ; { global configuredPython := '"python2'" } elif command -v python &>/dev/null ; { global configuredPython := '"python'" } else { echo "Error: This tool requires python 2 to be installed." return 1 } } proc python { matchstr $configuredPython { python2 { python2 @Argv} python { python @Argv} } } ## 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 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 } } ## This function grabs information about a movie and using python parses the ## JSON response to extrapolate the information for storage proc getMovieInfo { global apiKey := '946f500a' # try not to abuse this it is a key that came from the ruby-scripts repo I link to. global movie := $[echo @Argv | tr " " +] ## format the inputs to use for the api export PYTHONIOENCODING=utf8 #necessary for python in some cases global movieInfo := $[httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey] > /dev/null # query the server and get the JSON response global checkResponse := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Response']" !2 > /dev/null] if [[ $checkResponse == "False" ]]{ do { echo "No movie found" ; return 1 ;} } ## check to see if the movie was found # The rest of the code is just extrapolating the data with python from the JSON response global title := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Title']" !2 > /dev/null] global year := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Year']" !2 > /dev/null] global score := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']" !2 > /dev/null] global rated := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Rated']" !2 > /dev/null] global genre := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Genre']" !2 > /dev/null] global director := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Director']" !2 > /dev/null] global actors := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Actors']" !2 > /dev/null] global plot := $[echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Plot']" !2 > /dev/null] unset movieInfo # don't need this anymore unset checkResponse # don't need this anymore } # Prints the movie information out in a human readable format proc printMovieInfo { echo echo '==================================================' echo "| Title: $title" echo "| Year: $year" if [[ $score != "" ]]{ echo "| Tomato: $score";} if [[ $rated != "N/A" && $rated != "" ]]{ echo "| Rated: $rated";} echo "| Genre: $genre" echo "| Director: $director" echo "| Actors: $actors" if [[ $plot != "N/A" && $plot != "" ]]{ echo "| Plot: $plot"; } echo '==================================================' echo } 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" } } } proc usage { echo "Movies" echo "Description: Provides relevant information about a certain movie." echo "Usage: movies [flag] or movies [movieToSearch]" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Examples:" echo " movies Argo" echo " movies Inception" } getConfiguredPython || exit 1 getConfiguredClient || exit 1 checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here while getopts "uvh" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } h { usage exit 0 } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $# == 0 ]] { usage } elif [[ $1 == "update" ]]{ update } elif [[ $1 == "help" ]]{ usage } else { getMovieInfo @Argv || exit 1 ## exit if we return 1 (chances are movie was not found) printMovieInfo ## print out the data } (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:configuredPython) op:Equal rhs:{(DQ )} spids:[16])] spids: [16] ) (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: [40] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [48] ) ] spids: [48] ) ] spids: [-1 45] ) (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: [63] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [71] ) ] spids: [71] ) ] spids: [54 68] ) (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: [86] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [94] ) ] spids: [94] ) ] spids: [77 91] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [100 115] ) ] spids: [28] ) spids: [24 27] ) (FuncDef name: getConfiguredPython body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(python2)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [137] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python2))} spids: [145] ) ] spids: [145] ) ] spids: [-1 142] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(python)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [160] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python))} spids: [168] ) ] spids: [168] ) ] spids: [151 165] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool requires python 2 to be installed."))}) (ControlFlow token: arg_word:{(1)}) ] spids: [174 189] ) ] spids: [125] ) spids: [121 124] ) (FuncDef name: python body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredPython"))} arms: [ (case_arm pat_list: [{(python2)}] action: [(C {(python2)} {(DQ ($ VSub_At "$@"))})] spids: [211 212 219 -1] ) (case_arm pat_list: [{(python)}] action: [(C {(python)} {(DQ ($ VSub_At "$@"))})] spids: [222 223 230 -1] ) ] spids: [202 208 233] ) ] spids: [199] ) spids: [195 198] ) (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: [257 258 271 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [274 275 284 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [287 288 297 -1] ) ] spids: [248 254 300] ) ] spids: [245] ) spids: [241 244] ) (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: [331] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[335]) ] ) ] 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 355] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[375])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [366 387] ) ] spids: [310] ) spids: [306 309] ) (FuncDef name: getMovieInfo body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:apiKey) op:Equal rhs:{(946f500a)} spids:[405])] spids: [405] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:movie) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_At "$@"))}) (C {(tr)} {(DQ (" "))} {(Lit_Other "+")}) ] negated: False ) ] ) left_token: spids: [413 430] ) } spids: [412] ) ] spids: [412] ) (C {(export)} {(Lit_VarLike "PYTHONIOENCODING=") (utf8)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:movieInfo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ("http://www.omdbapi.com/?t=") ($ VSub_Name "$movie") ("&apikey=") ($ VSub_Name "$apiKey") ) } ) ] ) left_token: spids: [446 455] ) } spids: [445] ) ] spids: [445] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:checkResponse) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Response']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [481] ) ] ) ] negated: False ) ] ) left_token: spids: [466 484] ) } spids: [465] ) ] spids: [465] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$checkResponse")} right: {(DQ (False))} ) ) terminator: ) ] action: [ (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("No movie found"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word:{(1)}) terminator: ) ] spids: [503] ) ] spids: [-1 501] ) ] spids: [-1 520] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:title) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ("import sys, json; print json.load(sys.stdin)['Title']")) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [546] ) ] ) ] negated: False ) ] ) left_token: spids: [531 549] ) } spids: [530] ) ] spids: [530] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:year) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} {(DQ ("import sys, json; print json.load(sys.stdin)['Year']"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [568] ) ] ) ] negated: False ) ] ) left_token: spids: [553 571] ) } spids: [552] ) ] spids: [552] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:score) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [590] ) ] ) ] negated: False ) ] ) left_token: spids: [575 593] ) } spids: [574] ) ] spids: [574] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rated) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ("import sys, json; print json.load(sys.stdin)['Rated']")) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [612] ) ] ) ] negated: False ) ] ) left_token: spids: [597 615] ) } spids: [596] ) ] spids: [596] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:genre) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ("import sys, json; print json.load(sys.stdin)['Genre']")) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [634] ) ] ) ] negated: False ) ] ) left_token: spids: [619 637] ) } spids: [618] ) ] spids: [618] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:director) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Director']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [656] ) ] ) ] negated: False ) ] ) left_token: spids: [641 659] ) } spids: [640] ) ] spids: [640] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:actors) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Actors']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [678] ) ] ) ] negated: False ) ] ) left_token: spids: [663 681] ) } spids: [662] ) ] spids: [662] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:plot) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$movieInfo")}) (SimpleCommand words: [ {(python)} {(-c)} {(DQ ("import sys, json; print json.load(sys.stdin)['Plot']"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [700] ) ] ) ] negated: False ) ] ) left_token: spids: [685 703] ) } spids: [684] ) ] spids: [684] ) (C {(unset)} {(movieInfo)}) (C {(unset)} {(checkResponse)}) ] spids: [402] ) spids: [398 401] ) (FuncDef name: printMovieInfo body: (BraceGroup children: [ (C {(echo)}) (C {(echo)} {(SQ <"==================================================">)}) (C {(echo)} {(DQ ("| Title: ") ($ VSub_Name "$title"))}) (C {(echo)} {(DQ ("| Year: ") ($ VSub_Name "$year"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobNEqual left:{($ VSub_Name "$score")} right:{(DQ )}) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Tomato: ") ($ VSub_Name "$score"))}) terminator: ) ] spids: [-1 773] ) ] spids: [-1 782] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$rated")} right: {(DQ (N/A))} ) right: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$rated")} right: {(DQ )} ) ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Rated: ") ($ VSub_Name "$rated"))}) terminator: ) ] spids: [-1 808] ) ] spids: [-1 817] ) (C {(echo)} {(DQ ("| Genre: ") ($ VSub_Name "$genre"))}) (C {(echo)} {(DQ ("| Director: ") ($ VSub_Name "$director"))}) (C {(echo)} {(DQ ("| Actors: ") ($ VSub_Name "$actors"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$plot")} right: {(DQ (N/A))} ) right: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$plot")} right: {(DQ )} ) ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Plot: ") ($ VSub_Name "$plot"))}) terminator: ) ] spids: [-1 867] ) ] spids: [-1 877] ) (C {(echo)} {(SQ <"==================================================">)}) (C {(echo)}) ] spids: [731] ) spids: [727 730] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [911] ) ] spids: [911] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [920] ) ] spids: [920] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [929] ) ] spids: [929] ) (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: [939 975] ) } spids: [938] ) ] spids: [938] ) (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:[1031])] ) (C {(exit)} {(1)}) ] spids: [-1 1022] ) (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:[1062])] ) (C {(exit)} {(1)}) ] spids: [1040 1053] ) ] 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: [1159] ) ] 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: [1203] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 1191] ) ] spids: [-1 1221] ) (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: [1237] ) ] 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: [1261] ) ] 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: [1288] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1302] ) ] ) (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: [1356] ) ] op_id: Op_DPipe ) ] spids: [-1 1150] ) ] else_action: [(C {(exit)} {(1)})] spids: [1375 1383] ) ] spids: [-1 1091] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [1386 1397] ) ] spids: [1071 1400] ) ] spids: [896] ) spids: [892 895] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Movies))}) (C {(echo)} {(DQ ("Description: Provides relevant information about a certain movie."))}) (C {(echo)} {(DQ ("Usage: movies [flag] or movies [movieToSearch]"))}) (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 (" movies Argo"))}) (C {(echo)} {(DQ (" movies Inception"))}) ] spids: [1410] ) spids: [1406 1409] ) (AndOr children:[(C {(getConfiguredPython)})(C {(exit)} {(1)})] op_id:Op_DPipe) (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 (uvh))} {(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:[1538])] ) (C {(exit)} {(1)}) ] spids: [1527 1528 1547 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1550 1551 1562 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1565 1566 1582 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1585 1586 1597 -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:[1612])] ) (C {(exit)} {(1)}) ] spids: [1600 1601 1621 -1] ) ] spids: [1520 1524 1624] ) ] spids: [1517 1626] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [(C {(usage)})] spids: [-1 1642] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)})] spids: [1647 1661] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)})] spids: [1666 1680] ) ] else_action: [ (AndOr children: [(C {(getMovieInfo)} {(DQ ($ VSub_At "$@"))}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (C {(printMovieInfo)}) ] spids: [1685 1709] ) ] )