Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry Pick - Add function to check GPG expiry date (#1796) #1801

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions functions/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ add_keys() {
fi
}

## Check key for expiration within 30 days
##
## check_keys(String keyFile)
##
check_keys() {
local repoKey="/usr/share/keyrings/${1}.gpg"

echo -n "$(timestamp) [openHABian] Checking expiry date of apt keys... "

if [[ ! -f "${repoKey}" ]]; then echo "WARN (no file)"; return 1; fi
gpgKeys=$(gpg --with-colons --fixed-list-mode --show-keys "${repoKey}" | cut -d: -f7 | awk NF)
currentTime=$(date +%s)
if [[ -n "$gpgKeys" ]]; then
while IFS= read -r keyExpiry; do
diff=$((keyExpiry - currentTime))
daysLeft=$((diff/(60*60*24)))
if [[ ${daysLeft} -lt 30 ]]; then
echo "WARN (needs update)"
return 1
fi
done <<< "${gpgKeys}"
else
echo "WARN (no key in file)"
return 1
fi
echo "OK"
return 0
}

## Update given git repo and switch to specfied branch / tag
##
## update_git_repo(String path, String branch)
Expand Down
4 changes: 4 additions & 0 deletions functions/openhabian.bash
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ openhabian_update_check() {
openhabian_announcements
echo -n "$(timestamp) [openHABian] Switching to branch ${clonebranch:-openHAB}... "
if git -C "${BASEDIR:-/opt/openhabian}" checkout --quiet "${clonebranch:-openHAB}"; then echo "OK"; else echo "FAILED"; return 1; fi
echo "$(timestamp) [openHABian] Checking openHAB Signing Key expiry."
if ! check_keys openhab; then
add_keys "https://openhab.jfrog.io/artifactory/api/gpg/key/public" openhab
fi
}

## Updates the current openhabian repository to the most current version of the
Expand Down