mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-13 22:13:00 +00:00
permission handling in first time install script
This commit is contained in:
@@ -239,13 +239,15 @@ echo "-----------------------------------------------"
|
|||||||
|
|
||||||
# Ensure config directory exists
|
# Ensure config directory exists
|
||||||
mkdir -p "$PROJECT_ROOT_DIR/config"
|
mkdir -p "$PROJECT_ROOT_DIR/config"
|
||||||
|
chmod 755 "$PROJECT_ROOT_DIR/config" || true
|
||||||
|
|
||||||
# Create config_secrets.json from template if missing
|
# Create config_secrets.json from template if missing
|
||||||
if [ ! -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then
|
if [ ! -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then
|
||||||
if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.template.json" ]; then
|
if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.template.json" ]; then
|
||||||
echo "Creating config/config_secrets.json from template..."
|
echo "Creating config/config_secrets.json from template..."
|
||||||
cp "$PROJECT_ROOT_DIR/config/config_secrets.template.json" "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
cp "$PROJECT_ROOT_DIR/config/config_secrets.template.json" "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
||||||
chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
chown "$ACTUAL_USER:$ACTUAL_USER" "$PROJECT_ROOT_DIR/config/config_secrets.json" || true
|
||||||
|
chmod 640 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
||||||
echo "✓ Secrets file created from template"
|
echo "✓ Secrets file created from template"
|
||||||
else
|
else
|
||||||
echo "⚠ Template config/config_secrets.template.json not found; creating a minimal secrets file"
|
echo "⚠ Template config/config_secrets.template.json not found; creating a minimal secrets file"
|
||||||
@@ -256,7 +258,8 @@ if [ ! -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
chown "$ACTUAL_USER:$ACTUAL_USER" "$PROJECT_ROOT_DIR/config/config_secrets.json" || true
|
||||||
|
chmod 640 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
||||||
echo "✓ Minimal secrets file created"
|
echo "✓ Minimal secrets file created"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -444,9 +447,10 @@ if [ -f "$PROJECT_ROOT_DIR/config/config.json" ]; then
|
|||||||
echo "✓ Config file permissions set"
|
echo "✓ Config file permissions set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set proper permissions for secrets file (restrictive)
|
# Set proper permissions for secrets file (restrictive: owner rw, group r)
|
||||||
if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then
|
if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then
|
||||||
chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
chown "$ACTUAL_USER:$ACTUAL_USER" "$PROJECT_ROOT_DIR/config/config_secrets.json" || true
|
||||||
|
chmod 640 "$PROJECT_ROOT_DIR/config/config_secrets.json"
|
||||||
echo "✓ Secrets file permissions set"
|
echo "✓ Secrets file permissions set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,17 @@ class ConfigManager:
|
|||||||
with open(self.config_path, 'r') as f:
|
with open(self.config_path, 'r') as f:
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
|
|
||||||
# Load and merge secrets if they exist
|
# Load and merge secrets if they exist (be permissive on errors)
|
||||||
if os.path.exists(self.secrets_path):
|
if os.path.exists(self.secrets_path):
|
||||||
with open(self.secrets_path, 'r') as f:
|
try:
|
||||||
secrets = json.load(f)
|
with open(self.secrets_path, 'r') as f:
|
||||||
# Deep merge secrets into config
|
secrets = json.load(f)
|
||||||
self._deep_merge(self.config, secrets)
|
# Deep merge secrets into config
|
||||||
|
self._deep_merge(self.config, secrets)
|
||||||
|
except PermissionError as e:
|
||||||
|
print(f"Secrets file not readable ({self.secrets_path}): {e}. Continuing without secrets.")
|
||||||
|
except (json.JSONDecodeError, OSError) as e:
|
||||||
|
print(f"Error reading secrets file ({self.secrets_path}): {e}. Continuing without secrets.")
|
||||||
|
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user