Get basic cloning working

This commit is contained in:
speedie 2023-07-09 02:36:56 +02:00
parent 9c703e4039
commit 00d4d5eea7
4 changed files with 74 additions and 15 deletions

View file

@ -33,11 +33,6 @@ load_x() {
. "$v" && return 0
}
load_f() {
[ ! -f "$1" ] && return 1
. "$v" && return 0
}
die() {
printf "%s: %s\n" "packr" "$*" > /dev/stderr
exit 1
@ -45,6 +40,7 @@ die() {
main() {
load_x "packr_handler" || die "Failed to load handler"
packr_read_args "$@"
packr_check_action
}

View file

@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
packr_check_exist() { [ -z "$1" ] || [ ! -f "$1" ] && return 1; }
packr_check_exist() { [ ! -f "$1" ] && return 1; }
packr_create_dir() {
[ -z "$1" ] && die "packr_create_dir() failed: No directory was specified"
@ -31,14 +31,39 @@ cat << EOF > "$PACKR_CONFIG_FILE" || die "packr_create_conf(): Failed to create
# packr.conf
# This is the default configuration file for packr.
# See packr(1) and packr.conf(1) for more information.
PACKR_ALLOW_LICENSES="FREE" # Packages under this group will be allowed (FREE/OPENSOURCE/NONFREE/ANY)
# Package options
PACKR_BIN_PRIORITY="true" # Install primarily from binaries if possible (true/false)
PACKR_BIN_ENABLE="true" # Enable installation using binaries (true/false)
PACKR_SRC_ENABLE="true" # Enable installation from source (true/false)
PACKR_REQUIRE_SIGNING="true" # Require packages to be signed using a PGP key (true/false)
PACKR_GIT_CLONE_DEPTH="1" # Clone depth. 1 means no commit history. 0 means full commit history. Most users do not need commit history anyway.
# Directories
PACKR_CACHE_DIR="/var/cache/packr"
PACKR_REPO_DIR="/etc/packr/repos"
# Add repositories that should be used
add_repository "packr-main" "https://git.speedie.site/speedie/packr-main/raw/branch/master/.PACKR_REPO"
EOF
}
packr_conf_init() {
load_x "packr_repohandler" || die "Failed to load repository handler"
packr_check_exist "$PACKR_CONFIG_FILE" || packr_create_conf "$PACKR_CONFIG_FILE"
load_f "$PACKR_CONFIG_FILE" || die "packr_conf_init(): Failed to load configuration file $PACKR_CONFIG_FILE"
. "$PACKR_CONFIG_FILE"
}
packr_check_vars() {
:
[ -z "$PACKR_ALLOW_LICENSES" ] && die "packr_check_vars(): \$PACKR_ALLOW_LICENSES is not set. Incomplete config file."
[ -z "$PACKR_BIN_PRIORITY" ] && die "packr_check_vars(): \$PACKR_BIN_PRIORITY is not set. Incomplete config file."
[ -z "$PACKR_BIN_ENABLE" ] && die "packr_check_vars(): \$PACKR_BIN_ENABLE is not set. Incomplete config file."
[ -z "$PACKR_SRC_ENABLE" ] && die "packr_check_vars(): \$PACKR_SRC_ENABLE is not set. Incomplete config file."
[ -z "$PACKR_REQUIRE_SIGNING" ] && die "packr_check_vars(): \$PACKR_REQUIRE_SIGNING is not set. Incomplete config file."
[ -z "$PACKR_GIT_CLONE_DEPTH" ] && die "packr_check_vars(): \$PACKR_GIT_CLONE_DEPTH is not set. Incomplete config file."
[ -z "$PACKR_CACHE_DIR" ] && die "packr_check_vars(): \$PACKR_CACHE_DIR is not set. Incomplete config file."
[ -z "$PACKR_REPO_DIR" ] && die "packr_check_vars(): \$PACKR_REPO_DIR is not set. Incomplete config file."
return 0
}

View file

@ -81,15 +81,12 @@ EOF
exit "$exitcode"
}
packr_load_core() {
load_x "packr_cfhandler" || die "Failed to load config handler"
packr_conf_init || die "Failed to create configuration file"
packr_check_vars || die "Configuration file is not proper."
}
packr_setup_install() {
packr_load_core
load_x "packr_cfhandler" || die "Failed to load config handler"
load_x "packr_inst" || die "Failed to load packr_inst"
packr_conf_init
packr_check_vars
}
packr_check_action() {

41
src/packr_repohandler Executable file
View file

@ -0,0 +1,41 @@
#!/bin/sh
# packr-repohandler
#
# Copyright (C) 2023 speedie
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
packr_create_repository_dir() { mkdir -p "$1" || die "packr_create_repository_dir(): Failed to create repository directory $1"; }
packr_clone_repository() {
[ "$PACKR_GIT_CLONE_DEPTH" = "1" ] && git_arg_depth="--depth 1"
git clone -q $git_arg_depth "${2}" "${PACKR_REPO_DIR}/${1}" || die "packr_clone_repository(): Failed to clone repository ${2} to ${PACKR_REPO_DIR}/${1}"
}
packr_get_repository() {
[ ! -d "$PACKR_REPO_DIR" ] && packr_create_repository_dir "$PACKR_REPO_DIR"
curl -so "/tmp/packr-temp-repo-file" "$2" || die "packr_get_repository(): Failed to get repository file $2 for repository $1"
[ ! -f "/tmp/packr-temp-repo-file" ] && die "packr_get_repository(): Could not find repository file"
. "/tmp/packr-temp-repo-file" || die "packr_get_repository(): Failed to load repository file"
[ -z "$PACKR_REPO_NAME" ] && die "packr_get_repository(): Repository $1 does not specify PACKR_REPO_NAME."
[ -z "$PACKR_REPO_CLONE" ] && die "packr_get_repository(): Repository $1 does not specify PACKR_REPO_CLONE."
packr_clone_repository "$1" "$PACKR_REPO_CLONE"
mv /tmp/packr-temp-repo-file "${PACKR_REPO_DIR}/${1}/.PACKR_REPO" || die "packr_get_repository(): Failed to move .PACKR_REPO file"
}
add_repository() {
[ ! -d "${PACKR_REPO_DIR}/${1}" ] && packr_get_repository "$@"
}