├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── updateutility.sh /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at epsteina@wit.edu. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ### First off, thank you for considering contributing to bsupdate. 4 | 5 | #### 1. Where do I go from here? 6 | 7 | If you've noticed a bug or have a question, search the issue tracker to see if someone else in the community has already created a ticket. If not, go ahead and make one! 8 | 9 | 10 | #### 2. Fork & Clone The Repository 11 | * Fork the repo 12 | * Clone your fork ```git clone https://github.com/[YOUR_USERNAME_HERE]/bsupdate``` 13 | 14 | 15 | #### 3. Implement your fix or feature 16 | 17 | At this point, you're ready to make your changes! Feel free to ask for help; everyone is a beginner at first :smile_cat: 18 | 19 | #### 4. Check The Application Runtime 20 | 21 | Try running the utility and check the four test cases 22 | * What happens when you respond no to the update (the update shouldn't occur) 23 | * What happens when your internet is off and you try to run the utility (it should show an error saying there is no internet) 24 | * What happens when you say yes to the update (it should update the configured application) 25 | * What happens when you run the utility on an application where an update is available (it should ask the user if they want to update) 26 | * What happens when you run the utility on an application where an update isn't available (it should ware you that you already have the latest version) 27 | 28 | #### 6. Create A Pull Request 29 | 30 | First make sure to commit and push your changes to your forked repository. 31 | Check to see if there are any conflicts with the main repository and your fork. 32 | If there are none submit the request and give details as to what you changed or added. 33 | 34 | #### 7. Bask In All The Glory Of Adding To A FOSS Application 35 | ![Had to do it to em](https://68.media.tumblr.com/2dfc3369827df9b981e111d7fd8fc732/tumblr_mvemcyarmn1rslphyo1_400.gif) 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alex Epstein 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # bsupdate 4 | 5 | ### (Bash Script Update) 6 | #### A lightweight drop in bash script that can be added to any bash application/CLI to automate updating 7 | ##### Less then 4 KB 8 | 9 | If you have a bash application/script that has an installer script and you host the project on github this script can automate updating. 10 | 11 | ![Usage](https://media.giphy.com/media/xUPGcszQZQWbPn4d8I/giphy.gif) 12 | 13 |
14 | 15 | ## Usage 16 | * First clone the repository. ```git clone https://github.com/alexanderepstein/bsupdate``` 17 | * Git checkout to the latest stable version ```git checkout v2.2.1``` 18 | * Then edit the update utility.sh file located in the repository and change the variables at the top of the file to configure your updates. Read the comments on the variables to make sure that you do this correctly 19 | * Run chmod on the updateutility.sh file to make it executable ```chmod a+x updateutility.sh``` 20 | * Copy the file over to the root directory of your project 21 | * In the main script of your application add the ability to use either -u or --update and run my update utility.sh file (Look at the section on this on the README if don't already know how to implement this) 22 | * Inside of your installer script make sure to copy this file next to wherever your main application script sits so the previous step works as expected 23 | * Make sure to check the assumptions section of the README as if these assumptions are not met it will not work without some tinkering 24 | 25 | ## Assumptions 26 | * All updates come through the form of github releases. 27 | * Releases for unstable versions do not change the number on the version tag but add either a,b,rc to the end. The updater will not consider these as updates to end users. 28 | 29 | ## Adding the -u/--update functionality in your script 30 | 31 | ### The latter of the two options presented here allows for both -u and --update while the first only works with -u 32 | 33 | #### If you are already using bash options this is what adding the -u functionality would look like 34 | ``` bash 35 | while getopts ":uht:" opt; do 36 | case $opt in 37 | \?) 38 | echo "Invalid option: -$OPTARG" >&2 39 | exit 1 40 | ;; 41 | t) 42 | #do stuff 43 | ;; 44 | h) 45 | #do stuff 46 | ;; 47 | u) 48 | ./updateutility.sh #calling the update utility 49 | ;; 50 | :) 51 | echo "Option -$OPTARG requires an argument." >&2 52 | exit 1 53 | ;; 54 | esac 55 | done 56 | ``` 57 | 58 | #### If you aren't using bash options then it would make more sense to do the following at the top of your script 59 | ``` bash 60 | if [[ "$1" == "--update" || "$1" == "-u" ]]; then 61 | ./updateutility.sh ## calling the update utility 62 | exit 0 63 | fi 64 | ``` 65 | #### If you want to circumvent adding the file to your code you can just copy paste the code (after cloning b/c of copy paste issue in browsers w/ code) into the main script of your CLI 66 | Then use either one of the above examples but instead of calling ```./updateutility.sh``` just call 67 | ```bash 68 | getConfiguredClient || exit 1 69 | checkInternet || exit 1 70 | 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 71 | update || exit 1 72 | ``` 73 | 74 | ## But you update this repository so how do I automate updating the updater? 75 | There is no quick way to do this as the updater requires information from the user so it cannot just replace the code without having access to these variables. 76 | I could workaround around this by having two files, but that would make it harder for the end user to implement whereas this is supposed to be simple to setup. 77 | For now just it would make sense to watch the repository if you use it so that you will be notified for updates to bsupdate and can implement new versions of the updater as you see fit. 78 | 79 | ## Donate 80 | If this project helped you in any way and you feel like buying a broke college kid a cup of coffee 81 | 82 | [![Donate](https://img.shields.io/badge/Donate-Venmo-blue.svg)](https://venmo.com/AlexanderEpstein) 83 | [![Donate](https://img.shields.io/badge/Donate-SquareCash-green.svg)](https://cash.me/$AlexEpstein) 84 | 85 | ## License 86 | 87 | MIT License 88 | 89 | Copyright (c) 2017 Alex Epstein 90 | 91 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 92 | 93 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 94 | 95 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 96 | -------------------------------------------------------------------------------- /updateutility.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Author: Alexander Epstein https://github.com/alexanderepstein 3 | # Update utility version 2.2.1 4 | # To test the tool enter in the defualt values that are in the examples for each variable 5 | currentVersion="" #This version variable should not have a v but should contain all other characters ex Github release tag is v1.2.4 currentVersion is 1.2.4 6 | repositoryName="" #Name of repostiory to be updated ex. Sandman-Lite 7 | githubUserName="" #username that hosts the repostiory ex. alexanderepstein 8 | nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one 9 | 10 | 11 | ## This function determines which http get tool the system has installed and returns an error if there isnt one 12 | getConfiguredClient() 13 | { 14 | if command -v curl &>/dev/null; then 15 | configuredClient="curl" 16 | elif command -v wget &>/dev/null; then 17 | configuredClient="wget" 18 | elif command -v http &>/dev/null; then 19 | configuredClient="httpie" 20 | elif command -v fetch &>/dev/null; then 21 | configuredClient="fetch" 22 | else 23 | echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed\." >&2 24 | return 1 25 | fi 26 | } 27 | 28 | ## Allows to call the users configured client without if statements everywhere 29 | httpGet() 30 | { 31 | case "$configuredClient" in 32 | curl) curl -A curl -s "$@" ;; 33 | wget) wget -qO- "$@" ;; 34 | httpie) http -b GET "$@" ;; 35 | fetch) fetch -q "$@" ;; 36 | esac 37 | } 38 | 39 | update() 40 | { 41 | if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" || $latestVersion == "" ]];then 42 | echo "Error: update utility has not been configured correctly." >&2 43 | return 1 44 | else 45 | if [[ "$latestVersion" != "$currentVersion" ]]; then 46 | echo "Version $latestVersion available" 47 | echo -n "Do you wish to update $repositoryName [Y/n]: " 48 | read -r answer 49 | if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then 50 | cd ~ || { echo 'Update Failed' ; return 1 ; } 51 | if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Error: permissions denied deleting old clone, try running thr update as sudo" ; return 1 ; }; fi 52 | git clone "https://github.com/$githubUserName/$repositoryName" || { echo "Couldn't download latest version" ; return 1; } 53 | cd $repositoryName || { echo 'Update Failed' ; return 1 ;} 54 | 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." 55 | #chmod a+x install.sh #this might be necessary in your case but wasnt in mine. 56 | "./$nameOfInstallFile" || return 1 # could echo error here about sudo but I assume you handle errors in your own script correctly 57 | cd .. 58 | rm -r -f $repositoryName || { echo "Error: successfully updated but couldn't delete temperary files at ~/$repositoryName"; return 1; } 59 | else 60 | return 1 61 | fi 62 | else 63 | echo "$repositoryName is already the latest version" 64 | fi 65 | fi 66 | } 67 | 68 | checkInternet() 69 | { 70 | httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request 71 | } 72 | 73 | 74 | getConfiguredClient || exit 1 75 | checkInternet || exit 1 76 | 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 77 | update || exit 1 78 | --------------------------------------------------------------------------------