2021-03-14 14:07:11 -04:00

190 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
CONFIG_DIR="/voidpkg/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
"""
}
get_void_pkgs(){
echo -n "Location to place void-packages?: "
read vpkgs_location
if [ -z "${vpkgs_location}" ];then
vpkgs_location="/voidpkg/void-packages"
echo "Creating directory: ${vpkgs_location}"
mkdir -p "${vpkgs_location}"
git clone https://github.com/void-linux/void-packages.git "${vpkgs_location}"
elif [ -n "${vpkgs_location}" ];then
while true;do
echo -n "Use ssh? [y/N]: "
read use_ssh
if [ -z "${use_ssh}" ] || [ "${use_ssh}" = "n" ] || [ "${use_ssh}" = "N" ] ;then
echo "Creating directory: ${vpkgs_location}"
git clone https://github.com/void-linux/void-packages.git "${vpkgs_location}" || exit 1
break
elif [ "${use_ssh}" = "y" ] || [ "${use_ssh}" = "Y" ];then
echo -n "Remote git username? (i.e github username): "
read git_user
git clone git@github.com:"${git_user}"/void-packages.git "${vpkgs_location}" || exit 1
break
else
echo "please enter y, n, or leave blank"
fi
done
fi
}
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}"
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 repodata in ${REPO_PATH}"
xbps-rindex --sign --signedby "${USER}" --privkey "${KEY_PATH}" "${REPO_PATH}"
echo "Signing xbps files in ${REPO_PATH}"
xbps-rindex -S --signedby "${USER}" --privkey "${KEY_PATH}" "${REPO_PATH}"/*.xbps
else
echo "Signing xbps files in ${REPO_PATH}"
xbps-rindex --sign --signedby "${USER}" --privkey "${KEY_PATH}" "${REPO_PATH}"
echo "Signing xbps files in ${REPO_PATH}"
xbps-rindex -S --signedby "${USER}" --privkey "${KEY_PATH}" "${REPO_PATH}"/*.xbps
fi
}
add_pkg(){
load_conf
create_repo
cp -r "${void_packages}"/*.xbps "${REPO_PATH}" || exit 1
cp -r "${void_packages}"/nonfree/*.xbps "${REPO_PATH}" || exit 1
xbps-rindex -a "${REPO_PATH}"/*.xbps
}
remove_obsoletes(){
xbps-rindex -r "${REPO_PATH}"
xbps-rindex -c "${REPO_PATH}"
}
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
remove_obsoletes
;;
-vp | --void-packages)
get_void_pkgs
;;
-r | --remove-obsoletes)
load_conf
remove_obsoletes
;;
*)
help_file
;;
esac