-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add logic to handle multiple arrays. #85
Comments
This is doable. This script is rough, but works. Written with ChatGPT in less than 3 questions, no manual adjustment. Can be improved and implemented in the main AIO Script. I can work on it, but first I have to push some changes to the dev branch and I don't want them to conflict. #!/bin/bash
search_conf_files() {
folder="$1"
# Check if the directory exists
if [ ! -d "$folder" ]; then
echo "Directory $folder does not exist."
return 1
fi
conf_files=("$folder"/omv-snapraid-*.conf)
echo "Searching in folder: $folder"
echo "Found files matching pattern: ${conf_files[@]}"
if [ ${#conf_files[@]} -eq 0 ]; then
echo "No omv-snapraid-.conf files found in $folder"
return 1
elif [ ${#conf_files[@]} -eq 1 ]; then
echo "Found 1 omv-snapraid-.conf file: ${conf_files[0]}"
single_conf_file="${conf_files[0]}"
return 0
else
echo "Found multiple omv-snapraid-.conf files:"
for file in "${conf_files[@]}"; do
echo "$file"
done
return 2
fi
}
# Usage example:
search_conf_files "/etc/snapraid/"
result=$?
if [ $result -eq 0 ]; then
# Only one omv-snapraid-.conf file found, you can proceed with it
echo "Proceeding with the single omv-snapraid-.conf file: $single_conf_file"
# Use $single_conf_file variable wherever you need the file path
elif [ $result -eq 2 ]; then
# Multiple omv-snapraid-.conf files found, stopping the script
echo "Stopping the script due to multiple omv-snapraid-.conf files."
else
# No omv-snapraid-.conf files found, handle this case accordingly
echo "Handle the case when no omv-snapraid-.conf files are found or the directory does not exist."
fi |
I have pushed the changes (Snapraid config file check and notifiy) so we can start working on this. Here's an updated (rough) version, which has updated messages and notify logic: #!/bin/bash
function pick_snapraid_conf_file() {
search_conf_files "/etc/snapraid"
result=$?
if [ $result -eq 0 ]; then
# Only one SnapRAID config file found, proceeding
echo "Proceeding with the single omv-snapraid-.conf file: $SNAPRAID_CONF"
elif [ $result -eq 2 ]; then
# Multiple SnapRAID config files found, stopping the script
echo "Stopping the script due to multiple SnapRAID configuration files. Please choose one config file and update your settings in ""$CONFIG_FILE"". SnapRAID config files to be chosen:"
for file in "${conf_files[@]}"; do
echo "$file"
done
mklog "WARN: Stopping the script due to multiple SnapRAID configuration files. Please pick up one config file and update your settings in ""$CONFIG_FILE""."
SUBJECT="[WARNING] - Multiple SnapRAID configuration files!"
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
NOTIFY_OUTPUT="$SUBJECT Stopping the script due to multiple SnapRAID configuration files. Please pick up one config file and update your settings in "$CONFIG_FILE"."
notify_warning
if [ "$EMAIL_ADDRESS" ]; then
trim_log < "$TMP_OUTPUT" | send_mail
fi
exit 1;
else
# No SnapRAID conf file found, stopping the script
echo "SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file ""$SNAPRAID_CONF"" does not exist."
mklog "WARN: SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file ""$SNAPRAID_CONF"" does not exist."
SUBJECT="[WARNING] - SnapRAID configuration file not found!"
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
notify_warning
if [ "$EMAIL_ADDRESS" ]; then
trim_log < "$TMP_OUTPUT" | send_mail
fi
exit 1;
fi
}
search_conf_files() {
folder="$1"
# Check if the directory exists
if [ ! -d "$folder" ]; then
echo "Directory $folder does not exist."
return 1
fi
conf_files=("$folder"/omv-snapraid-*.conf)
#echo "Searching in folder: $folder"
#echo "Found files matching pattern: ${conf_files[@]}"
# if no files are found
if [ ${#conf_files[@]} -eq 0 ]; then
return 1
# if one file is found
elif [ ${#conf_files[@]} -eq 1 ]; then
$SNAPRAID_CONF="${conf_files[0]}"
return 0
# if multiple files are found
else
return 2
fi
}
pick_snapraid_conf_file |
@tehniemer I have added a lot of logic to pick up the OMV7 config file automatically. Can you please help me testing on your side? The logic is the following: If the SnapRAID config file referenced in
Output as usual is fully featured: screen, log file, email and notification. I've tested on OMV7 several scenarios:
Later today I'll test on my OMV6 real server. I want this to be the last change before release. Since OMV7 is out I want to act fast! |
I just pulled the dev branch over to my fork and will test over the next few days. There are a lot of changes in this update, will this be a major version bump? One thing I will comment on right away that if the script is going to exit if multiple |
Next release will be 3.3 which is a major release compared to 3.2. So yeah there might me many changes since your last pull/PR.
Not sure if I understand what you mean. To use multiple arrays the user can rely on the multi scipt-config functionality that I built some months ago, you might have missed it. From the dev README:
|
Again, I failed to read the right documentation, that's exactly what I was envisioning. My apologies. |
I ran a test and it completed successfully with my single array on OMV7, but I came across a couple of oddities. I received my normal Telegram notification that the script started, but not that it finished. I also did not receive the email summary I normally do even though the script said it was sent. I'll dig into this a bit more later. edit: |
I have ran multiple tests today on a OMV7 VM, always received the final notification. Since you got your email 5 mins later, maybe you got some network errors? At the moment any error from curl would be suppressed, so we would never know what happened. |
I'm thinking as much, I'll keep monitoring it. |
Everything has been working as expected for the last week or so. |
This is a continuation of the discussion of #80
OMV7 allows for configuring multiple SnapRAID arrays, it would be nice if this script could be configured similarly.
The text was updated successfully, but these errors were encountered: