Skip to content

Commit

Permalink
[Installer] Adding Config File Support
Browse files Browse the repository at this point in the history
  • Loading branch information
RafagaBlanca committed Aug 16, 2023
1 parent 5087b91 commit 2c1ccba
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
53 changes: 53 additions & 0 deletions base-system/tools/installer/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#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;
}

19 changes: 18 additions & 1 deletion base-system/tools/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Binary file added base-system/tools/installer/read
Binary file not shown.
13 changes: 11 additions & 2 deletions docs/usage/how-to-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2c1ccba

Please sign in to comment.