New Add-On for step-ca: step-admin - #1736
Conversation
Changed sources for testing
Typo in sources
| function detect_os() { | ||
| if grep -qi "alpine" /etc/os-release; then | ||
| #OS="Alpine" | ||
| PKG_UPDATE="" | ||
| PKG_INSTALL="apk add --no-cache" | ||
| PKG_UPGRADE="apk update" | ||
| PKG_UNINSTALL="apk del" | ||
| PKG_AUTOREMOVE="" | ||
| elif grep -qi "arch" /etc/os-release; then | ||
| #OS="Arch" | ||
| PKG_UPDATE="" | ||
| PKG_INSTALL="pacman -S" | ||
| PKG_UPGRADE="pacman -Syu" | ||
| PKG_UNINSTALL="pacman -Rs" | ||
| PKG_AUTOREMOVE="" | ||
| elif grep -qi "debian" /etc/os-release; then | ||
| #OS="Debian" | ||
| PKG_UPDATE="apt update" | ||
| PKG_INSTALL="apt -y install" | ||
| PKG_UPGRADE="apt -y upgrade" | ||
| PKG_UNINSTALL="apt -y --purge remove" | ||
| PKG_AUTOREMOVE="apt -y --purge autoremove" | ||
| if ! [[ -f /etc/apt/sources.list.d/smallstep.sources ]]; then | ||
| setup_deb822_repo \ | ||
| "smallstep" \ | ||
| "https://packages.smallstep.com/keys/apt/repo-signing-key.gpg" \ | ||
| "https://packages.smallstep.com/stable/debian" \ | ||
| "debs" \ | ||
| "main" | ||
| fi | ||
| elif grep -qi "ubuntu" /etc/os-release; then | ||
| #OS="Ubuntu" | ||
| PKG_UPDATE="apt update" | ||
| PKG_INSTALL="apt -y install" | ||
| PKG_UPGRADE="apt -y upgrade" | ||
| PKG_UNINSTALL="apt -y --purge remove" | ||
| PKG_AUTOREMOVE="apt -y --purge autoremove" | ||
| if ! [[ -f /etc/apt/sources.list.d/smallstep.sources ]]; then | ||
| setup_deb822_repo \ | ||
| "smallstep" \ | ||
| "https://packages.smallstep.com/keys/apt/repo-signing-key.gpg" \ | ||
| "https://packages.smallstep.com/stable/debian" \ | ||
| "debs" \ | ||
| "main" | ||
| fi | ||
| else | ||
| die "Unsupported OS. Exiting." | ||
| fi | ||
| } | ||
|
|
||
| # ============================================================================== | ||
| # HELPER FUNCTIONS | ||
| # ============================================================================== | ||
| function resolve_ip() { | ||
| local FQDN=$1 | ||
| local IP | ||
| IP=$(dig +short "$FQDN") | ||
| [[ -z "$IP" ]] && exit 1 || echo "$IP" | ||
| } |
There was a problem hiding this comment.
this should not be part of this PR.
there is another PR open for this, and we'd rather like those changes be incorporated into our existing funcs, if even needed.
There was a problem hiding this comment.
You are partly wrong - I've opened a PR for pve-lxc-system-admin.sh
#1627
During the initial discussion on this PR I have only asked for a suitable possibility to add some new supporting functions ...
For the moment the refactoring of the step-ca LXC is much more important (separate PR is coming quickly) and for that reason this step-admin Add-On will be handled by me with priority.
If needed I can make separate PRs for the supporting functions, but for the moment from my perspection nothing is opened beside parts of this PR...
How to proceed???
There was a problem hiding this comment.
we won't just add new core things for a single script, and we will also not create even more scripts like admin-core.sh.
also those changes make not that much sense, as some of that code already exists in our functions and would be doubled code.
Yes seperate Pr for supporting funcs would be appreciated, but this would come with integrating them into our existing core and possible also directly applying to other scripts that may benefit from the new helper function
There was a problem hiding this comment.
detect_os function:
- Copy&Paste from one of existing addon and define a funtion for better readability - I've seen this code fragments under the heading OS Detection) in most of actual existing Add-Ons under MAIN ...
- If a core function for detect OS is already available please let me know
whitail is widely used in your framework - but every usage of whiptail is handmade ...
- If whiptail functions are already available please let me know - I've found nothing
resolve_ip function:
- peanuts - I can simply move back into the add-on
There was a problem hiding this comment.
the whiptail is definitely something we have already talked about, but ultimately not yet tackled as basically every whiptail is a lot different.
So I think it would be nice if you could contribute the whiptail function as seperate PR.
Same for detect_os, but I think that can be incorporated into out core, as there are possibly already parts of that in core.
@MickLesk please correct me if I'm wrong. You know best about core.
There was a problem hiding this comment.
@CrazyWolf13 and @MickLesk :
- PR for
whiptailhelper-scripts: whiptail helper functions for dialog boxes #1760- moved back to the step-admin add-on until above PR is validated
detect_osfunction - giving up - moved back to the step-admin add-onresolve_ipfunction - giving up - moved back to the step-admin add-on
| # ============================================================================== | ||
| # Enable error handling | ||
| # | ||
| # set -E (enable errtrace option) | ||
| # set -e (enable errexit option) | ||
| # set -u (enable nounset option) | ||
| # set -o pipefail | ||
| # ============================================================================== | ||
| set -Eeuo pipefail | ||
| #trap 'error_handler' ERR | ||
|
|
||
| shopt -s expand_aliases | ||
| alias die='EXIT=$? LINE=$LINENO error_exit' | ||
| trap die ERR | ||
|
|
||
| function error_exit() { | ||
| trap - ERR | ||
| local reason="Unknown failure occured!" | ||
| local msg="${1:-$reason}" | ||
| msg_error "ERROR $EXIT at line $LINE: ${YW}$msg${CL}" 1>&2 | ||
| exit "$EXIT" | ||
| } |
There was a problem hiding this comment.
take a look at other addons especially the "-exporter ones
There was a problem hiding this comment.
take a look at other addons especially the "-exporter ones
From tools/addon/qbittorrent-exporter.sh
# Enable error handling
set -Eeuo pipefail
trap 'error_handler' ERR
load_functions
from tools/addon/all-templates.sh which is very closely to my solution (initial copy&paste from this one ...)
set -eEuo pipefail
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
function error_exit() {
trap - ERR
local DEFAULT='Unknown failure occured.'
local REASON="\e[97m${1:-$DEFAULT}\e[39m"
local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
msg "$FLAG $REASON" 1>&2
[ ! -z ${CTID-} ] && cleanup_ctid
exit $EXIT
}
I really need a simple die function with custom error messages:
$STD update-ca-certificates || die "Update of System CA Certificates failed!"
There was a problem hiding this comment.
ah my bad, that code was added later on.
Can't you use msg_warn "Update of System CA Certificates failed!" ?
There was a problem hiding this comment.
Intension of the die function:
- terminate (exit) with exit number
- with custom error message and
- additional trap information
The initial code fragment I've copy&paste was coming from our famous tteck (tteckster)
There was a problem hiding this comment.
@MickLesk has written the msg_warn func as far as I know.
There was a problem hiding this comment.
See https://github.com/community-scripts/ProxmoxVE/blob/main/misc/core.func:
a) By using your core functions I'm a little bit lost - error exit is NOT working:
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/error_handler.func)
# Enable error handling
#
set -Eeuo pipefail
trap 'error_handler' ERR
# Initialize all core functions (colors, formatting, icons, STD mode)
#
load_functions
# Main
#
msg_info "Start Main\n"
ls -lisa not_available.tmp || msg_error "expected exit with exit code"
msg_ok "Should never be reached"
Output - Not expected:
⠋ Start Main
ls: cannot access 'not_available.tmp': No such file or directory
✖️ expected exit with exit code
✔️ Should never be reached
b) The usage of tteck (tteckster) die function is working as expected:
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/error_handler.func)
# Enable error handling
#
set -Eeuo pipefail
#trap 'error_handler' ERR
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
function error_exit() {
trap - ERR
local reason="Unknown failure occured!"
local msg="${1:-$reason}"
msg_error "ERROR $EXIT at line $LINE: ${YW}$msg${CL}" 1>&2
exit "$EXIT"
}
# Initialize all core functions (colors, formatting, icons, STD mode)
#
load_functions
# Main
#
msg_info "Start Main\n"
ls -lisa not_available.tmp || die "expected exit with exit code"
msg_ok "Should never be reached"
Output - Works as designed:
⠋ Start Main
ls: cannot access 'not_available.tmp': No such file or directory
✖️ ERROR 2 at line 31: expected exit with exit code
c) How to use your core functions properly?
There was a problem hiding this comment.
Tteck is passed 1.5 year ago. We have other functions. Why shouldn’t it work? 580 other scripts work perfectly well with the core and the error_handler.
Incidentally, AllTemplates is the worst example you could possibly use; it’s hopelessly outdated, relies on the old architecture and has never been updated. Why? Because nobody uses it.
There was a problem hiding this comment.
Why shouldn’t it work?
Jung: Das war genau meine Frage!
Was wäre denn jetzt die Perfekte Lösung?
A simple code template would be appreciated ...
Removed outdated source calls and added whiptail, detect_os and resolve_IP helper functions back to the add-on.
Removed commented-out header function and its content.
|
@heinemannj Closing stale PR due to inactivity (no commits for 7 days after stale label). |
Scripts which are clearly AI generated and not further revised by the Author of this PR (in terms of Coding Standards and Script Layout) may be closed without review.
✍️ Description
New Add-On for
step-cahttps://community-scripts.org/scripts?q=step-ca
The Add-On can be used on any LXC (including the step-ca LXC) for CA and Certificate Maintenance.
Will replacing the
step-ca-admin.shon thestep-ca LXCto simplyfy the installation script (upcoming separate PR).🔗 Related PR / Issue
Link: #
community-scripts/ProxmoxVE#11504
✅ Prerequisites (X in brackets)
🛠️ Type of Change (X in brackets)
README,AppName.md,CONTRIBUTING.md, or other docs.🔍 Code & Security Review (X in brackets)
Code_Audit.md&CONTRIBUTING.mdguidelinesAppName.sh,AppName-install.sh,AppName.json)📋 Additional Information (optional)
Environment Variables introduced to support further automation:
📦 Application Requirements (for new scripts)
🌐 Source
Source: https://smallstep.com/ | Github: https://github.com/smallstep