Replace libexec/portzap/functions/ with libexec/portzap/ scripts
This commit is contained in:
parent
cc3f43c0fc
commit
7a22d2a9a5
7 changed files with 59 additions and 70 deletions
49
bin/portzap
49
bin/portzap
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
##
|
||||||
# Variables
|
# Variables
|
||||||
rootdir=$(dirname "$0")
|
rootdir=$(dirname "$0")
|
||||||
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
||||||
|
@ -9,30 +10,50 @@ installdir="${PORTZAP_INSTALLDIR:-/usr/ports/}"
|
||||||
revision="${installdir}/.portzap"
|
revision="${installdir}/.portzap"
|
||||||
libexec=$(realpath "${rootdir}/../libexec/portzap/")
|
libexec=$(realpath "${rootdir}/../libexec/portzap/")
|
||||||
|
|
||||||
# Masks
|
##
|
||||||
clone_mask=007
|
|
||||||
pull_mask=007
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
require_root() {
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
echo "This command requires root privileges."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
require_membership_of() {
|
||||||
|
group=$1
|
||||||
|
if ! id -Gn | tr ' ' '\n' | grep -e "^${group}$"; then
|
||||||
|
echo "This command requires a user to be a member of ${group}."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
require_dependency() {
|
||||||
|
deps=$1
|
||||||
|
for dep in $deps; do
|
||||||
|
if ! which -s "$dep"; then
|
||||||
|
echo "This command requires ${dep}, but it was not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
. "$libexec/functions/portzap-install"
|
. "$libexec/functions/portzap-install"
|
||||||
. "$libexec/functions/portzap-pull"
|
|
||||||
. "$libexec/functions/portzap-clone"
|
|
||||||
. "$libexec/functions/requirements"
|
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
"clone")
|
"clone")
|
||||||
require_deps git
|
require_dependency git
|
||||||
require_group _portzap
|
require_membership_of _portzap
|
||||||
portzap_clone "$portzap_dir" "$giturl" "$clone_mask"
|
${libexec}/portzap/portzap-clone "${giturl}" "${gitdir}"
|
||||||
;;
|
;;
|
||||||
"pull")
|
"pull")
|
||||||
require_deps git
|
require_dependency git
|
||||||
require_group _portzap
|
require_membership_of _portzap
|
||||||
portzap_pull "$portzap_dir" "$pull_mask"
|
${libexec}/portzap/portzap-pull "${gitdir}"
|
||||||
;;
|
;;
|
||||||
"install")
|
"install")
|
||||||
require_root
|
require_root
|
||||||
require_deps git
|
require_dependency git
|
||||||
portzap_install "$installdir" "$portzap_dir" "$libexec" "$portzap_file"
|
portzap_install "$installdir" "$portzap_dir" "$libexec" "$portzap_file"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
portzap_clone() {
|
|
||||||
portzap_dir=$1
|
|
||||||
ports_url=$2
|
|
||||||
clone_mask=$3
|
|
||||||
|
|
||||||
if [ -e "$portzap_dir/.git" ]; then
|
|
||||||
echo "$portzap_dir exists."
|
|
||||||
echo "Run 'portzap pull' instead."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
umask "$clone_mask"
|
|
||||||
git clone "$ports_url" "$portzap_dir"
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
portzap_pull() {
|
|
||||||
portzap_dir=$1
|
|
||||||
pull_mask=$2
|
|
||||||
if [ -e "$portzap_dir/.git" ]; then
|
|
||||||
umask "$pull_mask"
|
|
||||||
cd "$portzap_dir" || exit 1
|
|
||||||
git pull --rebase origin hardenedbsd/main
|
|
||||||
else
|
|
||||||
echo "Run 'portzap clone' first."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
require_deps() {
|
|
||||||
deps=$1
|
|
||||||
for dep in $deps; do
|
|
||||||
if ! which -s "$dep"; then
|
|
||||||
echo "$dep" is required, but not found
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
require_group() {
|
|
||||||
group=$1
|
|
||||||
cmd=$(id -Gn | tr ' ' '\n' | grep "^${group}$")
|
|
||||||
if [ "$cmd" != "$group" ]; then
|
|
||||||
echo "You must be a member of the '$group' group to run this command."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
require_root() {
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
|
||||||
echo "The install command must be run as root."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
11
libexec/portzap/portzap-clone
Executable file
11
libexec/portzap/portzap-clone
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
giturl=$1
|
||||||
|
gitdir=$2
|
||||||
|
if [ -e "${gitdir}/.git" ]; then
|
||||||
|
echo "${gitdir} already exists."
|
||||||
|
echo "Try 'portzap pull' instead."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
umask u=rwX,g=rwX,o=
|
||||||
|
git clone "${giturl}" "${gitdir}"
|
1
libexec/portzap/functions/portzap-install → libexec/portzap/portzap-install
Normal file → Executable file
1
libexec/portzap/functions/portzap-install → libexec/portzap/portzap-install
Normal file → Executable file
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
__portzap_install_update() {
|
__portzap_install_update() {
|
||||||
portzap_file=$1
|
portzap_file=$1
|
12
libexec/portzap/portzap-pull
Executable file
12
libexec/portzap/portzap-pull
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
gitdir=$1
|
||||||
|
umask=rwX,g=rwX,o=
|
||||||
|
if [ -e "${gitdir}/.git" ]; then
|
||||||
|
cd "${gitdir}"
|
||||||
|
git pull --rebase origin hardenedbsd/main
|
||||||
|
else
|
||||||
|
echo "A copy of the hardenedbsd ports tree wasn't found."
|
||||||
|
echo "Try 'portzap clone' instead."
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in a new issue