From 54124d2d9f9e0ab6fe87b3f5a1505bf91ce62a35 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 15 Jan 2023 18:31:45 -0300 Subject: [PATCH] Rewrite commands to use '/home/_portzap' --- bin/portzap | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/bin/portzap b/bin/portzap index fe95c57..912a85b 100755 --- a/bin/portzap +++ b/bin/portzap @@ -6,6 +6,8 @@ source="https://git.hardenedbsd.org/hardenedbsd/ports.git" stage_dir="/home/_portzap/ports" +clone_mode=007 +pull_mode=007 clone_mode=007 pull_mode=007 @@ -25,15 +27,21 @@ exit_on_missing_deps() { done } -user_is_root() { - user_id=$(id -u $(whoami)) - return $user_id = "0" +has_portzap_access() { + groups=$(id -Gn) + in_group=1 + for g in $groups; do + if [ $g="_portzap" ]; + then + in_group=0 + fi + done + return $in_group } user_is_not_root() { user_id=$(id -u $(whoami)) - result=$(test $user_id -ne "0") - return $result + return $(test $user_id -ne "0") } ## @@ -57,25 +65,33 @@ init() { clone() { if has_portzap_access then - echo "$stage_dir has already been cloned." - echo "Run 'portzap pull', or 'portzap rmtree' instead." - exit 1 + if [ -e "$stage_dir/.git" ]; + then + echo "$stage_dir has already been cloned." + echo "Run 'portzap pull', or 'portzap rmtree' instead." + exit 1 + fi + umask $clone_mode + git clone --depth 1 $source $stage_dir + else + echo "Permission denied" fi - git clone --depth 1 $source $stage_dir } pull() { - if user_is_root + if has_portzap_access then - echo "The pull command should not be run as root." - exit 1 - fi - if [ -e "$stage_dir/.git" ]; - then - cd $stage_dir - git pull --rebase origin hardenedbsd/main + if [ -e "$stage_dir/.git" ]; + then + umask $pull_mode + cd $stage_dir + git pull --rebase origin hardenedbsd/main + else + echo "Run 'portzap clone' first." + exit 1 + fi else - echo "Run 'portzap clone' first." + echo "Permission denied." exit 1 fi }