Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file.

Copy and paste this line into your terminal to run the script:

curl https://gist.githubusercontent.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043/raw/postman-deb.sh | sh

Or this line if you don't have curl:

wget -O - https://gist.githubusercontent.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043/raw/postman-deb.sh | sh
#!/bin/sh
curlExists=$(command -v curl)
echo "Testing Postman version"
targetName=""
if [ -z $curlExists ]; then
targetName=$(wget -S --spider "https://dl.pstmn.io/download/latest/linux64" 2>&1 | grep "Content-Disposition" | awk -F '=' '{ print $2 }')
else
targetName=$(curl -sI "https://dl.pstmn.io/download/latest/linux64" | grep "content-disposition" | awk -F '=' '{ print $2 }')
fi
versionMaj=$(echo "$targetName" | awk -F '-' '{ print $2 }' | awk -F '.' '{ print $1 }')
versionMin=$(echo "$targetName" | awk -F '-' '{ print $2 }' | awk -F '.' '{ print $2 }')
versionRev=$(echo "$targetName" | awk -F '-' '{ print $2 }' | awk -F '.' '{ print $3 }')
version="$versionMaj.$versionMin-$versionRev"
echo "Most recent Postman version V$version"
current=$(dpkg-query --showformat='${Version}' --show postman 2> /dev/null)
if [ $? -gt 0 ]; then
echo "Postman is not installed"
else
echo "Installed version V$current"
if [ "$current" = "$version" ]; then
echo "The most recent version of Postman is currently installed"
exit
else
echo "Updating Postman to the latest version"
fi
fi
originalPWD="$(pwd)"
targetPWD="$(mktemp -d postman.XXXXXX)"
cd "$targetPWD"
echo "Downloading latest Postman tarball"
if [ -z $curlExists ]; then
wget -q --show-progress "https://dl.pstmn.io/download/latest/linux64" --content-disposition
else
curl -# "https://dl.pstmn.io/download/latest/linux64" -O -J
fi
if [ $? -gt 0 ]; then
echo "Failed to download Postman tarball"
exit
fi
echo "Extracting Postman tarball"
tar -xf $(ls [Pp]ostman*.tar.gz)
if [ $? -gt 0 ]; then
echo "Failed to extract Postman tarball"
exit
fi
echo "Creating 'postman_$version' folder structure and files"
mkdir -m 0755 -p "postman_$version"
mkdir -m 0755 -p "postman_$version/usr/share/applications"
touch "postman_$version/usr/share/applications/Postman.desktop"
mkdir -m 0755 -p "postman_$version/usr/share/icons/hicolor/128x128/apps"
mkdir -m 0755 -p "postman_$version/opt/postman"
mkdir -m 0755 -p "postman_$version/DEBIAN"
touch "postman_$version/DEBIAN/control" "postman_$version/DEBIAN/postinst" "postman_$version/DEBIAN/prerm"
echo "Copying files"
cp "Postman/app/resources/app/assets/icon.png" "postman_$version/usr/share/icons/hicolor/128x128/apps/postman.png"
cp -R "Postman/"* "postman_$version/opt/postman/"
echo "Testing whether to use '-e'"
lines=$(echo "\n" | wc -l)
e=""
if [ $lines -eq 1 ]; then
echo "'-e' is required"
e="-e"
else
echo "'-e' is not required"
fi
echo "Writing files"
echo $e "[Desktop Entry]\nType=Application\nName=Postman\nGenericName=Postman API Tester\nIcon=postman\nExec=postman\nPath=/opt/postman\nCategories=Development;" > "postman_$version/opt/postman/Postman.desktop"
echo $e "Package: Postman\nVersion: $version\nSection: devel\nPriority: optional\nArchitecture: amd64\nDepends: gconf2, libgtk2.0-0, desktop-file-utils\nOptional: libcanberra-gtk-module\nMaintainer: You\nDescription: Postman\n API something" > "postman_$version/DEBIAN/control"
echo $e "if [ -f \"/usr/bin/postman\" ]; then\n\tsudo rm -f \"/usr/bin/postman\"\nfi\n\nsudo ln -s \"/opt/postman/Postman\" \"/usr/bin/postman\"\n\ndesktop-file-install \"/opt/postman/Postman.desktop\"" > "postman_$version/DEBIAN/postinst"
echo $e "if [ -f \"/usr/bin/postman\" ]; then\n\tsudo rm -f \"/usr/bin/postman\"\nfi" > "postman_$version/DEBIAN/prerm"
echo "Setting modes"
chmod 0775 "postman_$version/usr/share/applications/Postman.desktop"
chmod 0775 "postman_$version/DEBIAN/control"
chmod 0775 "postman_$version/DEBIAN/postinst"
chmod 0775 "postman_$version/DEBIAN/prerm"
echo "Validating modes"
nc=""
if [ $(stat -c "%a" "postman_$version/DEBIAN/control") != "775" ]; then
echo "File modes are invalid, calling 'dpkg-deb' with '--nocheck'"
nc="--nocheck"
else
echo "File modes are valid"
fi
echo "Building 'postman_$version.deb'"
dpkg-deb $nc -b "postman_$version" > /dev/null
if [ $? -gt 0 ]; then
echo "Failed to build 'postman_$version.deb'"
exit
fi
mv "postman_$version.deb" "$originalPWD"
cd "$originalPWD"
echo "Cleaning up"
rm -rf "$targetPWD"
while true; do
read -p "Do you want to install 'postman_$version.deb' [Y/n] " yn
if [ -z $yn ]; then
yn="y"
fi
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
echo "Installing"
sudo apt install -y "./postman_$version.deb"
if [ $? -gt 0 ]; then
echo "Failed to install 'postman_$version.deb'"
exit
fi
echo "Removing 'postman_$version.deb'"
rm -f "postman_$version.deb"
@ingeJulianLasso
Copy link

ingeJulianLasso commented Feb 8, 2020

AWESOME!!!
a thousand and a thousand thanks, it works perfectly in Ubuntu 18.04 installing version x64-7.17.0.

@tekhaus
Copy link

tekhaus commented Mar 11, 2020

beautiful, works like a champ in crostini! I ❤️ you

@StephenDoody
Copy link

StephenDoody commented Apr 18, 2020

Excellent, works perfectly, thank you.

@fakhamatia
Copy link

fakhamatia commented Apr 21, 2020

@fakhamatia should be working now, thanks for the information!

Again this error but in Ubuntu 19.10

$ ./PostmanDebDownloader.sh 
Testing Postman version
Most recent Postman version V7.22-1
Postman is not installed
Downloading latest Postman tarball
######################################################################### 100.0%curl: Saved to filename 'Postman-linux-x64-7.22.1.tar.gz'

Extracting Postman tarball
Creating 'postman_7.22-1' folder structure and files
Copying files
Testing whether to use '-e'
'-e' is not required
Writing files
Setting modes
Building 'postman_7.22-1.deb'
dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775)
Failed to build 'postman_7.22-1.deb'

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Apr 21, 2020

@fakhamatia should be working now, thanks for the information!

Again this error but in Ubuntu 19.10

$ ./PostmanDebDownloader.sh 
Testing Postman version
Most recent Postman version V7.22-1
Postman is not installed
Downloading latest Postman tarball
######################################################################### 100.0%curl: Saved to filename 'Postman-linux-x64-7.22.1.tar.gz'

Extracting Postman tarball
Creating 'postman_7.22-1' folder structure and files
Copying files
Testing whether to use '-e'
'-e' is not required
Writing files
Setting modes
Building 'postman_7.22-1.deb'
dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775)
Failed to build 'postman_7.22-1.deb'

Are you using a filesystem that does not support permissions, like NTFS? Because that will cause that error.

To fix it I added a check which will turn on the --nocheck flag for dpkg-deb if the actual file permission is not 775, this will make dpkg-deb ignore the permissions and should make it work. Let me know if it still doesn't work.

@fakhamatia
Copy link

fakhamatia commented Apr 21, 2020

Are you using a filesystem that does not support permissions, like NTFS?

Yes

Let me know if it still doesn't work.

No, it is OK, thank you 👌 👍

@lyfewithcode
Copy link

lyfewithcode commented Apr 22, 2020

Nice! Thank you :)

@Victorcasas
Copy link

Victorcasas commented Apr 25, 2020

Thank you very much, it's a very nice shell script!

@Tantawi
Copy link

Tantawi commented Jun 6, 2020

You are awesome!! thanks!!

@me-codes
Copy link

me-codes commented Jun 28, 2020

This is awesome thank you!!

@Killea
Copy link

Killea commented Aug 31, 2020

curl https://gist.githubusercontent.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043/raw/postman-deb.sh | bash -s -- -e

Could this line be added to the top of this script as a comment?

@cheirodgato
Copy link

cheirodgato commented Sep 1, 2020

Fantastic!!!

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Sep 1, 2020

@Killea I added a curl and wget version as a new file, that way it stands out more than a comment in the script, thanks for the idea!

@n8eloy
Copy link

n8eloy commented Sep 1, 2020

Awesome work bro, thank you! 🚀

Just a tip: it may be better to have the -y flag at line 153:
sudo apt install -y "./postman_$version.deb"

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Sep 2, 2020

@n8eloy Good idea, when you run the script locally it will already ask to install, and using curl/wget just assumes you want to install it, thanks for the tip!

@AlvaroCodigo
Copy link

AlvaroCodigo commented Sep 8, 2020

Gracias amigo mio, eres un dios <3

@ochen1
Copy link

ochen1 commented Oct 23, 2020

Thanks! It worked on Linux 5.4.0-52-generic

@richardwellerson
Copy link

richardwellerson commented Feb 23, 2021

Thanks bro! AWESOME!

@Sveagruva
Copy link

Sveagruva commented Feb 25, 2021

Thanks

@xrxrxr
Copy link

xrxrxr commented Mar 18, 2021

spassiba

@MKRNaqeebi
Copy link

MKRNaqeebi commented Apr 15, 2021

Wow (stared)

@binary-ibex
Copy link

binary-ibex commented May 29, 2021

Thanks Brother

@Miltonr87
Copy link

Miltonr87 commented Jul 9, 2021

Thanx a lot, I use Linux Mint and flatpack version of Postman is unfortunately very slow.

@PabloHdzVizcarra
Copy link

PabloHdzVizcarra commented Jul 15, 2021

Ohhh thanks men

@AndresJoaquinNino
Copy link

AndresJoaquinNino commented Nov 6, 2021

You are a hero!

@ohmydevops
Copy link

ohmydevops commented Nov 15, 2021

Brilliant! This even downloads the application for you.

Postman should pay you for this sunglasses

I agree

@mikiTesf
Copy link

mikiTesf commented Jan 21, 2022

I tried the script today and it breaks on line 59. The reason is because the downloaded tar archive is all in lowercase letters (postman instead of Postman). I also came across other errors:

.deb'ing 'postman_x64.tar-gz
/DEBIAN/control' near line 2 package 'postman':gz
 'Version' field value 'x64.tar-gz': version number does not start with digit
.deb'd to build 'postman_x64.tar-gz

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Jan 22, 2022

@mikiTesf It looks like Postman changed their naming scheme for tarballs, but it should work again.

Also a small update I forgot to upload, the package is now built in a temporary directory instead of the current working directory.

@mikiTesf
Copy link

mikiTesf commented Jan 23, 2022

@SanderTheDragon noted. Tried it again this morning. Works like a charm.

@sgtcoder
Copy link

sgtcoder commented Feb 5, 2022

Thanks guys, I updated my Postman script with some of this (it builds a repo)

@fakhamatia
Copy link

fakhamatia commented Jul 29, 2022

Testing Postman version
Most recent Postman version Vx64.tar-gz
Postman is not installed
Downloading latest Postman tarball
############################################################################################################################## 100.0%
Extracting Postman tarball
ls: cannot access 'Postman*.tar.gz': No such file or directory
tar: option requires an argument -- 'f'
Try 'tar --help' or 'tar --usage' for more information.
Failed to extract Postman tarball

Ubuntu 22.04

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Aug 4, 2022

@fakhamatia That mostly looks like the script is outdated, did you run it directly from the command line using one of the commands from the readme?

@stillru
Copy link

stillru commented Aug 5, 2022

Problem on lines 7-18.
Returning string is postman-linux-x64.tar.gz wich havent version

@SanderTheDragon
Copy link
Author

SanderTheDragon commented Aug 5, 2022

@stillru Thanks for letting me know!

I was just able to look and try it myself, and they dropped version information from the filenames. The only place I can find it now is in "/Postman/app/resources/app/package.json", this means that the only way to get the version is by first downloading the tarball. Or maybe they have a simple API that can be used for version info, I'll need to look into it.

I will update the script as soon as I can.

@sgtcoder
Copy link

sgtcoder commented Aug 5, 2022

I don't have any issues on my end. I actually included this script in my repository server so updates are automatic

@stillru
Copy link

stillru commented Aug 5, 2022

I create a fork and change version generation based on date from wget/curl answer https://gist.github.com/stillru/86aee4761f6129642c9a1d6d9bea96a4

Dirty, but work... How can i create pr for gist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment