First commit
This commit is contained in:
commit
535c05e713
3 changed files with 122 additions and 0 deletions
0
.projectile
Normal file
0
.projectile
Normal file
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
## About
|
||||
|
||||
portzap is a simple bourne shell script that takes care of keeping up to
|
||||
date with the [HardenedBSD](https://hardenedbsd.org) ports collection.
|
||||
|
||||
The
|
||||
[HardenedBSD ports collection](https://git.hardenedbsd.org/hardenedbsd/ports.git)
|
||||
is maintained as a git repository, and portzap allows the repository to be cloned
|
||||
(and updated) using a regular user account. The unpacking of the repository to
|
||||
`/usr/ports` is also supported but must be performed by root.
|
||||
|
||||
## Usage
|
||||
|
||||
* **portzap clone**
|
||||
This command should be run with a regular user account. <br>
|
||||
The command clones HardenedBSD's ports collection to `/tmp/ports`.
|
||||
|
||||
|
||||
* **portzap pull**
|
||||
This command should be run with a regular user account. <br>
|
||||
The command updates an existing repository previously cloned with `portzap clone`.
|
||||
|
||||
* **portzap unpack**
|
||||
This command should be run as root. It copies `/tmp/ports` to `/usr/ports`.
|
||||
|
97
bin/portzap
Executable file
97
bin/portzap
Executable file
|
@ -0,0 +1,97 @@
|
|||
#!/bin/sh
|
||||
|
||||
##
|
||||
# A shell script that takes care of keeping up to date with
|
||||
# the HardenedBSD ports collection.
|
||||
|
||||
source="https://git.hardenedbsd.org/hardenedbsd/ports.git"
|
||||
stage_dir="/tmp/ports/"
|
||||
|
||||
|
||||
##
|
||||
# Utils
|
||||
|
||||
exit_on_missing_deps() {
|
||||
deps="git"
|
||||
for dep in $deps; do
|
||||
which -s $dep
|
||||
if [ $? -ne 0 ]; then
|
||||
echo $dep is missing
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
user_is_root() {
|
||||
user_id=$(id -u $(whoami))
|
||||
return $user_id = "0"
|
||||
}
|
||||
|
||||
user_is_not_root() {
|
||||
user_id=$(id -u $(whoami))
|
||||
result=$(test $user_id -ne "0")
|
||||
return $result
|
||||
}
|
||||
|
||||
##
|
||||
# Commands
|
||||
|
||||
help() {
|
||||
echo portzap "[clone|pull|unpack]"
|
||||
}
|
||||
|
||||
clone() {
|
||||
if user_is_root
|
||||
then
|
||||
echo "The clone command should not be run as root."
|
||||
exit 1
|
||||
fi
|
||||
rm -rf $stage_dir
|
||||
git clone --depth 1 $source $stage_dir
|
||||
}
|
||||
|
||||
pull() {
|
||||
if user_is_root
|
||||
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
|
||||
else
|
||||
echo "Run 'portzap clone' first"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
unpack() {
|
||||
if user_is_not_root
|
||||
then
|
||||
echo "The unpack command should be run as root."
|
||||
exit 1
|
||||
fi
|
||||
cp -Rfv /tmp/ports /usr/
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"clone")
|
||||
exit_on_missing_deps
|
||||
clone
|
||||
break
|
||||
;;
|
||||
"pull")
|
||||
exit_on_missing_deps
|
||||
pull
|
||||
break
|
||||
;;
|
||||
"unpack")
|
||||
unpack
|
||||
break
|
||||
;;
|
||||
*)
|
||||
help
|
||||
break
|
||||
;;
|
||||
esac
|
Loading…
Reference in a new issue