From 56a73ed63591b3dc54279e3d7325df1648f345a0 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 15 Jan 2023 18:29:09 -0300 Subject: [PATCH] Add 'portzap init' --- bin/portzap | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/bin/portzap b/bin/portzap index 59b2b84..fe95c57 100755 --- a/bin/portzap +++ b/bin/portzap @@ -5,7 +5,11 @@ # the HardenedBSD ports collection. source="https://git.hardenedbsd.org/hardenedbsd/ports.git" -stage_dir="/tmp/ports/" +stage_dir="/home/_portzap/ports" + +clone_mode=007 +pull_mode=007 +init_mode=707 ## # Utils @@ -36,16 +40,22 @@ user_is_not_root() { # Commands help() { - echo "Usage: portzap clone|pull|unpack|rmtree" + echo "Usage: portzap init|clone|pull|unpack|rmtree" +} + +init() { + if user_is_not_root; + then + echo "The init command should be run as root." + exit + fi; + umask $init_mode + pw userdel _portzap -r + pw useradd _portzap -m -s /sbin/nologin } clone() { - if user_is_root - then - echo "The clone command should not be run as root." - exit 1 - fi - if [ -e "$stage_dir/.git" ]; + if has_portzap_access then echo "$stage_dir has already been cloned." echo "Run 'portzap pull', or 'portzap rmtree' instead." @@ -79,19 +89,11 @@ unpack() { cp -Rfv /tmp/ports /usr/ } -rmtree() { - if [ -e $stage_dir ]; - then - echo "Please wait." - rm -rf $stage_dir - echo "OK: removed $stage_dir" - else - echo "$stage_dir does not exist." - exit 1 - fi -} - case $1 in + "init") + init + break + ;; "clone") exit_on_missing_deps clone @@ -114,4 +116,4 @@ case $1 in help break ;; -esac + esac