Skip to content

Commit

Permalink
Allow running install-dependencies script as root (#978)
Browse files Browse the repository at this point in the history
Currently, we always run privilege commands in the script with `sudo`.
This makes the script unusable if running as the root user, which we
might want to do in some environments such as in a container.

Signed-off-by: Monthon Klongklaew <monthonk@amazon.com>
  • Loading branch information
monthonk authored Aug 9, 2024
1 parent 299f19e commit 8869934
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
10 changes: 8 additions & 2 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ inputs:
required: false
type: boolean
default: false
run-as-root:
description: "Install as root user"
required: false
type: boolean
default: false
runs:
using: "composite"
steps:
Expand All @@ -29,7 +34,8 @@ runs:
--fuse-version ${{ inputs.fuseVersion }} \
${{ fromJSON(inputs.llvm) && '--with-llvm' || '' }} \
${{ fromJSON(inputs.libunwind) && '--with-libunwind' || '' }} \
${{ fromJSON(inputs.fio) && '--with-fio' || '' }}
${{ fromJSON(inputs.fio) && '--with-fio' || '' }} \
${{ fromJSON(inputs.run-as-root) && '--run-as-root' || '' }}
- name: Configure FUSE to allow other users to access FS
shell: bash
run: echo 'user_allow_other' | sudo tee -a /etc/fuse.conf
run: echo 'user_allow_other' | ${{ !fromJSON(inputs.run-as-root) && 'sudo' || '' }} tee -a /etc/fuse.conf
26 changes: 18 additions & 8 deletions .github/actions/install-dependencies/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ $ENHANCED_GETOPT -ne 4 ]]; then
exit 1
fi

LONGOPTS="fuse-version:,with-fio,with-libunwind,with-llvm,dry-run"
LONGOPTS="fuse-version:,with-fio,with-libunwind,with-llvm,dry-run,run-as-root"
getopt --quiet-output --long=$LONGOPTS --name "$0" -- "$@"
if [[ $? -ne 0 ]]; then
echo "couldn't read arguments" >&2
Expand All @@ -19,6 +19,7 @@ dry_run=false
install_llvm=false
install_fio=false
install_libunwind=false
run_as_root=false
unset -v fuse_version

while true; do
Expand All @@ -43,6 +44,10 @@ while true; do
install_llvm=true
shift
;;
--run-as-root)
run_as_root=true
shift
;;
--)
shift
break
Expand Down Expand Up @@ -76,6 +81,11 @@ fi
os_release_id=$(cat /etc/os-release | grep "^ID=" | cut -d '=' -f2 | tr -d '"')

package_list="jq"
privilege_escalation_cmd="sudo"

if [[ $run_as_root == true ]]; then
privilege_escalation_cmd=""
fi

case "$os_release_id" in
amzn)
Expand Down Expand Up @@ -158,15 +168,15 @@ echo "Package list to install: \"${package_list}\""
if [[ $dry_run == false ]]; then
case $os_release_id in
amzn)
sudo yum install -y $package_list
type -p yum-config-manager >/dev/null || sudo yum install yum-utils -y
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo -y
sudo yum install gh -y
sudo yum update gh -y
$privilege_escalation_cmd yum install -y $package_list
type -p yum-config-manager >/dev/null || $privilege_escalation_cmd yum install yum-utils -y
$privilege_escalation_cmd yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo -y
$privilege_escalation_cmd yum install gh -y
$privilege_escalation_cmd yum update gh -y
;;
ubuntu)
sudo apt-get -q update
sudo apt-get install -y $package_list
$privilege_escalation_cmd apt-get -q update
$privilege_escalation_cmd apt-get install -y $package_list
;;
*)
echo "no distro specific config for $OS_RELEASE_ID" &>2
Expand Down

0 comments on commit 8869934

Please sign in to comment.