summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-12-17 11:01:24 +0100
committerGitHub <noreply@github.com>2022-12-17 11:01:24 +0100
commitb56917451dbb57a148bf5b997fb507632c6829fd (patch)
treeb508dc8174d3a848c2d0554eac8b6270b6f2c139
parent3ef1de3846e7ce2648935d65013dbb280d492531 (diff)
parent672b6cc486f140e5598abd41be9d5daebc422b40 (diff)
downloadvyos-1x-b56917451dbb57a148bf5b997fb507632c6829fd.tar.gz
vyos-1x-b56917451dbb57a148bf5b997fb507632c6829fd.zip
Merge pull request #1714 from c-po/current
op-mode: T707: explicitly use sudo when working with RAID devices
-rw-r--r--op-mode-definitions/show-raid.xml.in2
-rwxr-xr-xsrc/op_mode/show_raid.sh10
2 files changed, 10 insertions, 2 deletions
diff --git a/op-mode-definitions/show-raid.xml.in b/op-mode-definitions/show-raid.xml.in
index 8bf394552..2ae3fad6a 100644
--- a/op-mode-definitions/show-raid.xml.in
+++ b/op-mode-definitions/show-raid.xml.in
@@ -9,7 +9,7 @@
<script>${vyos_completion_dir}/list_raidset.sh</script>
</completionHelp>
</properties>
- <command>${vyos_op_scripts_dir}/show_raid.sh $3</command>
+ <command>sudo ${vyos_op_scripts_dir}/show_raid.sh $3</command>
</tagNode>
</children>
</node>
diff --git a/src/op_mode/show_raid.sh b/src/op_mode/show_raid.sh
index ba4174692..ab5d4d50f 100755
--- a/src/op_mode/show_raid.sh
+++ b/src/op_mode/show_raid.sh
@@ -1,5 +1,13 @@
#!/bin/bash
+if [ "$EUID" -ne 0 ]; then
+ # This should work without sudo because we have read
+ # access to the dev, but for some reason mdadm must be
+ # run as root in order to succeed.
+ echo "Please run as root"
+ exit 1
+fi
+
raid_set_name=$1
raid_sets=`cat /proc/partitions | grep md | awk '{ print $4 }'`
valid_set=`echo $raid_sets | grep $raid_set_name`
@@ -10,7 +18,7 @@ else
# This should work without sudo because we have read
# access to the dev, but for some reason mdadm must be
# run as root in order to succeed.
- sudo /sbin/mdadm --detail /dev/${raid_set_name}
+ mdadm --detail /dev/${raid_set_name}
else
echo "Must be administrator or root to display RAID status"
fi