MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / buildDirectBootstrapScript

Function buildDirectBootstrapScript

internal/ui/plugins/ansible/plugin.go:1761–1932  ·  view source on GitHub ↗
(cfg cfgpkg.AnsibleBootstrapConfig, keyContent string, dryRun bool)

Source from the content-addressed store, hash-verified

1759}
1760
1761func buildDirectBootstrapScript(cfg cfgpkg.AnsibleBootstrapConfig, keyContent string, dryRun bool) string {
1762 userQuoted := shellSingleQuote(strings.TrimSpace(cfg.Username))
1763 uidQuoted := shellSingleQuote(formatBootstrapUID(cfg.UID))
1764 shellQuoted := shellSingleQuote(strings.TrimSpace(cfg.Shell))
1765 passQuoted := shellSingleQuote(strings.TrimSpace(cfg.Password))
1766 keyQuoted := shellSingleQuote(strings.TrimSpace(keyContent))
1767 modeQuoted := shellSingleQuote(strings.TrimSpace(cfg.SudoersFileMode))
1768
1769 return fmt.Sprintf(`#!/bin/sh
1770set -eu
1771
1772BOOTSTRAP_USER=%s
1773BOOTSTRAP_UID=%s
1774BOOTSTRAP_SHELL=%s
1775BOOTSTRAP_PASS=%s
1776BOOTSTRAP_KEY=%s
1777SUDOERS_MODE=%s
1778DRY_RUN=%t
1779CREATE_HOME=%t
1780INSTALL_KEY=%t
1781SET_PASSWORD=%t
1782GRANT_SUDO=%t
1783
1784changed=0
1785applied_create_user=0
1786applied_update_shell=0
1787applied_install_authorized_key=0
1788applied_set_password=0
1789applied_create_sudoers=0
1790
1791if [ "$DRY_RUN" = "true" ]; then
1792 would_change=0
1793
1794 if ! id -u "$BOOTSTRAP_USER" >/dev/null 2>&1; then
1795 echo "would_create_user=1"
1796 if [ -n "$BOOTSTRAP_UID" ]; then
1797 echo "plan_useradd=useradd -u $BOOTSTRAP_UID -s $BOOTSTRAP_SHELL $BOOTSTRAP_USER"
1798 else
1799 echo "plan_useradd=useradd -s $BOOTSTRAP_SHELL $BOOTSTRAP_USER"
1800 fi
1801 would_change=$((would_change+1))
1802 else
1803 echo "would_create_user=0"
1804 if [ -n "$BOOTSTRAP_UID" ]; then
1805 CURRENT_UID="$(id -u "$BOOTSTRAP_USER")"
1806 if [ "$CURRENT_UID" != "$BOOTSTRAP_UID" ]; then
1807 echo "would_update_uid=1"
1808 echo "plan_usermod=usermod -u $BOOTSTRAP_UID $BOOTSTRAP_USER"
1809 would_change=$((would_change+1))
1810 else
1811 echo "would_update_uid=0"
1812 fi
1813 fi
1814 fi
1815
1816 if [ "$INSTALL_KEY" = "true" ] && [ -n "$BOOTSTRAP_KEY" ]; then
1817 if id -u "$BOOTSTRAP_USER" >/dev/null 2>&1; then
1818 HOME_DIR="$(getent passwd "$BOOTSTRAP_USER" | cut -d: -f6)"

Calls 2

formatBootstrapUIDFunction · 0.85
shellSingleQuoteFunction · 0.70