Rewrite commands to use '/home/_portzap'

This commit is contained in:
0x1eef 2023-01-15 18:31:45 -03:00 committed by Robert
parent 56a73ed635
commit 54124d2d9f

View file

@ -6,6 +6,8 @@
source="https://git.hardenedbsd.org/hardenedbsd/ports.git" source="https://git.hardenedbsd.org/hardenedbsd/ports.git"
stage_dir="/home/_portzap/ports" stage_dir="/home/_portzap/ports"
clone_mode=007
pull_mode=007
clone_mode=007 clone_mode=007
pull_mode=007 pull_mode=007
@ -25,15 +27,21 @@ exit_on_missing_deps() {
done done
} }
user_is_root() { has_portzap_access() {
user_id=$(id -u $(whoami)) groups=$(id -Gn)
return $user_id = "0" 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_is_not_root() {
user_id=$(id -u $(whoami)) user_id=$(id -u $(whoami))
result=$(test $user_id -ne "0") return $(test $user_id -ne "0")
return $result
} }
## ##
@ -56,28 +64,36 @@ init() {
clone() { clone() {
if has_portzap_access if has_portzap_access
then
if [ -e "$stage_dir/.git" ];
then then
echo "$stage_dir has already been cloned." echo "$stage_dir has already been cloned."
echo "Run 'portzap pull', or 'portzap rmtree' instead." echo "Run 'portzap pull', or 'portzap rmtree' instead."
exit 1 exit 1
fi fi
umask $clone_mode
git clone --depth 1 $source $stage_dir git clone --depth 1 $source $stage_dir
else
echo "Permission denied"
fi
} }
pull() { pull() {
if user_is_root if has_portzap_access
then then
echo "The pull command should not be run as root."
exit 1
fi
if [ -e "$stage_dir/.git" ]; if [ -e "$stage_dir/.git" ];
then then
umask $pull_mode
cd $stage_dir cd $stage_dir
git pull --rebase origin hardenedbsd/main git pull --rebase origin hardenedbsd/main
else else
echo "Run 'portzap clone' first." echo "Run 'portzap clone' first."
exit 1 exit 1
fi fi
else
echo "Permission denied."
exit 1
fi
} }
unpack() { unpack() {