|
97 | 97 | # Change the ownership of the volume to VOLUME_OWNER:VOLUME_GROUP if |
98 | 98 | # these environmental variables are defined. Without doing this libvirt |
99 | 99 | # cannot access the volume on RedHat based GNU/Linux distributions. |
100 | | -if [[ -z "$VOLUME_OWNER" || -z "$VOLUME_GROUP" ]]; then |
101 | | - # Avoid attempting to change permissions on volumes that are not file or |
102 | | - # directory based |
103 | | - if [[ -f "$output" || -d "$output" ]]; then |
104 | | - existing_owner="$(stat --format '%U' "$output")" |
105 | | - existing_group="$(stat --format '%G' "$output")" |
106 | | - new_owner="${VOLUME_OWNER:-$existing_owner}" |
107 | | - new_group="${VOLUME_GROUP:-$existing_group}" |
108 | | - output=$(chown "$new_owner":"$new_group" "$output" 2>1) |
109 | | - result=$? |
110 | | - if [[ $result -ne 0 ]]; then |
111 | | - echo "Failed to change ownership of the volume to $new_owner:$new_group" |
112 | | - echo "$output" |
113 | | - virsh vol-delete --pool "$POOL" --vol "$NAME" |
114 | | - exit $result |
115 | | - fi |
116 | | - else |
117 | | - echo "Setting ownership on volumes not backed by a file or directory is not supported" |
118 | | - exit 1 |
| 100 | +# Avoid attempting to change permissions on volumes that are not file or |
| 101 | +# directory based |
| 102 | +if [[ -f "$output" || -d "$output" ]]; then |
| 103 | + existing_owner="$(stat --format '%U' "$output")" |
| 104 | + existing_group="$(stat --format '%G' "$output")" |
| 105 | + new_owner="${VOLUME_OWNER:-$existing_owner}" |
| 106 | + new_group="${VOLUME_GROUP:-$existing_group}" |
| 107 | + output=$(chown "$new_owner":"$new_group" "$output" 2>1) |
| 108 | + result=$? |
| 109 | + if [[ $result -ne 0 ]]; then |
| 110 | + echo "Failed to change ownership of the volume to $new_owner:$new_group" |
| 111 | + echo "$output" |
| 112 | + virsh vol-delete --pool "$POOL" --vol "$NAME" |
| 113 | + exit $result |
119 | 114 | fi |
120 | 115 | fi |
121 | 116 |
|
|
0 commit comments