From d8a41b6e3547f4041e7db7432889423ab3e20d41 Mon Sep 17 00:00:00 2001 From: lbussy Date: Sat, 24 Apr 2021 08:03:27 -0500 Subject: [PATCH 1/6] Add .local to exclusions --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2383fde..7df9edd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Home dir files +.local .bash_logout .bash_aliases .bashrc From 168cfa6f6843f125dcdb7cc29e73f08a2eba2cd3 Mon Sep 17 00:00:00 2001 From: lbussy Date: Sat, 24 Apr 2021 08:04:05 -0500 Subject: [PATCH 2/6] Add toolPath to config --- BrewPiUtil.py | 7 +++++-- settings/defaults.cfg | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BrewPiUtil.py b/BrewPiUtil.py index 39b5703..4e4d1a0 100755 --- a/BrewPiUtil.py +++ b/BrewPiUtil.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# Copyright (C) 2018, 2019 Lee C. Bussy (@LBussy) +# Copyright (C) 2018-2021 Lee C. Bussy (@LBussy) # This file is part of LBussy's BrewPi Script Remix (BrewPi-Script-RMX). # @@ -96,6 +96,7 @@ def readCfgWithDefaults(configFile = None): if error: defCfg = ConfigObj() defCfg.filename = defaultFile + defCfg['toolPath'] = '/home/pi/brewpi-tools-rmx/' defCfg['scriptPath'] = '/home/brewpi/' defCfg['wwwPath'] = '/var/www/html/' defCfg['port'] = 'auto' @@ -126,8 +127,10 @@ def readCfgWithDefaults(configFile = None): logMessage("Using default configuration.") # Fix pathnames + defCfg['toolPath'] = addSlash(defCfg['toolPath']) defCfg['scriptPath'] = addSlash(defCfg['scriptPath']) defCfg['wwwPath'] = addSlash(defCfg['wwwPath']) + return defCfg @@ -270,7 +273,7 @@ def logMessage(*objs): def logWarn(*objs): """ Prints a timestamped warning message to stdout - """ + """ if 'USE_TIMESTAMP_LOG' in os.environ: printStdOut(strftime("%Y-%m-%d %H:%M:%S [W]"), *objs) else: diff --git a/settings/defaults.cfg b/settings/defaults.cfg index bf26a3c..4e5c031 100644 --- a/settings/defaults.cfg +++ b/settings/defaults.cfg @@ -2,6 +2,7 @@ # the settings in config.cfg. That file will overrule the defaults # set here. +toolPath = /home/pi/brewpi-tools-rmx/ scriptPath = /home/brewpi/ wwwPath = /var/www/html/ port = auto From 7bb058970fe674090b4292bf6e971c2c61f25b80 Mon Sep 17 00:00:00 2001 From: lbussy Date: Sat, 24 Apr 2021 08:10:20 -0500 Subject: [PATCH 3/6] Whitespace cleanup --- Tilt.py | 2 +- brewpi.py | 2 +- programController.py | 2 +- utils/doCleanup.sh | 8 ++++---- utils/doDaemon.sh | 8 ++++---- utils/doDepends.sh | 12 ++++++------ utils/doIndex.sh | 10 +++++----- utils/doMenu.sh | 6 +++--- utils/doUpdate.sh | 30 +++++++++++++++--------------- utils/doWiFi.sh | 10 +++++----- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Tilt.py b/Tilt.py index 77493ec..51656ac 100755 --- a/Tilt.py +++ b/Tilt.py @@ -255,7 +255,7 @@ def blecallback(self, data): if self.opts.json and self.debug: # Print Debug display_raw = False print("Tilt JSON: {}".format(tiltJson)) - + else: # Not a Tilt return diff --git a/brewpi.py b/brewpi.py index fad10ea..c2ed372 100755 --- a/brewpi.py +++ b/brewpi.py @@ -608,7 +608,7 @@ def initTilt(): # Set up Tilt config['tiltColor'] + 'Batt': 0 }) - + def initISpindel(): # Initialize iSpindel global ispindel global config diff --git a/programController.py b/programController.py index f6bdfee..8bebc67 100755 --- a/programController.py +++ b/programController.py @@ -609,7 +609,7 @@ def flash_file(self, hexFile): bootLoaderPort = util.findSerialPort(bootLoader=True, my_port=config['port']) # bootLoaderPort = util.findSerialPort(bootLoader=True) if not bootLoaderPort: - printStdErr("\nERROR: Could not find port in bootloader.") + printStdErr("\nERROR: Could not find port in bootloader.") return False programCommand = (avrdudehome + 'avrdude' + diff --git a/utils/doCleanup.sh b/utils/doCleanup.sh index 7b483e3..18ff661 100755 --- a/utils/doCleanup.sh +++ b/utils/doCleanup.sh @@ -43,19 +43,19 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" - + # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" diff --git a/utils/doDaemon.sh b/utils/doDaemon.sh index a250784..286f605 100755 --- a/utils/doDaemon.sh +++ b/utils/doDaemon.sh @@ -43,7 +43,7 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" @@ -55,11 +55,11 @@ init() { # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" @@ -194,7 +194,7 @@ ExecStart=/bin/bash $scriptName SyslogIdentifier=$daemonName [Install] -WantedBy=multi-user.target" +WantedBy=multi-user.target" } > "$unitFile" chown root:root "$unitFile" chmod 0644 "$unitFile" diff --git a/utils/doDepends.sh b/utils/doDepends.sh index 031aeab..4615534 100755 --- a/utils/doDepends.sh +++ b/utils/doDepends.sh @@ -22,7 +22,7 @@ declare SCRIPTPATH GITROOT APTPACKAGES PIP3PACKAGES REINSTALL GOODPORT GOODPORTS # Declare /inc/const.inc file constants declare THISSCRIPT GITROOT USERROOT REALUSER # Declare /inc/asroot.inc file constants -declare HOMEPATH +declare HOMEPATH # Declare placeholders for nginx work declare DANGER_AHEAD RECONFIG_APACHE # Declare alternative ports @@ -45,7 +45,7 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" @@ -268,7 +268,7 @@ do_packages() { fi for pkg in ${APTPACKAGES,,}; do if [ -n "$REINSTALL" ]; then - + apt-get --reinstall install "${pkg,,}" -y -q=2||die echo else @@ -294,12 +294,12 @@ do_packages() { else echo -e "\nNo apt packages were missing." fi - + # Get list of installed packages with upgrade available upgradesAvail=$(dpkg --get-selections | xargs apt-cache policy {} | \ grep -1 Installed | sed -r 's/(:|Installed: |Candidate: )//' | \ uniq -u | tac | sed '/--/I,+1 d' | tac | sed '$d' | sed -n 1~2p) - + # Loop through only the required packages and see if they need an upgrade for pkg in ${APTPACKAGES,,}; do if [[ ${upgradesAvail,,} == *"$pkg"* ]]; then @@ -308,7 +308,7 @@ do_packages() { doCleanup=1 fi done - + # Cleanup if we updated packages if [ -n "$doCleanup" ]; then echo -e "Cleaning up local repositories." diff --git a/utils/doIndex.sh b/utils/doIndex.sh index 1bd39a5..d33b56a 100755 --- a/utils/doIndex.sh +++ b/utils/doIndex.sh @@ -39,23 +39,23 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" - + # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" - + # Get config file read functionality # shellcheck source=/dev/null . "$GITROOT/inc/config.inc" "$@" diff --git a/utils/doMenu.sh b/utils/doMenu.sh index 43f042d..485f1c0 100755 --- a/utils/doMenu.sh +++ b/utils/doMenu.sh @@ -50,15 +50,15 @@ init() { # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" - + # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" diff --git a/utils/doUpdate.sh b/utils/doUpdate.sh index 289d8ad..e29f3d7 100755 --- a/utils/doUpdate.sh +++ b/utils/doUpdate.sh @@ -44,27 +44,27 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" - + # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" - + # Get network test functionality # shellcheck source=/dev/null . "$GITROOT/inc/nettest.inc" "$@" - + # Get config reading functionality # shellcheck source=/dev/null . "$GITROOT/inc/config.inc" "$@" @@ -77,7 +77,7 @@ init() { banner() { local adj adj="$1" - echo -e "\n***Script $THISSCRIPT $adj.***" > /dev/tty + echo -e "\n***Script $THISSCRIPT $adj.***" > /dev/tty } ############ @@ -195,12 +195,12 @@ updateme() { local branch branch=$(git branch | grep \* | cut -d ' ' -f2) url="${url/THISBRANCH/$branch}" - echo -e "\nDownloading current version of this script." > /dev/tty - cd "$SCRIPTPATH" && { curl -s "$url" -o "tmpUpdate.sh"; cd - &> /dev/null || die; } > /dev/tty - chown brewpi:brewpi "$SCRIPTPATH/tmpUpdate.sh" > /dev/tty - chmod 770 "$SCRIPTPATH/tmpUpdate.sh" > /dev/tty - echo -e "\nExecuting current version of script." > /dev/tty - eval "bash $SCRIPTPATH/tmpUpdate.sh $*" > /dev/tty + echo -e "\nDownloading current version of this script." > /dev/tty + cd "$SCRIPTPATH" && { curl -s "$url" -o "tmpUpdate.sh"; cd - &> /dev/null || die; } > /dev/tty + chown brewpi:brewpi "$SCRIPTPATH/tmpUpdate.sh" > /dev/tty + chmod 770 "$SCRIPTPATH/tmpUpdate.sh" > /dev/tty + echo -e "\nExecuting current version of script." > /dev/tty + eval "bash $SCRIPTPATH/tmpUpdate.sh $*" > /dev/tty } ############ @@ -231,7 +231,7 @@ process() { pushd . &> /dev/null || die # Store current directory cd "$(dirname "$(readlink -e "$0")")" || die # Move to where the script is # Update repo as necessary - echo -e "\nChecking $doRepo for necessary updates." > /dev/tty + echo -e "\nChecking $doRepo for necessary updates." > /dev/tty doRepoUrl "$doRepo" || warn updateRepo "$doRepo" || warn popd &> /dev/null || die # Move back to where we started @@ -280,7 +280,7 @@ flash() { else branch="" fi - echo "" > /dev/tty + echo "" > /dev/tty read -rp "Do you want to flash your controller now? [y/N]: " yn < /dev/tty case "$yn" in [Yy]* ) eval "python3 -u $SCRIPTPATH/updateFirmware.py $branch" ;; diff --git a/utils/doWiFi.sh b/utils/doWiFi.sh index 1442efa..b18f6d2 100755 --- a/utils/doWiFi.sh +++ b/utils/doWiFi.sh @@ -56,23 +56,23 @@ init() { popd &> /dev/null || exit 1 exit 1 fi - + # Get project constants # shellcheck source=/dev/null . "$GITROOT/inc/const.inc" "$@" - + # Get error handling functionality # shellcheck source=/dev/null . "$GITROOT/inc/error.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/asroot.inc" "$@" - + # Get help and version functionality # shellcheck source=/dev/null . "$GITROOT/inc/help.inc" "$@" - + # Get wireless lan device name and gateway WLAN="$(iw dev | awk '$1=="Interface"{print $2}')" } From 3dd2d27dd1887cce9c859f3a151a20a14d6665f5 Mon Sep 17 00:00:00 2001 From: lbussy Date: Sat, 24 Apr 2021 08:11:03 -0500 Subject: [PATCH 4/6] Remove trailing comma after null --- brewpiJson.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brewpiJson.py b/brewpiJson.py index 213c8fd..3d83aec 100755 --- a/brewpiJson.py +++ b/brewpiJson.py @@ -126,7 +126,7 @@ def addRow(jsonFileName, row, tiltColor = None, iSpindel = None): # Write iSpindel values elif iSpindel: if row['spinSG'] is None: - jsonFile.write(",null,") + jsonFile.write(",null") else: jsonFile.write(",{\"v\":" + str(row['spinSG']) + "}") From 03ca63052ec6b974656c62bf023f9af764d3db40 Mon Sep 17 00:00:00 2001 From: lbussy Date: Sat, 24 Apr 2021 08:11:32 -0500 Subject: [PATCH 5/6] New file --- gitInfo.py | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 gitInfo.py diff --git a/gitInfo.py b/gitInfo.py new file mode 100755 index 0000000..3d967f1 --- /dev/null +++ b/gitInfo.py @@ -0,0 +1,132 @@ +#!/usr/bin/python3 + +# Copyright (C) 2021 Lee C. Bussy (@LBussy) + +# This file is part of LBussy's BrewPi Script Remix (BrewPi-Script-RMX). +# +# BrewPi Script RMX is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# BrewPi Script RMX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BrewPi Script RMX. If not, see . + +import git +import os +import json +from pprint import pprint as pp + +import BrewPiUtil as util + + +class GitInfo: + path = None + repo = None + + def __init__(self, arg): + self.path = arg + self.repo = git.Repo(self.path, search_parent_directories=True) + + def get_git_root(self) -> str: + try: + root = self.repo.git.rev_parse("--show-toplevel") + except: + root = None + return root + + def get_git_tag(self) -> str: + try: + tags = sorted(self.repo.tags, key=lambda t: t.commit.committed_datetime) + tagref = str(tags[-1]) + except: + tagref = None + return tagref + + def get_git_branch(self) -> str: + try: + branch = str(self.repo.active_branch) + except: + branch = None + return branch + + def get_commit_author(self) -> str: + try: + name = self.repo.head.commit.author.name + except: + name = None + return name + + def get_commit_author_email(self) -> str: + try: + email = self.repo.head.commit.author.email + except: + email = None + return email + + def get_commit_hash(self, length = None) -> str: + try: + if length == None: + commithash = self.repo.head.commit.hexsha + else: + commithash = self.repo.head.commit.hexsha[:length] + except: + hash = None + return commithash + + def get_commit_message(self) -> str: + try: + message = self.repo.head.commit.message + message = message.split('\n', 1)[0] + message = message[ 0 : 50 ].strip() + except: + message = None + return message + + def get_git_dict(self) -> dict: + git_dict = {} + git_dict['git_root'] = self.get_git_root() + git_dict['git_tag'] = self.get_git_tag() + git_dict['git_branch'] = self.get_git_branch() + git_dict['commit_author'] = self.get_commit_author() + git_dict['commit_author_email'] = self.get_commit_author_email() + git_dict['commit_hash'] = self.get_commit_hash() + git_dict['commit_hash_short'] = self.get_commit_hash(7) + git_dict['commit_message'] = self.get_commit_message() + return git_dict + + def get_git_json(self, ind = None) -> str: + if ind == None: + json_str = json.dumps(self.get_git_dict()) + else: + json_str = json.dumps(self.get_git_dict(), indent = ind) + return json_str + + +if __name__ == "__main__": + config = util.readCfgWithDefaults() + path_list = [config['toolPath'], config['scriptPath'], config['wwwPath']] + for path in path_list: + # need path + gi = GitInfo(path) + print("Testing git information for {}".format(path)) + print("Repo = {}".format(gi.get_git_root())) + print("Tag = {}".format(gi.get_git_tag())) + print("Branch = {}".format(gi.get_git_branch())) + print("Commit Hash = {}".format(gi.get_commit_hash())) + print("Short Commit Hash = {}".format(gi.get_commit_hash(7))) + print("Commit Author = {}".format(gi.get_commit_author())) + print("Commit Author Email = {}".format(gi.get_commit_author_email())) + print("Commit Message = {}".format(gi.get_commit_message())) + print("Dict object:") + pp(gi.get_git_dict()) + print("JSON Beacon:") + print(gi.get_git_json()) + print("JSON Beacon Pretty:") + print(gi.get_git_json(4)) + print() From 4c93d3e81a3746e98c448cbe3dd7ee1185869c81 Mon Sep 17 00:00:00 2001 From: Lee Bussy Date: Sat, 24 Apr 2021 09:07:07 -0500 Subject: [PATCH 6/6] Skip perms on venv (#185) --- utils/doPerms.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/utils/doPerms.sh b/utils/doPerms.sh index 5f989f8..58aedb2 100755 --- a/utils/doPerms.sh +++ b/utils/doPerms.sh @@ -92,11 +92,21 @@ perms() { if [ -e "$GITROOT/BEERSOCKET" ]; then chown -R brewpi:www-data "$GITROOT/BEERSOCKET" || warn fi - find "$GITROOT" -type d -exec chmod 775 {} \; || warn - find "$GITROOT" -type f -exec chmod 660 {} \; || warn - find "$GITROOT" -type f -regex ".*\.\(py\|sh\)" -exec chmod 770 {} \; || warn + + # Set the directories excluding venv + chmod 660 "$GITROOT"/*.* || warn + chmod +x "$GITROOT"/*.sh >/dev/null 2>&1 # Probably no shell scripts here + chmod +x "$GITROOT"/*.py || warn + for dirname in "$GITROOT"/*/; do + if [ "${dirname%%}" != "$GITROOT/venv/" ]; then + find "${dirname%%}" -type d -exec chmod 775 {} \; || warn + find "${dirname%%}" -type f -exec chmod 660 {} \; || warn + find "${dirname%%}" -type f -regex ".*\.\(py\|sh\)" -exec chmod 770 {} \; || warn + fi + done find "$GITROOT/logs" -type f -iname "*.txt" -exec chmod 777 {} \; || warn find "$GITROOT/settings" -type f -exec chmod 664 {} \; || warn + echo -e "\nAllowing BrewPi python access to Bluetooth interfaces." setcap cap_net_raw+eip $(eval readlink -f `which python3`) }