Skip to content

Conversation

@renyijiu
Copy link
Collaborator

No description provided.

…iles without extension

This commit improves the SN file reading functionality in install.sh:

1. Added read_sn_from_file() function that supports:
   - Plain text files (.txt)
   - JSON format files (.json)
   - YAML format files (.yaml, .yml)
   - Key-value pair format
   - Files without extension

2. Enhanced file validation logic:
   - Support files without extension (e.g., "sn", "info")
   - For files without extension: if sn_field is provided, try structured formats first, fallback to plain text if not provided
   - For files with extension: validate extension is in allowed list (.txt, .json, .yaml, .yml)

3. Improved field matching behavior:
   - If sn_field is provided, must match successfully in the file, otherwise return error
   - If sn_field is not provided, treat file as plain text
   - This ensures data integrity and prevents silent failures

4. Error handling improvements:
   - Better error messages when field is not found
   - Handles cases where jq/yq tools are not available (fallback to grep/sed)
   - Proper handling of grep failures in set -e mode

5. Code improvements:
   - All comments and log messages in English
   - Better code organization and readability
   - Consistent error handling

The changes ensure that:
- Files with extension + sn_field: must match, error if not found
- Files without extension + sn_field: must match, error if not found
- Files without extension + no sn_field: treat as plain text
- .txt files: always treat as plain text (sn_field optional)
- Remove automatic REMOVE_CONFIG flag setting (uninstall.sh already handles config cleanup)
- Save SN value to SERIAL_NUM when using --sn_file (for manual --remove_config support)
- Add API response content logging for better debugging
- Improve error handling and logging throughout SN validation process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants