-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
Centralize all standard LXC options to avoid code duplication #322
Conversation
If this get merged, I will do a second PR to go back and cleanup all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea.
@remz1337 I don't think a bulk script update should be done, I think it would be better to merge this, and script authors update scripts as we go, ensuring there are no side effects. |
Standard HDD size 4GB is a bit too much I think.we have some scripts with less. How do you set an LXC to Privileged? What about the alpine scripts? How do you set the script to verbose? It must be understandable for every beginner. Many questions... 😅 |
We should also consider that this will make it harder for contributors to know what settings exist, though everyone probably just copies it today without thinking about it anyway |
Co-authored-by: Håvard Gjøby Thom <[email protected]>
15d8382
Co-authored-by: Håvard Gjøby Thom <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, we can use documentation to ensure users are able to understand what options can be overridden.
I approved @havardthom changes to wording. We need one more approval for this to be merged. I think it makes a lot of sense and I will volunteer to write some documentation. |
@MickLesk checking in with you on this. This is a major change so I think we need consensus rather than just two approvals. |
@@ -491,6 +522,7 @@ install_script() { | |||
NEXTID=$(pvesh get /cluster/nextid) | |||
timezone=$(cat /etc/timezone) | |||
header_info | |||
base_settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its wrong here? Need to replace with Row 529 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, essentially you load all the standard (base) settings (eg. 4GB HDD, 512Mb RAM, 1 CPU...) with the base_settings
function, then calling default_settings
allows to overide them with whatever is defined in the actual installation script (eg. 20Gb HDD, 4CPU...)
It must be possible to overwrite the following functions by default. (From the LXC Install Script): CT_TYPE="$var_unprivileged"
DISK_SIZE="$var_disk”
CORE_COUNT="$var_cpu”
RAM_SIZE="$var_ram” As Example for this function header_info {
clear
cat <<"EOF"
__ __
/ //_/___ ____ ___ ____ _____ _
/ ,< / __ \/ __ `__ \/ __ `/ __ `/
/ /| / /_/ / / / / / / /_/ / /_/ /
/_/ |_\____/_/ /_/ /_/\__, /\__,_/
/____/
EOF
}
header_info
echo -e "Loading..."
APP="Komga"
var_disk="4"
var_cpu="1"
var_ram="2048"
var_os="debian"
var_version="12"
variables
color
catch_errors
function default_settings() {
CT_TYPE="1"
PW=""
CT_ID=$NEXTID
HN=$NSAPP
DISK_SIZE="$var_disk"
CORE_COUNT="$var_cpu"
RAM_SIZE="$var_ram"
BRG="vmbr0"
NET="dhcp"
GATE=""
APT_CACHER=""
APT_CACHER_IP=""
DISABLEIP6="no"
MTU=""
SD=""
NS=""
MAC=""
VLAN=""
SSH="no"
VERB="no"
echo_default
}
function update_script() {
header_info
check_container_storage
check_container_resources vs. Komga new: function header_info {
clear
cat <<"EOF"
__ __
/ //_/___ ____ ___ ____ _____ _
/ ,< / __ \/ __ `__ \/ __ `/ __ `/
/ /| / /_/ / / / / / / /_/ / /_/ /
/_/ |_\____/_/ /_/ /_/\__, /\__,_/
/____/
EOF
}
header_info
echo -e "Loading..."
APP="Komga"
var_unprivileged="1"
var_disk="4"
var_cpu="1"
var_ram="2048"
var_os="debian"
var_version="12"
variables
color
catch_errors
base_settings
function update_script() {
header_info
check_container_storage
check_container_resources and in build.func the base_settings: base_settings() {
# Default Settings
CT_TYPE="1"
DISK_SIZE="4"
CORE_COUNT="1"
RAM_SIZE="1024"
# Changed From CT.sh
CT_TYPE=${var_unprivileged:-$CT_TYPE}
DISK_SIZE=${var_disk:-$DISK_SIZE}
CORE_COUNT=${var_cpu:-$CORE_COUNT}
RAM_SIZE=${var_ram:-$RAM_SIZE}
# Other Default Settings (unchangeble)
PW=""
CT_ID=$NEXTID
HN=$NSAPP
BRG="vmbr0"
NET="dhcp"
GATE=""
APT_CACHER=""
APT_CACHER_IP=""
DISABLEIP6="no"
MTU=""
SD=""
NS=""
MAC=""
VLAN=""
SSH="no"
VERB="no"
# 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
if [ -z "$var_os" ]; then
var_os="debian"
fi
if [ -z "$var_version" ]; then
var_version="12"
fi
} |
Not a fan. Having it right there, makes it simple for everyone to know, what is up. |
Hey, catching up on this. Thanks for your comments @MickLesk
Yes maybe we can set it it 2 or 3 as default, I don't mind. For me, default should be enough to spin up an "empty" container (eg. debian, without anything else)
this doesn't change, "
Not sure about this, I will have to check.
same here, "
Let me know if you have any other questions And regarding your other comment (I won't be quoting everything, but the one that start with):
If you do it that way, then it's not possible anymore for the scripts to override other settings such as VLAN, VERB... The goal of this PR is more about removing the need for every script to redefine things that are always standard (like |
@havardthom regarding your comment
We could create some documentation (either MD file in the repo or a page in the wiki) with all the possible options + values. And maybe what we do is keep some common settings commented in there (so they only have to uncomment is they want to override them)? |
My comments above was old. I think you should look at the last idea I had, I think that can or should be the only right solution..😅 |
You mean the example you gave with Komga? With your suggestion, scripts can't override some defaults if needed (like changing |
I checked some alpine scripts. My PR would work with them too, no issues |
Ive build an complete rework of this logic: Advanced Settings (i know cores Icon missing in this screenshot) Here is the git change in build.func: Here is the git change of nextpvr.sh (CT): Feel free to test all variables with: bash -c "$(wget -qLO - https://raw.githubusercontent.com/MickLesk/Proxmox_DEV/refs/heads/main/ct/nextpvr.sh)" |
Who defines the default settings? As a user of the scripts, I do find it repetitive to need to set the same things over and over again. I'd like to be able to set my own preferred settings. My personally I always select Debian 12. This would be really cool for the user to define. So in our case, we run a Proxmox Helper Script Defaults script in PVE shell and we go through each option: |
This exceeds the scope and would be possible (if it can be migrated without any problems at all) sometime in mid-2025. So many things need to be changed that you cannot imagine. The fact that the scripts probably run on more than 25,000 Proxmox servers must also be taken into consideration. We want to keep it clean, simple and easy to understand. |
Note
We are meticulous when it comes to merging code into the main branch, so please understand that we may reject pull requests that do not meet the project's standards. It's never personal. Also, game-related scripts have a lower chance of being merged.
Description
Add a function,
base_settings
, to centralize all common options so that scripts only need to define settings that need to be overridden. For the great majority of scripts, all the options use the default values fordefault_settings
. Key settings are already captured outside of thedefault_settings
function:var_XXX
(eg.var_disk
,var_cpu
...)With this PR, the default_settings function in scripts could go from:
to
and in case a script needs to overwrite an additional setting, simply add it back, like this:
I've been using this in my fork for some time. It's great when you need to add a new default variable, you don't need to update back all the scripts. Plus, it's good practice to avoid duplication of information.
Type of change
Please check the relevant option(s):
Prerequisites
The following efforts must be made for the PR to be considered. Please check when completed: