From b01545665ee2cb60142f54a98d290f9ee6a89a28 Mon Sep 17 00:00:00 2001 From: Yuri Sibirski <31861444+ysibirski@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:17:23 -0400 Subject: [PATCH] Do not run as root init.sh (#21) --- logs/.gitignore | 2 ++ scripts/init.sh | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 logs/.gitignore diff --git a/logs/.gitignore b/logs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/scripts/init.sh b/scripts/init.sh index 5e8d320..0ee7765 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -9,6 +9,14 @@ echo -e "\n\033[1m=== Checking all the requirements ===\033[0m" verify_required_commands +# Making sure the script is not being run as root +LOCAL_USER_ID="$(id -u)" +LOCAL_GROUP_ID="$(id -g)" +if [ "${LOCAL_USER_ID}" == 0 ] || [ "${LOCAL_GROUP_ID}" == 0 ]; then + echo -e "\n\033[0;31m\033[1m=== Error: This script should not be run as root. Exiting ===\033[0m\n" + exit 1 +fi + echo -e "\n\033[1mWhat kind of node type would you like to run: \033[0m" select role_value in rpc forger; do if [ -n "${role_value}" ]; then @@ -81,8 +89,6 @@ if ! [ -f "${ENV_FILE}" ]; then sed -i "s/SCNODE_NET_NODENAME=.*/SCNODE_NET_NODENAME=${SCNODE_NET_NODENAME}/g" "${ENV_FILE}" # Setting local user and group in docker containers - LOCAL_USER_ID="$(id -u)" - LOCAL_GROUP_ID="$(id -g)" echo -e "\n\033[1m=== Setting up the docker containers local user and group ids ===\033[0m\n" echo -e "The uid:gid with which to run the processes inside of the container will default to ${LOCAL_USER_ID}:${LOCAL_GROUP_ID}" read -rp "Do you want to change the user (please answer 'no' if you don't know what you are doing) ? ('yes' or 'no') " user_group_answer