Skip to content

Instantly share code, notes, and snippets.

@SanderTheDragon
Last active December 23, 2024 13:34
Show Gist options
  • Save SanderTheDragon/1331397932abaa1d6fbbf63baed5f043 to your computer and use it in GitHub Desktop.
Save SanderTheDragon/1331397932abaa1d6fbbf63baed5f043 to your computer and use it in GitHub Desktop.
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file.

Postman Debian Package Builder

Usage

Simply run the one of the following commands in your terminal and it will download the latest Postman version, build a .deb package and ask you if you want to install it.

if you have curl:

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

If you do not have curl:

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

License

This script is licensed under the MIT License.

Contributors

  • pedzed: idea for this script
  • SanderTheDragon: initial script and updates

Issues

Building Problems
  • chrisbjr: missing -e in some shells
  • cyfrost: -e not working with direct command
  • fakhamatia: dpkg-deb not building with wrong permissions
Missing Dependencies
  • jveillet: gconf2
  • kagurazakakotori: libgtk2.0-0 and libcanberra-gtk-module
  • wirwolf: desktop-file-utils
Installation Problems
  • maxgalbu, R0nAk: desktop file not installing
Upstream Changes
  • emamut: changed icon path
  • mikiTesf: changed tarball name from Postman to postman
  • stillru: changed tarball name to one without version information
  • 0xjams: changed from GTK 2 to GTK 3

Ideas

  • xlmnxp, cyfrost, Killea: direct curl command (at the top)
  • cyfrost: version check before building
  • n8eloy: -y flag for apt install
  • stillru: using date as version
  • 0xjams: support for ARM64
#!/bin/sh
# SPDX-FileCopyrightText: 2017-2024 SanderTheDragon <[email protected]>
#
# SPDX-License-Identifier: MIT
arch=$(dpkg --print-architecture)
echo "Detected architecture: $arch"
case "$arch" in
amd64) downloadURL="https://dl.pstmn.io/download/latest/linux64";;
arm64) downloadURL="https://dl.pstmn.io/download/latest/linux_arm64";;
*)
echo "Unsupported architecture: $arch"
exit
;;
esac
curlExists=$(command -v curl)
echo "Testing Postman version"
dateString=""
if [ -z $curlExists ]; then
dateString=$(wget -S --spider $downloadURL 2>&1 | grep "Date" | awk -F ':' '{ print $2 }')
else
dateString=$(curl -sI $downloadURL 2>&1 | grep "date" | awk -F ':' '{ print $2 }')
fi
targetName="postman-$(date --date="$dateString" "+%y-%j-%H").tar.gz"
versionMaj=$(echo "$targetName" | awk -F '.' '{ print $1 }' | awk -F '-' '{ print $2 }')
versionMin=$(echo "$targetName" | awk -F '.' '{ print $1 }' | awk -F '-' '{ print $3 }')
versionRev=$(echo "$targetName" | awk -F '.' '{ print $1 }' | awk -F '-' '{ print $4 }')
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 $downloadURL -O $targetName
else
curl -# $downloadURL -o $targetName
fi
if [ $? -gt 0 ]; then
echo "Failed to download Postman tarball"
exit
fi
echo "Extracting Postman tarball"
tar -xf $targetName
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: $arch\nDepends: libgtk-3-0, desktop-file-utils\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"
@AlvaroCodigo
Copy link

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

Thanks bro! AWESOME!

@Sveagruva
Copy link

Thanks

@xrxrxr
Copy link

xrxrxr commented Mar 18, 2021

spassiba

@MKRNaqeebi
Copy link

Wow (stared)

@binary-ibex
Copy link

Thanks Brother

@Miltonr87
Copy link

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

@pablohdzvizcarra
Copy link

Ohhh thanks men

@AndresJoaquinNino
Copy link

You are a hero!

@ohmydevops
Copy link

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

@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

@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

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

@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

@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.

@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?

@SanderTheDragon
Copy link
Author

@stillru That is a very good idea, and it is probably the best way, thanks! :D
I edited it a bit to use a different scheme, day of year looks nicer in my opinion and hour could be useful.
Also PRs do not exist for gists, but I added you (and everyone else who helped in one way or another) to the new contributors part of the README.

Other than that:

  • targetName is now actually used as target name
  • I fixed the issue where dpkg-deb complains about the Optional field
  • I added licensing information (MIT), which could be useful

I hope everything will work now : )

@fakhamatia
Copy link

I hope everything will work now : )

Yes, thank you its work but in end show a warning:

$ ./PostmanDebDownloader.sh
.
.
.
Unpacking postman (22.223-09) ...
Setting up gconf2 (3.2.6-7ubuntu2) ...
Setting up postman (22.223-09) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
ZSys is adding automatic system snapshot to GRUB menu
N: Download is performed unsandboxed as root as file '/Postman/Downloader/postman_22.223-09.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
Removing 'postman_22.223-09.deb'

@SanderTheDragon
Copy link
Author

@fakhamatia I don't get that message on my system (Debian Testing), but it looks like it is caused by the fact that the download and build is done by your current user instead of the _apt user. And in my opinion the build should be done by the current user.

I could add a check to see if the _apt user exists and chown the package if it does. But since the install succeeds and the loglevel is notice, I think the best way for now is to just ignore it.

@MBM1607
Copy link

MBM1607 commented Sep 17, 2022

Thanks a lot @SanderTheDragon !

@rizperdana
Copy link

Thanks a lot @SanderTheDragon this script really helpful, it works on pop os 22.04, should work on ubuntu and linux mint version too!

@dxdns
Copy link

dxdns commented Jan 12, 2023

At the end this message appears:
N: Download is performed unsandboxed as root as file '/Postman/Downloader/postman_22.223-09.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
Removing 'postman_22.223-09.deb'

But it worked on linux mint. Thanks

@LeCongNam
Copy link

Thank you @SanderTheDragon. I'm find postman fix cursor very long until I found it this repo.

@0xjams
Copy link

0xjams commented Apr 2, 2024

I added a check so that it downloads the right version depending on the architecture. I also removed gconf2 as a dependency, and it seemed to work just fine.

https://gist.github.com/0xjams/d8ca3c2448e97bfae1cf1812d6e7f9ee

@SanderTheDragon
Copy link
Author

@0xjams Thanks for these improvements!

I moved the architecture check to the top, so the date/version is checked for the correct architecture (I would expect that they are the same, but just to be sure).
I also checked the dependencies, and it seems like it now depends on GTK 3 instead of GTK 2, so gconf2 is not needed anymore.

@lopezdonaque
Copy link

Thanks for it!!

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