customversion: make script less likely to error in systemd services

This commit is contained in:
ave 2019-01-23 02:13:22 +03:00
parent 9fd72d479e
commit 3f97a21677
No known key found for this signature in database
GPG Key ID: 09356ABAA42C842B
1 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
#!/bin/env python3
import sys
import os
import getpass
import datetime
import socket
@ -18,8 +18,15 @@ customtext = customtext.strip(",")
timestamp = str(datetime.datetime.utcnow()).split('.')[0] + " UTC"
customtext += ", built on {}@{} at {}".format(os.getlogin(),
socket.gethostname(),
try:
uname = getpass.getuser()
except:
uname = "unknown"
hostname = socket.gethostname().split(".")[0]
customtext += ", built on {}@{} at {}".format(uname,
hostname,
timestamp)
# Replace the target string