Compare commits

...

9 commits

Author SHA1 Message Date
245fe9957a Fix shellcheck errors
Some checks are pending
sourcezap / shellcheck (push) Waiting to run
2024-08-17 18:56:38 -03:00
fb47f6466b Fix indentation 2024-08-17 18:36:38 -03:00
87f8e18ade Silence grep with -q 2024-08-17 18:18:39 -03:00
c68eebf4a5 Add setup-doas improvements 2024-08-17 18:11:06 -03:00
0b5e414d2c Update sourcezap.8 2024-08-17 16:34:28 -03:00
a5135e085a Fix docs 2024-08-16 23:34:33 -03:00
bbb71c9a84 s|COMMANDS|GENERAL|g 2024-08-16 20:16:21 -03:00
59b3f3ed30 Remove '_sourcezap' group in 'sourcezap teardown' 2024-08-16 20:03:19 -03:00
0x1eef
81b163dd25 Add 'sourcezap [setup|teardown]' (#5)
Co-authored-by: 0x1eef <0x1eef@protonmail.com>
Reviewed-on: http://git.bastion.home.network/0x1eef/sourcezap/pulls/5
2024-08-16 19:45:22 -03:00
8 changed files with 78 additions and 14 deletions

View file

@ -8,15 +8,19 @@ can be installed into `/usr/src/` by root.
## CLI
### CLI: setup-sourcezap
### CLI: setup
`setup-sourcezap` should be run after installing sourcezap for
the first time. <br> There is no harm in running `setup-sourcezap`
`sourcezap setup` should be run after installing sourcezap for
the first time. <br> There is no harm in running `sourcezap setup`
multiple times:
# Add the '_sourcezap' user, group and home directory
# This command requires root privileges
root@localhost# setup-sourcezap
root@localhost# sourcezap setup
# Reverse the changes made by 'sourcezap setup'
# This command requires root privileges
root@localhost# sourcezap teardown
### CLI: group
@ -71,7 +75,7 @@ recent version of sourcezap can be installed via git:
# Install
root@localhost# make install
root@localhost# setup-sourcezap
root@localhost# sourcezap setup
# Add user to '_sourcezap' group
root@localhost# pw groupmod -n _sourcezap -m <user>

View file

@ -42,6 +42,12 @@ while [ "${i}" -le "$#" ]; do
done
case $1 in
"setup")
"${libexec}"/commands/sourcezap-setup
;;
"teardown")
"${libexec}"/commands/sourcezap-teardown
;;
"clone")
require_dependency "git doas"
"${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
@ -68,7 +74,11 @@ case $1 in
*)
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
printf "\n"
printf "Commands:\n"
printf "Setup\n"
printf " setup Setup sourcezap for the first time\n"
printf " teardown Reverse the changes made by 'sourcezap setup'\n"
printf "\n"
printf "General\n"
printf " clone Clone the HardenedBSD source tree\n"
printf " pull Pull source tree updates\n"
printf " checkout Checkout a branch other than the default\n"

View file

@ -3,7 +3,7 @@ set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
##

View file

@ -0,0 +1,25 @@
#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)}
libexec="${localbase}"/libexec/sourcezap
user=_sourcezap
##
# functions
# shellcheck source=/dev/null
. "${libexec}"/functions/print.sh
##
# main
if [ "$(id -u)" = "0" ]; then
pw userdel -n "${user}" || true
pw groupdel -n "${user}" || true
rm -rf /home/"${user:?}"/ || true
printok "done"
else
printerr "you must be root"
exit 1
fi

View file

@ -16,9 +16,11 @@ sharedir="${localbase}"/share/sourcezap
# main
src="${sharedir}"/doas.conf
dest="${localbase}"/etc/doas.conf
if grep -Fq "$(cat "${src}")" "${dest}"; then
printok "doas.conf is up to date"
else
cat "${src}" >> "${dest}"
printok "${dest} updated"
while read -r line < "${src}"; do
if grep -q "${line}" "${dest}"; then
continue
fi
cat "${src}" >> "${dest}"
printok "modified ${dest}"
break
done

View file

@ -5,5 +5,5 @@ set -e
# main
group="_sourcezap"
mygroups=$(id -Gn | tr ' ' '\n')
echo "${mygroups}" | grep -e "^${group}$" > /dev/null 2>&1
echo "${mygroups}" | grep -qe "^${group}$"
exit "${?}"

View file

@ -6,6 +6,8 @@
.Nd manages a copy of the HardenedBSD source tree
.Sh SYNOPSIS
.br
.Nm sourcezap setup
.Nm sourcezap teardown
.Nm sourcezap clone
.Nm sourcezap pull
.Nm sourcezap checkout
@ -17,7 +19,22 @@ manages a copy of the HardenedBSD source tree.
The copy of the source tree is maintained by members of
the '_sourcezap' group, and a copy of the source tree
can be installed into /usr/src/ by root.
.Sh EXAMPLES
.Sh SETUP
.sp
.sp
.Nm sourcezap setup
.br
Setup sourcezap for the first time
.br
This command requires root privileges
.Pp
.Nm sourcezap teardown
.br
Reverse the changes made by 'sourcezap setup'
.br
This command requires root privileges
.Pp
.Sh GENERAL
.sp
.sp
.Nm sourcezap clone

View file

@ -1,5 +1,11 @@
* vNEXT
** Add 'setup/setup-doas' improvements
More likely to do what's expected, but blind spots still exist
** Add 'sourcezap setup', 'sourcezap teardown'
Replaces and enhances 'setup-sourcezap'
** Add libexec/sourcezap/commands/sourcezap-sh
Runs /bin/sh within /home/_sourcezap/src/ as the '_sourcezap' user