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.
#!/bin/sh
ls Postman*.tar.gz > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Removing old Postman tarballs"
rm -f $(ls Postman*.tar.gz)
fi
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 $4 }' | awk -F '.' '{ print $1 }')
versionMin=$(echo "$targetName" | awk -F '-' '{ print $4 }' | awk -F '.' '{ print $2 }')
versionRev=$(echo "$targetName" | awk -F '-' '{ print $4 }' | 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
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
if [ -d "Postman" ]; then
echo "Removing old 'Postman/'"
rm -rf "Postman/"
fi
echo "Extracting Postman tarball"
tar -xf $(ls Postman*.tar.gz)
if [ $? -gt 0 ]; then
echo "Failed to extract Postman tarball"
exit
fi
if [ -d "postman_$version" ]; then
echo "Removing old 'postman_$version/'"
rm -rf "postman_$version/"
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"
if [ -f "postman_$version.deb" ]; then
echo "Removing old 'postman_$version.deb'"
rm -f "postman_$version.deb"
fi
echo "Building 'postman_$version.deb'"
dpkg-deb -b "postman_$version" > /dev/null
if [ $? -gt 0 ]; then
echo "Failed to build 'postman_$version.deb'"
exit
fi
echo "Cleaning up"
rm -f $(ls Postman*.tar.gz)
rm -rf "Postman/"
rm -rf "postman_$version/"
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 "./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"
@pedzed

This comment has been minimized.

Copy link

pedzed commented May 25, 2017

Brilliant! This even downloads the application for you.

Postman should pay you for this 😎

@Amiko

This comment has been minimized.

Copy link

Amiko commented Aug 14, 2017

Cheers man!

@Eli-Goldberg

This comment has been minimized.

Copy link

Eli-Goldberg commented Oct 9, 2017

AWESOME!

@erick-jeronimo

This comment has been minimized.

Copy link

erick-jeronimo commented Oct 27, 2017

Great! Thank you very much!

@Deliganli

This comment has been minimized.

Copy link

Deliganli commented Dec 12, 2017

very nice, thanks

@eginter

This comment has been minimized.

Copy link

eginter commented Jan 8, 2018

Worked perfectly, thanks!

@victort

This comment has been minimized.

Copy link

victort commented Jan 9, 2018

👍

@klapperkopp

This comment has been minimized.

Copy link

klapperkopp commented Jan 29, 2018

👍 Thanks!

@mfischbo

This comment has been minimized.

Copy link

mfischbo commented Jan 29, 2018

Works like a charm! Thanks a lot! 👍

@Nguimjeu

This comment has been minimized.

Copy link

Nguimjeu commented Feb 1, 2018

Much appreciated!

@jveillet

This comment has been minimized.

Copy link

jveillet commented Feb 5, 2018

Very nice, thanks!! 👍
I had a trouble with shared libraries tho, and add to do an apt-get install gconf2 in order to launch postman after the installation, if that can help anyone running into the same problem as me.

@whyseman

This comment has been minimized.

Copy link

whyseman commented Feb 5, 2018

Thank you!

@limberlost88

This comment has been minimized.

Copy link

limberlost88 commented Feb 19, 2018

Nice

@maxgalbu

This comment has been minimized.

Copy link

maxgalbu commented Mar 13, 2018

The app is installed but doesn't appear in the OS menu... (linux mint)

@R0nAk

This comment has been minimized.

Copy link

R0nAk commented Mar 21, 2018

@maxgalbu I am facing same issue

@ppshobi

This comment has been minimized.

Copy link

ppshobi commented Mar 23, 2018

Superb Bro 💐

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Mar 23, 2018

@maxgalbu @R0nAk It should work now, some desktop environments require desktop-file-install

@jveillet I added gconf2 as dependency

@chrisbjr

This comment has been minimized.

Copy link

chrisbjr commented Mar 31, 2018

hi @SanderTheDragon getting this:

Removing old Postman tarballs
Downloading latest Postman tarball
######################################################################## 100.0%curl: Saved to filename 'Postman-linux-x64-6.0.10.tar.gz'

Removing old 'Postman/'
Extracting Postman tarball
Postman V6.0-10
Removing old 'postman_6.0-10/'
Creating 'postman_6.0-10' folder structure and files
Copying files
Writing files
Setting modes
Building 'postman_6.0-10.deb'
dpkg-deb: error: parsing file 'postman_6.0-10/DEBIAN/control' near line 1:
 invalid package name (character '\' not allowed (only letters, digits and characters '-+._'))
Failed to build 'postman_6.0-10.deb'
@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Mar 31, 2018

@chrisbjr I updated the script, could you try running it with -e, it seems like some shells require it

@vaporwavie

This comment has been minimized.

Copy link

vaporwavie commented Apr 13, 2018

Really helpful. Awesome work! =)

@isitavi

This comment has been minimized.

Copy link

isitavi commented May 5, 2018

Great automation 👍

@teol

This comment has been minimized.

Copy link

teol commented May 25, 2018

Good job, thanks for sharing :-)

@emamut

This comment has been minimized.

Copy link

emamut commented May 28, 2018

Good job and consider this in line 65 cp "Postman/app/resources/app/assets/icon.png" of the latest version

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented May 28, 2018

Thanks for telling me @emamut, I updated it in the script

@xlmnxp

This comment has been minimized.

Copy link

xlmnxp commented May 29, 2018

paste code in terminal

curl "https://gist.githubusercontent.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043/raw/77284fac50ad74bf751ecfe1a3b6b45296895fef/postman-deb.sh" | sh
@jeriveromartinez

This comment has been minimized.

Copy link

jeriveromartinez commented Jun 27, 2018

I suggest you make the next change in line 111 by the following code
sudo dpkg -i "postman_$version.deb"
sudo apt install -f
with taha fix the error of teh user @chrisbjr

@zifahnet

This comment has been minimized.

Copy link

zifahnet commented Jul 7, 2018

Thanks

@raviyadav4875

This comment has been minimized.

Copy link

raviyadav4875 commented Sep 20, 2018

Works, thanks.
Keep it up

@pauloeli

This comment has been minimized.

Copy link

pauloeli commented Sep 24, 2018

Congratulations, really helpful

@matrixraven

This comment has been minimized.

Copy link

matrixraven commented Oct 11, 2018

This is awesome. Was trying to get Postman installed on my PixelBook in Crostini and get an icon in the launcher. Your script is flawless. Appreciate it!

@ashatat

This comment has been minimized.

Copy link

ashatat commented Oct 13, 2018

This is awesome man 👍

@BuddhikaNelum

This comment has been minimized.

Copy link

BuddhikaNelum commented Oct 29, 2018

thank you very much .... this is awsome..

@smamran

This comment has been minimized.

Copy link

smamran commented Nov 4, 2018

Postman Installation via Most Easiest Way

https://github.com/linux-bd/ubuntu/blob/master/app/postman.md

@chilly-dude

This comment has been minimized.

Copy link

chilly-dude commented Nov 30, 2018

Just used to install Postman on Crostini for my Pixelbook. Worked perfectly! Thanks!

@LizhangX

This comment has been minimized.

Copy link

LizhangX commented Feb 14, 2019

Works very well, thank you! FYI, if you want to remove postman or you accidentally remove postman folder in /opt/, you can run apt-get remove postman to remove it and use this script to reinstall :)

@MrMartinez

This comment has been minimized.

Copy link

MrMartinez commented Mar 29, 2019

Thnk's

@lukevance

This comment has been minimized.

Copy link

lukevance commented Apr 7, 2019

Beautiful

@MCZ-Pro

This comment has been minimized.

Copy link

MCZ-Pro commented Apr 29, 2019

thanks it's work perfect

@ashadnasim52

This comment has been minimized.

Copy link

ashadnasim52 commented May 15, 2019

thanks

@edugon

This comment has been minimized.

Copy link

edugon commented May 22, 2019

Thanks!

@chr1s3sw0rthy

This comment has been minimized.

Copy link

chr1s3sw0rthy commented May 22, 2019

nice.

@kagurazakakotori

This comment has been minimized.

Copy link

kagurazakakotori commented May 23, 2019

I got a postman: error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory error after installing because it depends on libgtk2.0-0, it may be better to add libgtk2.0-0 as dependency

After installing libgtk2.0-0, I also got a Gtk-Message: Failed to load module "canberra-gtk-module", which can be ignored since it doesn't cause a failure. It can be solved by installing libcanberra-gtk-module, maybe it can also be added as dependency.

My modified version is here

@YitziG

This comment has been minimized.

Copy link

YitziG commented May 31, 2019

Amazing!

@tombusby

This comment has been minimized.

Copy link

tombusby commented Jun 20, 2019

Nice work

@denidiasjr

This comment has been minimized.

Copy link

denidiasjr commented Jul 9, 2019

Awesome!

@wpkyaw

This comment has been minimized.

Copy link

wpkyaw commented Jul 23, 2019

I tried to install postman using your script on Crostini Linux beta (Chrome OS). It is unable to install after creating the deb file. So I go to the file manager and install with Linux beta. But then when I run the postman app, it is only loading and stuck. Can anyone help me?

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Jul 23, 2019

@wpkyaw, do you get any error messages in the terminal when you try to run it? If not, it could be something with Chrome OS which I don't have any experience with.

@kagurazakakotori, I added libgtk2.0-0 as dependency, and libcanberra-gtk-module as optional dependency, thanks for the information!

@cyfrost

This comment has been minimized.

Copy link

cyfrost commented Aug 19, 2019

Hi, when I try to run this script via this command:

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

I get this error:

image

Is anyone else facing this issue?

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Aug 19, 2019

@cyfrost I updated the script to automatically detect whether the '-e' flag is required. Since it does not seem to work in the way you tried (when using a pipe the command should actually be | bash -s -- -e). Running the same command again should fix it.

@cyfrost

This comment has been minimized.

Copy link

cyfrost commented Aug 20, 2019

@SanderTheDragon Thank you, it works as expected. This is a very handy addition to my workflow.

For anybody else looking for the copy-pasta, here it is:

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

This script essentially does:

  1. Pulls in the latest tarball of Postman from their official site.
  2. Creates a .deb package file and automatically installs it.
  3. Cleans up after it's done.

For those wondering, yes, this handy script can also be used as a updater script. Anytime a new version is out, just re-run this again and it should auto-update the existing Postman (the best part has to be that this app is now managed by APT).

@JoeXavi

This comment has been minimized.

Copy link

JoeXavi commented Aug 29, 2019

really awesome, thanks friend

@Dahouo

This comment has been minimized.

Copy link

Dahouo commented Nov 12, 2019

Really a good job. Thanks

@cyfrost

This comment has been minimized.

Copy link

cyfrost commented Nov 13, 2019

@SanderTheDragon I have a suggestion: can we have this script check if Postman is already installed and compare its version to the latest available and bail out if its up-to-date. Here's how we can find the current version: dpkg-query --showformat='${Version}' --show postman | egrep -o '^[^-]+', the output of this for me is 7.11 which is the latest Postman version available at the moment. Ofcourse, The output and error code is different if the package is not installed. Depending on if there's an update available, the script should download and install the update or else bail out saying everything is up-to-date. Doing this will save bandwidth and packaging.

For reference, I have a similar script that does this for another app (VSCodium), please have a look at it if need be.

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Nov 13, 2019

@cyfrost that is a really good idea, I changed it now. And I decided to use dpkg-query --showformat='${Version}' --show postman without the egrep part, since it's possible for the next version to be 7.11-1.

Thanks for the suggestion and piece of code!

@cyfrost

This comment has been minimized.

Copy link

cyfrost commented Nov 14, 2019

@SanderTheDragon The update is as expected, I've tested it and it is working! Thank you :)

@cameronj86

This comment has been minimized.

Copy link

cameronj86 commented Nov 15, 2019

Worked for my Chromebook in 2019. Thanks a lot!

@Lailanater

This comment has been minimized.

Copy link

Lailanater commented Nov 22, 2019

Works great! Thank you for all of your work!

@ameet-pradhan-au5

This comment has been minimized.

Copy link

ameet-pradhan-au5 commented Dec 9, 2019

Did get some error at the end. Using elementary OS 5.1 Hera-x64.
But still works like a charm. Thank a lot!!!!

@wirwolf

This comment has been minimized.

Copy link

wirwolf commented Dec 22, 2019

clear Kubuntu 18.04.03

wir_wolf@HOME:/tmp$ sudo ./postman-deb.sh 
Testing Postman version
Most recent Postman version V7.14-0
Postman is not installed
Downloading latest Postman tarball
############################################################################################################################################################################################################ 100,0%curl: Saved to filename 'Postman-linux-x64-7.14.0.tar.gz'

Extracting Postman tarball
Creating 'postman_7.14-0' folder structure and files
Copying files
Testing whether to use '-e'
'-e' is not required
Writing files
Setting modes
Building 'postman_7.14-0.deb'
Cleaning up
Do you want to install 'postman_7.14-0.deb'[Y/n] y
Installing
Чтение списков пакетов… Готово
Построение дерева зависимостей       
Чтение информации о состоянии… Готово
Заметьте, вместо «./postman_7.14-0.deb» выбирается «postman»
Предлагаемые пакеты:
  libcanberra-gtk-module
Следующие НОВЫЕ пакеты будут установлены:
  postman
Обновлено 0 пакетов, установлено 1 новых пакетов, для удаления отмечено 0 пакетов, и 0 пакетов не обновлено.
Необходимо скачать 0 B/52,4 MB архивов.
После данной операции объём занятого дискового пространства возрастёт на 0 B.
Пол:1 /tmp/postman_7.14-0.deb postman amd64 7.14-0 [52,4 MB]
Выбор ранее не выбранного пакета postman.
(Чтение базы данных … на данный момент установлено 224214 файлов и каталогов.)
Подготовка к распаковке /tmp/postman_7.14-0.deb …
Распаковывается postman (7.14-0) …
Настраивается пакет postman (7.14-0) …
/var/lib/dpkg/info/postman.postinst: 7: /var/lib/dpkg/info/postman.postinst: desktop-file-install: not found
dpkg: ошибка при обработке пакета postman (--configure):
 installed postman package post-installation script subprocess returned error exit status 127
Обрабатываются триггеры для mime-support (3.60ubuntu1) …
Обрабатываются триггеры для hicolor-icon-theme (0.17-2) …
При обработке следующих пакетов произошли ошибки:
 postman
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to install 'postman_7.14-0.deb'
wir_wolf@HOME:/tmp$ 

fix: sudo apt install desktop-file-utils

@SanderTheDragon

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Dec 22, 2019

@wirwolf I added desktop-file-utils as a dependency, thanks for the information!

@fakhamatia

This comment has been minimized.

Copy link

fakhamatia commented Jan 26, 2020

Ubuntu 18.04 :

Removing old Postman tarballs
Testing Postman version
Most recent Postman version V7.16-1
Postman is not installed
Downloading latest Postman tarball
######################################################################### 100.0%curl: Saved to filename 'Postman-linux-x64-7.16.1.tar.gz'

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

This comment has been minimized.

Copy link
Owner Author

SanderTheDragon commented Jan 26, 2020

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

@ingeJulianLasso

This comment has been minimized.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.