From 703341db49f7ee999798e3211a27195d9d561dfd Mon Sep 17 00:00:00 2001 From: mollusk Date: Tue, 20 Oct 2020 22:23:35 -0400 Subject: [PATCH] Add basic funcionality --- repo.sh | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 repo.sh diff --git a/repo.sh b/repo.sh new file mode 100755 index 0000000..7680d28 --- /dev/null +++ b/repo.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +CONFIG_DIR="${HOME}/.config/vur" +CONFIG_FILE="vur.conf" +KEY_FILE="privkey.pem" +KEY_PATH="${CONFIG_DIR}/${KEY_FILE}" + +help_file(){ + echo """ + + usage: ${0} [-a] + + -a add packages to repository and sign them + """ +} + + + +gen_conf(){ + + if [ ! -d "${CONFIG_DIR}" ];then + mkdir -p "${CONFIG_DIR}" || exit 1 + fi + + if [ ! -f "${CONFIG_DIR}/${CONFIG_FILE}" ];then + echo "No config file exists yet" + echo -e "Please answer a few questions to set up the config\n\n" + + echo -n "Where do you want your custom repository? (mind permissions): " + read repo_location + + echo "REPO_PATH=${repo_location}" > "${CONFIG_DIR}/${CONFIG_FILE}" + + echo -n "Where is your 'void-packages' location (no trailing /):" + read void_packages_location + + echo "void_packages=${void_packages_location}/hostdir/binpkgs" >> "${CONFIG_DIR}/${CONFIG_FILE}" + + echo "Provid enter the full path of your custom repository: " + source "${CONFIG_DIR}/${CONFIG_FILE}" + fi +} + +load_conf(){ + + if [ -f "${HOME}"/.config/vrepo.conf ];then + source "${CONFIG_DIR}"/"${CONFIG_FILE}" + else + gen_conf + source "${CONFIG_DIR}"/"${CONFIG_FILE}" + fi +} + +check_deps(){ + if [ ! -f "/usr/bin/xbps-install" ];then + echo "A Void Linux based system is required!" + echo "Unable to locate xbps-install" + return 1 + exit 1 + fi +} + +create_repo(){ + + if [ ! -d "${REPO_PATH}" ];then + + mkdir "${REPO_PATH}" + #cd "${BASE_DIR}"/"${REPO_PATH}" || return + + + if [ -d "${REPO_PATH}" ];then + + return 0 + fi + + elif [ -d "${REPO_PATH}" ];then + echo "Using custom repository: ${REPO_PATH}" + return 0 + fi +} + +gen_key(){ + ssh-keygen -t rsa -b 4096 -m PEM -f "${KEY_PATH}" +} + +sign_pkgs(){ + + if [ ! -f "${KEY_PATH}" ];then + echo "Key file does not exist" + echo "Generating a new key..." + gen_key + + echo "Signing xbps files in ${REPO_PATH}" + xbps-rindex --sign --signedby "mollusk" --privkey "${KEY_PATH}" "$REPO_PATH" + else + echo "Signing xbps files in ${REPO_PATH}" + xbps-rindex --sign --signedby "mollusk" --privkey "${KEY_PATH}" "$REPO_PATH" + fi +} + +add_pkg(){ + load_conf + create_repo + cp -r "${void_packages}"/*.xbps "${REPO_PATH}" || exit 1 + xbps-rindex -a "${REPO_PATH}"/*.xbps +} + +case "${1}" in + + -c | --create) + load_conf + create_repo + ;; + + -gk | --gen-key) + load_conf + gen_key + ;; + + -sp | --sign-pkgs) + load_conf + sign_pkgs + ;; + + -a | --add-pkg) + load_conf + add_pkg + sign_pkgs + ;; + + *) + help_file + ;; +esac \ No newline at end of file