Rewrite libexec/portzap/portzap-install
This commit is contained in:
parent
5dc23097b9
commit
9811cf229c
6 changed files with 32 additions and 106 deletions
26
bin/portzap
26
bin/portzap
|
@ -4,11 +4,11 @@ set -e
|
|||
##
|
||||
# Variables
|
||||
rootdir=$(dirname "$0")
|
||||
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
||||
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"
|
||||
libexec=$(realpath "${rootdir}/../libexec/portzap/")
|
||||
libexec=$(realpath "${rootdir}/../libexec/portzap")
|
||||
|
||||
##
|
||||
# Functions
|
||||
|
@ -22,7 +22,7 @@ require_root() {
|
|||
|
||||
require_membership_of() {
|
||||
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}."
|
||||
exit 1
|
||||
fi
|
||||
|
@ -38,25 +38,29 @@ require_dependency() {
|
|||
done
|
||||
}
|
||||
|
||||
. "$libexec/functions/portzap-install"
|
||||
|
||||
##
|
||||
# main
|
||||
case $1 in
|
||||
"clone")
|
||||
require_dependency git
|
||||
require_membership_of _portzap
|
||||
${libexec}/portzap/portzap-clone "${giturl}" "${gitdir}"
|
||||
${libexec}/portzap-clone "${giturl}" "${gitdir}"
|
||||
;;
|
||||
"pull")
|
||||
require_dependency git
|
||||
require_membership_of _portzap
|
||||
${libexec}/portzap/portzap-pull "${gitdir}"
|
||||
${libexec}/portzap-pull "${gitdir}"
|
||||
;;
|
||||
"install")
|
||||
require_root
|
||||
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
|
||||
|
|
|
@ -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
|
|
@ -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"
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
set -ex
|
||||
giturl=$1
|
||||
gitdir=$2
|
||||
if [ -e "${gitdir}/.git" ]; then
|
||||
|
@ -8,4 +8,4 @@ if [ -e "${gitdir}/.git" ]; then
|
|||
exit 1
|
||||
fi
|
||||
umask u=rwX,g=rwX,o=
|
||||
git clone "${giturl}" "${gitdir}"
|
||||
git clone --depth 1 "${giturl}" "${gitdir}"
|
||||
|
|
|
@ -1,56 +1,16 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
set -ex
|
||||
gitdir=$1
|
||||
installdir=$2
|
||||
revision=$3
|
||||
excludes=".git .gitignore .hooks .arcconfig"
|
||||
|
||||
__portzap_install_update() {
|
||||
portzap_file=$1
|
||||
ports_dir=$2
|
||||
libexec_dir=$3
|
||||
rev=$(cat "$portzap_file")
|
||||
rm_files=$(git diff --name-only --diff-filter=D "$rev"..HEAD)
|
||||
ch_files=$(git diff --name-only --diff-filter=RAM "$rev"..HEAD | \
|
||||
cut -d / -f1 -f2 | uniq)
|
||||
for file in $rm_files; do
|
||||
if [ -e "$ports_dir/$file" ]; then
|
||||
echo RM "$ports_dir/$file"
|
||||
rm "$ports_dir/$file"
|
||||
fi;
|
||||
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"
|
||||
}
|
||||
cd ${gitdir}
|
||||
find -s . -maxdepth 1 \
|
||||
-exec cp -Rfv {} ${installdir} \; \
|
||||
-exec chown -R root:_portzap ${installdir}/{} \; \
|
||||
-exec chmod -R u=rwX,g=rwX,o= ${installdir}/{} \;
|
||||
cd ${installdir}
|
||||
for exclude in ${excludes}; do
|
||||
rm -rf ${exclude}
|
||||
done
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
set -ex
|
||||
gitdir=$1
|
||||
umask=rwX,g=rwX,o=
|
||||
if [ -e "${gitdir}/.git" ]; then
|
||||
|
|
Loading…
Reference in a new issue