Rewrite libexec/portzap/portzap-install

This commit is contained in:
0x1eef 2024-04-01 23:41:53 -03:00
parent 5dc23097b9
commit 9811cf229c
6 changed files with 32 additions and 106 deletions

View file

@ -4,11 +4,11 @@ set -e
## ##
# Variables # Variables
rootdir=$(dirname "$0") rootdir=$(dirname "$0")
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
gitdir="/home/_portzap/ports" gitdir="/home/_portzap/ports"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports/}" giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
revision="${installdir}/.portzap" revision="${installdir}/.portzap"
libexec=$(realpath "${rootdir}/../libexec/portzap/") libexec=$(realpath "${rootdir}/../libexec/portzap")
## ##
# Functions # Functions
@ -22,7 +22,7 @@ require_root() {
require_membership_of() { require_membership_of() {
group=$1 group=$1
if ! id -Gn | tr ' ' '\n' | grep -e "^${group}$"; then if ! id -Gn | tr ' ' '\n' | grep -e "^${group}$" > /dev/null 2>&1; then
echo "This command requires a user to be a member of ${group}." echo "This command requires a user to be a member of ${group}."
exit 1 exit 1
fi fi
@ -38,25 +38,29 @@ require_dependency() {
done done
} }
. "$libexec/functions/portzap-install" ##
# main
case $1 in case $1 in
"clone") "clone")
require_dependency git require_dependency git
require_membership_of _portzap require_membership_of _portzap
${libexec}/portzap/portzap-clone "${giturl}" "${gitdir}" ${libexec}/portzap-clone "${giturl}" "${gitdir}"
;; ;;
"pull") "pull")
require_dependency git require_dependency git
require_membership_of _portzap require_membership_of _portzap
${libexec}/portzap/portzap-pull "${gitdir}" ${libexec}/portzap-pull "${gitdir}"
;; ;;
"install") "install")
require_root require_root
require_dependency git require_dependency git
portzap_install "$installdir" "$portzap_dir" "$libexec" "$portzap_file" ${libexec}/portzap-install "${gitdir}" "${installdir}" "${revision}"
;;
"adduser")
require_root
${libexec}/portzap-adduser
;; ;;
*) *)
echo "Usage: portzap clone|pull|install" echo "Usage: portzap COMMAND [OPTIONS]"
;; ;;
esac esac

View file

@ -1,26 +0,0 @@
#!/bin/sh
set -e
ports_dir=$1
libexec_dir=$2
group=_portzap
mode=u=rwx,g=rwx,o=
for i in $(seq 3 $#); do
relative_portzap_dir=$(eval echo -n "\${$i}")
realpath=$(realpath "$ports_dir/$relative_portzap_dir")
# Install directory
install -d -g $group -m $mode \
"$relative_portzap_dir" \
"$ports_dir/$relative_portzap_dir"
echo "$realpath"
# Install files
find "$relative_portzap_dir" -maxdepth 1 -type f \
\( -not -name ".gitignore" \) \
\( -not -name ".arcconfig" \) \
-exec "$libexec_dir/install-file" "$ports_dir/$relative_portzap_dir" {} +
# Install subdirs (recursive)
find -s "$relative_portzap_dir" -depth 1 -type d \
-exec "$libexec_dir/install-directory" "$ports_dir" "$libexec_dir" {} \;
done

View file

@ -1,12 +0,0 @@
#!/bin/sh
set -e
dest=$1
group=_portzap
mode=u=rw,g=rw,o=
files=""
for i in $(seq 2 $#); do
file=$(eval echo -n "\$$i")
files="$files $file"
done
install -g $group -m $mode "$files" "$dest"

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
set -e set -ex
giturl=$1 giturl=$1
gitdir=$2 gitdir=$2
if [ -e "${gitdir}/.git" ]; then if [ -e "${gitdir}/.git" ]; then
@ -8,4 +8,4 @@ if [ -e "${gitdir}/.git" ]; then
exit 1 exit 1
fi fi
umask u=rwX,g=rwX,o= umask u=rwX,g=rwX,o=
git clone "${giturl}" "${gitdir}" git clone --depth 1 "${giturl}" "${gitdir}"

View file

@ -1,56 +1,16 @@
#!/bin/sh #!/bin/sh
set -e set -ex
gitdir=$1
installdir=$2
revision=$3
excludes=".git .gitignore .hooks .arcconfig"
__portzap_install_update() { cd ${gitdir}
portzap_file=$1 find -s . -maxdepth 1 \
ports_dir=$2 -exec cp -Rfv {} ${installdir} \; \
libexec_dir=$3 -exec chown -R root:_portzap ${installdir}/{} \; \
rev=$(cat "$portzap_file") -exec chmod -R u=rwX,g=rwX,o= ${installdir}/{} \;
rm_files=$(git diff --name-only --diff-filter=D "$rev"..HEAD) cd ${installdir}
ch_files=$(git diff --name-only --diff-filter=RAM "$rev"..HEAD | \ for exclude in ${excludes}; do
cut -d / -f1 -f2 | uniq) rm -rf ${exclude}
for file in $rm_files; do
if [ -e "$ports_dir/$file" ]; then
echo RM "$ports_dir/$file"
rm "$ports_dir/$file"
fi;
done done
for file in $ch_files; do
if [ -f "$file" ]; then
echo "$file"
"$libexec_dir/install-file" "$ports_dir" "$file"
else
dir=$file
"$libexec_dir/install-directory" "$ports_dir" "$libexec_dir" "$dir"
fi
done
}
__portzap_install_ports() {
ports_dir=$1
libexec_dir=$2
find -s . -maxdepth 1 -type f \
\( -not -name ".gitignore" \) \
\( -not -name ".arcconfig" \) \
-exec "$libexec_dir/install-file" "$ports_dir" {} +
find -s . -maxdepth 1 -type d \
\( -not -name "." \) \
\( -not -name ".git" \) \
\( -not -name ".hooks" \) \
-exec "$libexec_dir/install-directory" "$ports_dir" "$libexec_dir" {} +
}
portzap_install() {
ports_dir=$1
portzap_dir=$2
libexec_dir=$3
portzap_file=$4
cd "$portzap_dir" || exit 1
if [ -e "$portzap_file" ]; then
__portzap_install_update "$portzap_file" "$ports_dir" "$libexec_dir"
else
__portzap_install_ports "$portzap_dir" "$libexec_dir"
fi
git rev-parse HEAD > "$portzap_file"
}

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
set -e set -ex
gitdir=$1 gitdir=$1
umask=rwX,g=rwX,o= umask=rwX,g=rwX,o=
if [ -e "${gitdir}/.git" ]; then if [ -e "${gitdir}/.git" ]; then