From 3f97a21677a575113f632da74f9bc2ad4c2dd212 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Wed, 23 Jan 2019 02:13:22 +0300 Subject: [PATCH] customversion: make script less likely to error in systemd services --- patches/customversion/addpatch.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/patches/customversion/addpatch.py b/patches/customversion/addpatch.py index 1614bb8..1d391ff 100644 --- a/patches/customversion/addpatch.py +++ b/patches/customversion/addpatch.py @@ -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