diff --git a/base-system/tools/installer/config.c b/base-system/tools/installer/config.c new file mode 100644 index 00000000..85d2595c --- /dev/null +++ b/base-system/tools/installer/config.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#define MAX_LINE_LENGTH 100 +#define MAX_CONFIGS 10 + +struct Config { + char key[MAX_LINE_LENGTH]; + char value[MAX_LINE_LENGTH]; +}; + +int main(int argc, char *argv[]) { + + FILE *file = fopen(argv[1], "r"); + if (file == NULL) { + perror("The file doesn't exist"); + return 1; + } + + struct Config config[MAX_CONFIGS]; + int configCount = 0; + + char line[MAX_LINE_LENGTH]; + while (fgets(line, sizeof(line), file)) { + if (line[0] == '#') { + continue; + } + + char *key = strtok(line, "="); + char *value = strtok(NULL, "\n"); + + if (key) { + strcpy(config[configCount].key, key); + if (value) { + strcpy(config[configCount].value, value); + } else { + config[configCount].value[0] = '\0'; + } + configCount++; + } + } + + fclose(file); + + + for (int i = 0; i < configCount; i++) { + printf("%s\n", config[i].value); + } + + return 0; +} + diff --git a/base-system/tools/installer/install.sh b/base-system/tools/installer/install.sh index 4077db20..8fbe29f3 100755 --- a/base-system/tools/installer/install.sh +++ b/base-system/tools/installer/install.sh @@ -54,6 +54,7 @@ NEW_PASSWORD="" INSTANCE_IP_ADDRESS="" INSTANCE_IP_MASK="" INSTANCE_IP_GATEWAY="" +CONFIG_FILE_PATH="" while [ "$#" -gt 0 ]; do case "$1" in --root-password) @@ -101,9 +102,25 @@ while [ "$#" -gt 0 ]; do shift 2 fi ;; + --config-file | -ig) + if [ -n "$2" ]; then + CONFIG_FILE_PATH="$2" + output=$(./read $CONFIG_FILE_PATH) + NEW_PASSWORD=$(echo "$output" | sed -n 1p) + DIRECTIVES_FILE_URL=$(echo "$output" | sed -n 2p) + DIRECTIVES_SERVER_IP=$(echo "$output" | sed -n 3p) + INSTANCE_IP_ADDRESS=$(echo "$output" | sed -n 4p) + INSTANCE_IP_MASK=$(echo "$output" | sed -n 5p) + INSTANCE_IP_GATEWAY=$(echo "$output" | sed -n 6p) + shift 2 + else + echo "Error: option --config-file requires an argument" >&2 + exit 1 + fi + ;; -h | --help) echo "Installs the current huronOS into an usb" - echo "Usage: ./install.sh [--root-password PASSWORD] [--directives-url URL] [--directives-server-ip IP] [--instance-ip-address IP --instance-ip-mask NUMBER --instance-ip-gateway IP]" + echo "Usage: ./install.sh [--root-password PASSWORD] [--directives-url URL] [--directives-server-ip IP] [--instance-ip-address IP --instance-ip-mask NUMBER --instance-ip-gateway IP] [--config-file FILE]" exit 1 ;; # Whichever other parameter passed, we know nothing about that here diff --git a/base-system/tools/installer/read b/base-system/tools/installer/read new file mode 100644 index 00000000..fb916908 Binary files /dev/null and b/base-system/tools/installer/read differ diff --git a/docs/usage/how-to-install.md b/docs/usage/how-to-install.md index 8ed54e51..721f87c1 100644 --- a/docs/usage/how-to-install.md +++ b/docs/usage/how-to-install.md @@ -82,9 +82,18 @@ sidebar_position: 1 2. Execute the installer, chose one of this options: - **Passing all the configurations in one go** ```bash - ./install.sh --directives-url http://site.com/directives.hdf --directives-server-ip 1.1.1.1 --root-password toor --instance-ip-address 192.168.1.1 --instance-ip-mask 24 --instance-ip-gateway 192.168.1.254 + ./install.sh --directives-url http://site.com/directives.hdf --directives-server-ip 1.1.1.1 --root-password toor --instance-ip-address 192.168.1.1 --instance-ip-mask 24 --instance-ip-gateway 192.168.1.254 --config-file config.conf ``` - + - **Using a config file** + ```bash + ./install.sh --config-file config.conf + ``` + And your config file should look like this: + ``` + #Installer config + PASSWORD=toor + ``` + - **Fill the prompts:** 1. Write the **directives url** to sync with, please **paste the URL you previously set up**. If you don't have one, just leave it blank _(be aware that sync won't work)_, this can be changed after the installation in the (`HURONOS/data/configs/sync-server.conf` file of the huronOS usb). 2. Write the **directives server IP** to force the firewall exception to this specific server. You can leave it blank if you want to fallback to DNS resolution.