Skip to content

Commit 8caf5e5

Browse files
authored
feat: allow adding SSH authorized key for root (advanced settings) by @dsiebel (#1456)
* feat: allow adding SSH authorized key for root (advanced settings) by @dsiebel * remove spaces
1 parent f8ab39e commit 8caf5e5

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

misc/build.func

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ color() {
3636
INFO="${TAB}💡${TAB}${CL}"
3737
OS="${TAB}🖥️${TAB}${CL}"
3838
OSVERSION="${TAB}🌟${TAB}${CL}"
39-
CONTAINERTYPE="${TAB}📦${TAB}${CL}"
39+
CONTAINERTYPE="${TAB}📦${TAB}${CL}"
4040
DISKSIZE="${TAB}💾${TAB}${CL}"
4141
CPUCORE="${TAB}🧠${TAB}${CL}"
4242
RAMSIZE="${TAB}🛠️${TAB}${CL}"
@@ -283,16 +283,17 @@ base_settings() {
283283
MAC=""
284284
VLAN=""
285285
SSH="no"
286+
SSH_AUTHORIZED_KEY=""
286287
TAGS="community-script;"
287-
288+
288289
# Override default settings with variables from ct script
289290
CT_TYPE=${var_unprivileged:-$CT_TYPE}
290291
DISK_SIZE=${var_disk:-$DISK_SIZE}
291292
CORE_COUNT=${var_cpu:-$CORE_COUNT}
292293
RAM_SIZE=${var_ram:-$RAM_SIZE}
293294
VERB=${var_verbose:-$VERBOSE}
294295
TAGS="${TAGS}${var_tags:-}"
295-
296+
296297
# Since these 2 are only defined outside of default_settings function, we add a temporary fallback. TODO: To align everything, we should add these as constant variables (e.g. OSTYPE and OSVERSION), but that would currently require updating the default_settings function for all existing scripts
297298
if [ -z "$var_os" ]; then
298299
var_os="debian"
@@ -314,9 +315,9 @@ echo_default() {
314315
echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}"
315316
echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}"
316317
echo -e "${CONTAINERTYPE}${BOLD}${DGN}Container Type: ${BGN}$CT_TYPE_DESC${CL}"
317-
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}GB${CL}"
318+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE} GB${CL}"
318319
echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}"
319-
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MiB${CL}"
320+
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}"
320321
echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}${CT_ID}${CL}"
321322
if [ "$VERB" == "yes" ]; then
322323
echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}Enabled${CL}"
@@ -463,13 +464,13 @@ advanced_settings() {
463464
if DISK_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then
464465
if [ -z "$DISK_SIZE" ]; then
465466
DISK_SIZE="$var_disk"
466-
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}GB${CL}"
467+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE} GB${CL}"
467468
else
468469
if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
469470
echo -e "{INFO}${HOLD}${RD} DISK SIZE MUST BE AN INTEGER NUMBER!${CL}"
470471
advanced_settings
471472
fi
472-
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}GB${CL}"
473+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE} GB${CL}"
473474
fi
474475
else
475476
exit_script
@@ -489,9 +490,9 @@ advanced_settings() {
489490
if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then
490491
if [ -z "$RAM_SIZE" ]; then
491492
RAM_SIZE="$var_ram"
492-
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MiB${CL}"
493+
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}"
493494
else
494-
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MiB${CL}"
495+
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}"
495496
fi
496497
else
497498
exit_script
@@ -649,6 +650,15 @@ advanced_settings() {
649650
echo -e "${ROOTSSH}${BOLD}${DGN}Root SSH Access: ${BGN}$SSH${CL}"
650651
fi
651652

653+
if [[ "${SSH}" == "yes" ]]; then
654+
SSH_AUTHORIZED_KEY="$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "SSH Authorized key for root (leave empty for none)" 8 58 --title "SSH Key" 3>&1 1>&2 2>&3)"
655+
656+
if [[ -z "${SSH_AUTHORIZED_KEY}" ]]; then
657+
echo "Warning: No SSH key provided."
658+
fi
659+
else
660+
SSH_AUTHORIZED_KEY=""
661+
fi
652662
if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
653663
VERB="yes"
654664
else
@@ -697,15 +707,15 @@ install_script() {
697707
header_info
698708
echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME${CL}"
699709
VERB="no"
700-
base_settings "$VERB"
710+
base_settings "$VERB"
701711
echo_default
702712
break
703713
;;
704714
2)
705715
header_info
706-
echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME (${SEARCH}${BL}Verbose)${CL}"
716+
echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME (${SEARCH}Verbose)${CL}"
707717
VERB="yes"
708-
base_settings "$VERB"
718+
base_settings "$VERB"
709719
echo_default
710720
break
711721
;;
@@ -729,13 +739,13 @@ install_script() {
729739
check_container_resources() {
730740
# Check actual RAM & Cores
731741
current_ram=$(free -m | awk 'NR==2{print $2}')
732-
current_cpu=$(nproc)
742+
current_cpu=$(nproc)
733743

734744
# Check whether the current RAM is less than the required RAM or the CPU cores are less than required
735745
if [[ "$current_ram" -lt "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then
736746
echo -e "\n${INFO}${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
737747
echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
738-
read -r -p "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? <yes/No> " prompt
748+
read -r -p "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? <yes/No> " prompt
739749
# Check if the input is 'yes', otherwise exit with status 1
740750
if [[ ! ${prompt,,} =~ ^(yes)$ ]]; then
741751
echo -e "${CROSS}${HOLD} ${YWB}Exiting based on user input.${CL}"
@@ -754,7 +764,7 @@ check_container_storage() {
754764
if (( usage > 80 )); then
755765
# Prompt the user for confirmation to continue
756766
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
757-
read -r -p "Continue anyway? <y/N> " prompt
767+
read -r -p "Continue anyway? <y/N> " prompt
758768
# Check if the input is 'y' or 'yes', otherwise exit with status 1
759769
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
760770
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"

0 commit comments

Comments
 (0)