|
1 | 1 | #!/usr/bin/env bash |
2 | | -set -exo pipefail |
| 2 | +set -euo pipefail |
3 | 3 |
|
4 | 4 | usage() { |
5 | 5 | echo "Usage:" |
@@ -33,63 +33,74 @@ handle_nvidia_version() { |
33 | 33 | version=$(echo "$gpu_update" | cut -d' ' -f2) |
34 | 34 | fi |
35 | 35 |
|
36 | | - # Update version entry if version is available and file exists |
37 | | - if [ -n "$version" ] && [ -f NVIDIA_DRIVER_VERSION ]; then |
| 36 | + # Update version entry if version is available |
| 37 | + if [ -n "$version" ]; then |
38 | 38 | if grep -q "^${version_key} = " NVIDIA_DRIVER_VERSION; then |
39 | | - sed -i "s/^${version_key} = .*/${version_key} = \"${version}\"/" NVIDIA_DRIVER_VERSION |
| 39 | + if ! sed -i "s/^${version_key} = .*/${version_key} = \"${version}\"/" NVIDIA_DRIVER_VERSION; then |
| 40 | + echo "Failed to update NVIDIA driver version in NVIDIA_DRIVER_VERSION file" |
| 41 | + fi |
40 | 42 | fi |
41 | 43 | fi |
42 | 44 | } |
43 | 45 |
|
44 | | -readonly ami_type="$1" |
| 46 | +readonly ami_type="${1:-}" |
45 | 47 | if [ -z "$ami_type" ]; then |
46 | 48 | error "AMI_TYPE must be provided" |
47 | 49 | fi |
48 | 50 |
|
| 51 | +# Validate AMI type |
| 52 | +case "$ami_type" in |
| 53 | +al2 | al2023) |
| 54 | + # Valid AMI types |
| 55 | + ;; |
| 56 | +*) |
| 57 | + error "Invalid AMI type: $ami_type" |
| 58 | + ;; |
| 59 | +esac |
| 60 | + |
| 61 | +# Backup current release file and generate new one |
49 | 62 | cp release-$ami_type.auto.pkrvars.hcl release-$ami_type.old.hcl |
50 | 63 | ./generate-release-vars.sh $ami_type |
| 64 | + |
| 65 | +# Compare release files (excluding ami_version) |
51 | 66 | set +e |
52 | 67 | diff_val=$(diff <(grep -v ami_version release-$ami_type.old.hcl) <(grep -v ami_version release-$ami_type.auto.pkrvars.hcl)) |
53 | 68 | set -e |
54 | 69 |
|
55 | | -# Check for NVIDIA driver version for both AL2 and AL2023 |
56 | | -if [ "$ami_type" = "al2" ] || [ "$ami_type" = "al2023" ]; then |
57 | | - gpu_update=$(./scripts/check-update-security.sh "${ami_type}_gpu") |
58 | | - handle_nvidia_version "$ami_type" "$gpu_update" |
59 | | - if [[ $gpu_update == true* ]]; then |
60 | | - Update="true" |
61 | | - fi |
| 70 | +# Initialize update flag |
| 71 | +Update="false" |
| 72 | + |
| 73 | +# Check for NVIDIA driver version updates |
| 74 | +gpu_update=$(./scripts/check-update-security.sh "${ami_type}_gpu") |
| 75 | +handle_nvidia_version "$ami_type" "$gpu_update" |
| 76 | +if [[ $gpu_update == true* ]]; then |
| 77 | + Update="true" |
62 | 78 | fi |
63 | 79 |
|
64 | | -# If no difference in dependencies, check for security update |
| 80 | +# Check for security updates if no dependency changes |
65 | 81 | if [ -z "$diff_val" ]; then |
66 | | - Update="false" |
67 | | - case "$ami_type" in |
68 | | - "al2" | "al2023") |
69 | | - # Check security updates for each architecture type |
70 | | - amd_update=$(./scripts/check-update-security.sh $ami_type) |
71 | | - arm_update=$(./scripts/check-update-security.sh "${ami_type}_arm") |
72 | | - |
73 | | - # Combine results |
74 | | - if [[ $amd_update == true* ]] || [[ $arm_update == true* ]]; then |
75 | | - Update="true" |
76 | | - fi |
77 | | - ;; |
78 | | - *) |
79 | | - echo "Error: Invalid AMI type: $ami_type" |
80 | | - exit 1 |
81 | | - ;; |
82 | | - esac |
| 82 | + # Check security updates for each architecture type |
| 83 | + amd_update=$(./scripts/check-update-security.sh $ami_type) |
| 84 | + arm_update=$(./scripts/check-update-security.sh "${ami_type}_arm") |
| 85 | + |
| 86 | + # Combine results |
| 87 | + if [[ $amd_update == true* ]] || [[ $arm_update == true* ]]; then |
| 88 | + Update="true" |
| 89 | + fi |
83 | 90 | else |
84 | 91 | Update="true" |
85 | 92 | fi |
86 | 93 |
|
| 94 | +# Clean up temporary file |
87 | 95 | rm "release-$ami_type.old.hcl" |
88 | 96 |
|
| 97 | +# Handle git operations based on update status |
89 | 98 | if [ "$Update" = "true" ]; then |
90 | 99 | echo "Update exists for $ami_type" |
91 | 100 | git add release-$ami_type.auto.pkrvars.hcl |
92 | | - if [ -f NVIDIA_DRIVER_VERSION ] && ! git diff --quiet NVIDIA_DRIVER_VERSION; then |
| 101 | + |
| 102 | + # Add NVIDIA_DRIVER_VERSION if it has changes |
| 103 | + if ! git diff --quiet NVIDIA_DRIVER_VERSION; then |
93 | 104 | echo "NVIDIA driver version changes detected" |
94 | 105 | git add NVIDIA_DRIVER_VERSION |
95 | 106 | fi |
|
0 commit comments