├── package.json ├── .gitignore ├── README.md └── bin └── postman-updater /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postman-updater-linux", 3 | "version": "0.0.2", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "Aniket Panse ", 11 | "license": "Apache-2.0", 12 | "directories": { 13 | "lib": "lib", 14 | "bin": "bin" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # PLATFORM 2 | # ======== 3 | # All exclusions that are specific to the NPM, GIT, IDE and Operating Systems. 4 | 5 | # - Do not allow installed node modules to be committed. Doing `npm install -d` will bring them in root or other places. 6 | node_modules 7 | 8 | # - Do not commit any log file from anywhere 9 | *.log 10 | *.log.* 11 | 12 | # - Prevent addition of OS specific file explorer files 13 | Thumbs.db 14 | .DS_Store 15 | 16 | # Prevent IDE stuff 17 | .idea 18 | 19 | 20 | # PROJECT 21 | # ======= 22 | # Configuration pertaining to project specific repository structure. 23 | 24 | # - Prevent Sublime text IDE files from being commited to repository 25 | *.sublime-* 26 | 27 | # - Allow sublime text project file to be commited in the development directory. 28 | !/develop/*.sublime-project 29 | 30 | # - Prevent CI output files from being Added 31 | /out/ 32 | /newman/ 33 | 34 | # - Prevent diff backups from SourceTree from showing as commit. 35 | *.BACKUP.* 36 | *.BASE.* 37 | *.LOCAL.* 38 | *.REMOTE.* 39 | *.orig 40 | 41 | # Prevent unit test coverage reports from being added 42 | .coverage 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Postman Updater (for Linux) 2 | 3 | # Deprecated 4 | 5 | > You can now install Postman from the [Ubuntu snap store](https://snapcraft.io/postman), so please do that. 6 | 7 | This is a simple bash script, which allows you to update the Postman Linux app, 8 | straight from the terminal. 9 | 10 | ## Installation 11 | 12 | ### 1. Using NPM 13 | ```bash 14 | $ npm install -g postman-updater-linux 15 | ``` 16 | 17 | ### 2. Manually 18 | 19 | Copy the [`postman-updater`](https://github.com/czardoz/postman-updater-linux/blob/master/bin/postman-updater) script 20 | to your $PATH, and make it executable. Remember to change the path, if you 21 | do not want to install it to `/usr/local/bin`: 22 | 23 | ```bash 24 | # curl -o /usr/local/bin/postman-updater https://raw.githubusercontent.com/postmanlabs/postman-updater-linux/master/bin/postman-updater 25 | # chmod +x /usr/local/bin/postman-updater 26 | ``` 27 | 28 | ## Usage 29 | 30 | By default, `postman-updater` assumes that the installation happens in `/opt/postman`. You can 31 | override this by providing a command line flag, `-l /your/path`. If you are _not_ installing to any 32 | system directory, you will not have to use sudo in any of the following commands. 33 | 34 | #### 1. Checking for updates 35 | 36 | You can check if updates are available: 37 | ```bash 38 | sudo postman-updater check 39 | ``` 40 | 41 | Or, with a custom install location: 42 | ```bash 43 | postman-updater check -l /your/custom/path 44 | ``` 45 | 46 | #### 2. Installing Postman 47 | 48 | You can install Postman to a path: 49 | ```bash 50 | sudo postman-updater install # by default, installs to /opt/postman 51 | ``` 52 | 53 | Or, with a custom install location: 54 | ```bash 55 | postman-updater install -l /your/custom/path 56 | ``` 57 | 58 | #### 3. Updating Postman 59 | 60 | This will update Postman, with default installation directory set to `/opt/postman`. 61 | 62 | ```bash 63 | sudo postman-updater update 64 | ``` 65 | 66 | You can change the default location with the `-l` flag: 67 | 68 | ```bash 69 | postman-updater update -l /your/custom/path 70 | ``` 71 | -------------------------------------------------------------------------------- /bin/postman-updater: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Set python's encoding. 4 | PYTHONIOENCODING=utf8; 5 | 6 | # Helper vars 7 | _TRUE_="true"; 8 | _FALSE_="false"; 9 | 10 | LOCATION="/opt/Postman" # Default install/update location 11 | VERSION="latest" # Default to latest version 12 | 13 | function __debug { 14 | if [[ ${PM_DEBUG} == "true" ]]; then 15 | echo "[*] [DEBUG] " $@ >&2; 16 | fi 17 | } 18 | 19 | function usage { 20 | echo "Usage:"; 21 | echo " postman-updater -h Display this help message."; 22 | echo " postman-updater check [-l INSTALL_DIRECTORY] Check for updates."; 23 | echo " postman-updater update [-l INSTALL_DIRECTORY] Update to the latest version."; 24 | echo " postman-updater install [-l INSTALL_DIRECTORY] Install the latest version of Postman."; 25 | exit 0; 26 | } 27 | 28 | function is_installed { 29 | local LOCATION=$1; 30 | local PKG_JSON_LOCATION=${LOCATION}/app/resources/app/package.json; 31 | 32 | __debug "Checking if Postman is already installed in location: " ${LOCATION}; 33 | 34 | if [[ -f ${PKG_JSON_LOCATION} ]]; then 35 | __debug "Found an installation of Postman." 36 | echo ${_TRUE_}; 37 | else 38 | __debug "Did not find a Postman installation." 39 | echo ${_FALSE_}; 40 | fi 41 | } 42 | 43 | function get_installed_version { 44 | local LOCATION=$1; 45 | local PKG_JSON_LOCATION=${LOCATION}/app/resources/app/package.json; 46 | 47 | __debug "Fetching version of currently installed Postman from location: " ${LOCATION}; 48 | 49 | if [[ $(is_installed "${LOCATION}") == $_TRUE_ ]]; then 50 | local INSTALLED_VERSION=$(cat ${PKG_JSON_LOCATION} | \ 51 | python -c "import sys, json; print(json.load(sys.stdin)['version'])"); 52 | __debug "Postman is installed! The version is: " ${INSTALLED_VERSION}; 53 | echo ${INSTALLED_VERSION}; 54 | else 55 | __debug "Cannot get installed version: Postman is not installed!"; 56 | echo ""; 57 | fi 58 | } 59 | 60 | function get_latest_version { 61 | __debug "Fetching the latest version from Postman's app release server"; 62 | local LATEST_VERSION=$(curl -s 'https://dl.pstmn.io/changelog?channel=stable&platform=linux' | \ 63 | python -c "import sys, json; print(json.load(sys.stdin)['changelog'][0]['name'])"); 64 | __debug "Latest version is: " ${LATEST_VERSION}; 65 | echo ${LATEST_VERSION}; 66 | } 67 | 68 | function check_update { 69 | # if installed, find out the installed version. 70 | if [[ $(is_installed "${LOCATION}") == $_TRUE_ ]]; then 71 | local INSTALLED_VERSION=$(get_installed_version "${LOCATION}"); 72 | local LATEST_VERSION=$(get_latest_version); 73 | if [[ ${LATEST_VERSION} != ${INSTALLED_VERSION} ]]; then 74 | echo "Update available!" 75 | echo " Latest version : " ${LATEST_VERSION}; 76 | echo " Installed version : " ${INSTALLED_VERSION}; 77 | else 78 | echo "Great, you have the latest version installed!"; 79 | fi 80 | else 81 | echo "No local installation of Postman found!"; 82 | fi 83 | } 84 | 85 | function get_current_arch { 86 | if [ $(uname -m) == 'x86_64' ]; then 87 | echo "64"; 88 | else 89 | echo "32"; 90 | fi 91 | } 92 | 93 | function install_postman { 94 | local ARCH=$(get_current_arch); 95 | local TMP_DIR="/tmp/_postman_tmp"; 96 | local TARBALL="${TMP_DIR}/postman.tar.gz"; 97 | local LATEST_VERSION=$(get_latest_version); 98 | local LATEST_VERSION_URL="https://dl.pstmn.io/download/version/${LATEST_VERSION}/linux${ARCH}"; 99 | 100 | mkdir -p ${TMP_DIR}; 101 | 102 | __debug "Downloading from URL:" ${LATEST_VERSION_URL}; 103 | curl -o "${TARBALL}" "$LATEST_VERSION_URL"; 104 | 105 | _UPD_PM_RETURN=$(pwd); 106 | cd ${TMP_DIR}; 107 | tar -xf ${TARBALL}; 108 | 109 | # Make sure that the Postman executable is available in the extracted folder. 110 | if [[ -x "${TMP_DIR}/Postman" ]]; then 111 | mkdir -p ${LOCATION}; 112 | 113 | # remove the existing location 114 | rm -r ${LOCATION}; 115 | 116 | # move the temporary directory to the actual location. 117 | mv "${TMP_DIR}/Postman" ${LOCATION}; 118 | else 119 | echo "Oops, we might have a corrupt archive downloaded. Aborting installation."; 120 | fi 121 | } 122 | 123 | function update_postman { 124 | if [[ $(is_installed "${LOCATION}") == $_FALSE_ ]]; then 125 | echo "Postman is not installed in ${LOCATION}. No update can be performed."; 126 | else 127 | install_postman; 128 | fi 129 | } 130 | 131 | function _parse_subcommand_opts { 132 | local ALL_ARGS=$1; 133 | __debug "Parsing subcommand opts," ${ALL_ARGS} 134 | while getopts ":l:" SUB_OPT; do 135 | case ${SUB_OPT} in 136 | l ) 137 | LOCATION=${OPTARG}; 138 | ;; 139 | esac 140 | done 141 | } 142 | 143 | # Parse options to the command 144 | while getopts ":h" OPTION; do 145 | case ${OPTION} in 146 | h ) 147 | usage; 148 | ;; 149 | \? ) 150 | echo "Invalid Option: -$OPTARG" 1>&2; 151 | exit 1; 152 | ;; 153 | esac 154 | done 155 | shift $((OPTIND -1)) 156 | 157 | # Extract & remove the subcommand from the list of CLI args 158 | SUB_CMD=$1; shift; 159 | 160 | # parse the rest of the args as options. 161 | _parse_subcommand_opts $@; 162 | 163 | case "$SUB_CMD" in 164 | check) 165 | check_update; 166 | ;; 167 | update) 168 | update_postman; 169 | ;; 170 | install) 171 | install_postman; 172 | ;; 173 | "") 174 | usage; 175 | ;; 176 | \? ) 177 | echo "Invalid Sub-Command: $SUB_CMD" 1>&2; 178 | usage; 179 | exit 1; 180 | ;; 181 | esac 182 | --------------------------------------------------------------------------------