Skip to content

Commit

Permalink
Provide git-describe based version information when running from with…
Browse files Browse the repository at this point in the history
…in git

This is useful when executing grml2usb from inside grml2usb.git itself

Thanks: Florian Apolloner for review and feedback
  • Loading branch information
mika committed Oct 30, 2019
1 parent 6fd18ca commit 04781c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions debian/rules
Expand Up @@ -18,7 +18,7 @@ build-indep: build-stamp
build-stamp:
dh_testdir

egrep -q "PROG_VERSION = '\*\*\*UNRELEASED\*\*\*'" grml2usb || (echo "PROG_VERSION in grml2usb wrong." && exit 2)
egrep -q "^PROG_VERSION = '\*\*\*UNKNOWN\*\*\*'" grml2usb || (echo "PROG_VERSION in grml2usb wrong." && exit 2)
$(MAKE)
cd mbr && $(MAKE) && cd ..
touch build-stamp
Expand All @@ -41,7 +41,7 @@ install: build

# Add here commands to install the package into debian/grml2usb.
install -m 755 grml2usb debian/grml2usb/usr/sbin/grml2usb
sed -i -e "s/PROG_VERSION = '\*\*\*UNRELEASED\*\*\*'/PROG_VERSION = '$(VERSION)'/" debian/grml2usb/usr/sbin/grml2usb
sed -i -e "s/^PROG_VERSION = '\*\*\*UNKNOWN\*\*\*'/PROG_VERSION = '$(VERSION)'/" debian/grml2usb/usr/sbin/grml2usb
install -m 755 grml2iso debian/grml2usb/usr/sbin/grml2iso
install -m 644 mbr/mbrmgr debian/grml2usb/usr/share/grml2usb/mbr/mbrmgr
install -m 644 mbr/mbrldr debian/grml2usb/usr/share/grml2usb/mbr/mbrldr
Expand Down
17 changes: 16 additions & 1 deletion grml2usb
Expand Up @@ -32,7 +32,22 @@ import uuid
import shutil

# The line following this line is patched by debian/rules and tarball.sh.
PROG_VERSION = '***UNRELEASED***'
PROG_VERSION = '***UNKNOWN***'

# when running from inside git, try to report version information via git-describe
try:
git_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
with open(os.devnull, 'w') as devnull:
PROG_VERSION = subprocess.check_output(["git",
"-C",
git_dir,
"describe",
"--always",
"--dirty"],
stderr=devnull).strip().decode('utf-8', errors='replace') + \
" (git)"
except Exception:
pass

# global variables
MOUNTED = set() # register mountpoints
Expand Down
2 changes: 1 addition & 1 deletion tarball.sh
Expand Up @@ -116,7 +116,7 @@ rm grml2usb-$VERSION/grml2iso.8.txt

# binaries, grub
cp grml2usb grml2iso mbr/mbrldr mbr/mbrmgr grub/* grml2usb-$VERSION/
sed -i -e "s/PROG_VERSION='\*\*\*UNRELEASED\*\*\*'/PROG_VERSION='${VERSION}'/" grml2usb-$VERSION/grml2usb
sed -i -e "s/PROG_VERSION='\*\*\*UNKNOWN\*\*\*'/PROG_VERSION='${VERSION}'/" grml2usb-$VERSION/grml2usb

tar zcf grml2usb.tgz "${DIR}"

Expand Down

0 comments on commit 04781c3

Please sign in to comment.