2020-11-30 00:13:25 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
AL_TEMP_LOCATION="/tmp"
|
|
|
|
AL_INSTALL_ROOT="/tmp/alroot"
|
|
|
|
AL_INSTALLED_PKG_DATABASE="${AL_INSTALL_ROOT}/var/aps/installed"
|
|
|
|
AL_LOCAL_PKG_DATABASE="${AL_INSTALL_ROOT}/var/aps/repos"
|
2020-11-30 01:15:13 +02:00
|
|
|
AL_LOCK="${AL_INSTALL_ROOT}/var/aps/lock"
|
2020-11-30 00:13:25 +02:00
|
|
|
|
|
|
|
# Repo config
|
|
|
|
official="https://git.hippoz.xyz/alnux/repo"
|
|
|
|
|
|
|
|
set_default_package_config_values() {
|
|
|
|
AL_PKG_CONFIG_DEPLOY=true
|
|
|
|
AL_PKG_CONFIG_VER="0.1"
|
|
|
|
AL_PKG_CONFIG_NAME="alnuxpackage"
|
|
|
|
AL_PKG_CONFIG_MAKEDEPENDS=""
|
|
|
|
AL_PKG_CONFIG_DEPENDS=""
|
|
|
|
}
|
|
|
|
|
|
|
|
unset_config_values() {
|
|
|
|
unset AL_PKG_CONFIG_DEPLOY
|
|
|
|
unset AL_PKG_CONFIG_VER
|
|
|
|
unset AL_PKG_CONFIG_NAME
|
|
|
|
unset AL_PKG_CONFIG_MAKEDEPENDS
|
|
|
|
unset AL_PKG_CONFIG_DEPENDS
|
|
|
|
}
|
|
|
|
|
|
|
|
load_installed_pkg_config() {
|
|
|
|
echo ":: Looking up package ${1} in local installed packages..."
|
|
|
|
set_default_package_config_values
|
|
|
|
if [ -d "${AL_INSTALLED_PKG_DATABASE}/${1}" ]; then
|
|
|
|
echo ":: Package ${1} was found, loading config..."
|
|
|
|
AL_PKG_NAME=${1}
|
|
|
|
AL_PKG_PACKAGE_PATH="${AL_INSTALLED_PKG_DATABASE}/${1}"
|
|
|
|
run_package_script "package"
|
|
|
|
else
|
|
|
|
echo "[E] Package ${1} was not found in the local installed package database, exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_package() {
|
|
|
|
echo "[*] Copying package ${1} into temporary location ${AL_TEMP_LOCATION}..."
|
|
|
|
#tar -xf "${1}" -C "${AL_TEMP_LOCATION}"
|
|
|
|
cp -prv "${1}" "${AL_TEMP_LOCATION}"
|
|
|
|
AL_PKG_NAME="${1%/}"
|
|
|
|
AL_PKG_NAME="${AL_PKG_NAME##*/}"
|
|
|
|
AL_PKG_NAME=$(echo "${AL_PKG_NAME}" | cut -f 1 -d '.')
|
|
|
|
cd "${AL_INSTALL_ROOT}"
|
|
|
|
|
|
|
|
AL_PKG_PACKAGE_PATH="${AL_TEMP_LOCATION}/${AL_PKG_NAME}"
|
|
|
|
|
|
|
|
set_default_package_config_values
|
|
|
|
}
|
|
|
|
|
|
|
|
add_package_to_database() {
|
|
|
|
if [ ! -d "${AL_INSTALLED_PKG_DATABASE}" ]; then
|
|
|
|
echo "[*] Package database folder not found, creating..."
|
|
|
|
mkdir -pv "${AL_INSTALLED_PKG_DATABASE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x "${AL_PKG_PACKAGE_PATH}/package" ]; then
|
|
|
|
echo ":: Adding target ${AL_PKG_NAME} to installed package database..."
|
|
|
|
if [ ! -d "${AL_INSTALLED_PKG_DATABASE}/${AL_PKG_NAME}" ]; then
|
|
|
|
echo "[*] Package folder for ${AL_PKG_NAME} not found, creating..."
|
|
|
|
mkdir "${AL_INSTALLED_PKG_DATABASE}/${AL_PKG_NAME}"
|
|
|
|
fi
|
|
|
|
cp -pv "${AL_PKG_PACKAGE_PATH}/package" "${AL_INSTALLED_PKG_DATABASE}/${AL_PKG_NAME}/package"
|
|
|
|
if [ -e "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloadfiles" ]; then
|
|
|
|
cp -pv "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloadfiles" "${AL_INSTALLED_PKG_DATABASE}/${AL_PKG_NAME}/payloadfiles"
|
|
|
|
fi
|
|
|
|
else
|
2021-01-16 16:49:12 +02:00
|
|
|
echo "[E] Target ${AL_PKG_NAME} does not have a package script and will not be added to the installed package database"
|
2020-11-30 00:13:25 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
run_package_script() {
|
|
|
|
if [ -x "${AL_PKG_PACKAGE_PATH}/${1}" ]; then
|
|
|
|
echo ":: Running ${1} script for target ${AL_PKG_NAME}..."
|
2021-01-16 16:49:12 +02:00
|
|
|
. "${AL_PKG_PACKAGE_PATH}/${1}" ${AL_INSTALL_ROOT}
|
2020-11-30 00:13:25 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
deploy_package_payload() {
|
|
|
|
if [ "${AL_PKG_CONFIG_DEPLOY}" = true ]; then
|
|
|
|
echo ":: Deploying target ${AL_PKG_NAME}..."
|
|
|
|
cp -rpv "${AL_PKG_PACKAGE_PATH}/payload"/* "${AL_INSTALL_ROOT}" > "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloaddeploylog"
|
|
|
|
sed 's/^.*-> //' "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloaddeploylog" | tr -d \'\" > "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloadfiles"
|
|
|
|
rm "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloaddeploylog"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_extracted_package() {
|
|
|
|
run_package_script "package"
|
|
|
|
run_package_script "build"
|
|
|
|
run_package_script "predeploy"
|
|
|
|
deploy_package_payload
|
|
|
|
run_package_script "postdeploy"
|
|
|
|
|
|
|
|
echo "[*] Install complete for target ${AL_PKG_NAME}"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_cleanup() {
|
|
|
|
echo "[*] Cleaning up after target ${AL_PKG_NAME}..."
|
2020-12-01 18:40:14 +02:00
|
|
|
rm -r "${AL_PKG_PACKAGE_PATH}"
|
|
|
|
rm "${AL_TEMP_LOCATION}/${AL_PKG_NAME}-payloadfiles"
|
2020-11-30 00:13:25 +02:00
|
|
|
|
|
|
|
unset AL_PKG_PACKAGE_PATH
|
|
|
|
unset AL_PKG_NAME
|
|
|
|
|
|
|
|
unset_config_values
|
|
|
|
|
|
|
|
cd "${AL_INSTALL_ROOT}"
|
|
|
|
}
|
|
|
|
|
|
|
|
install_local_package() {
|
|
|
|
if [ ! -e "${1}" ]; then
|
|
|
|
echo "[E] File ${1} does not exist, exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
extract_package "${1}"
|
|
|
|
install_extracted_package
|
|
|
|
add_package_to_database
|
|
|
|
extract_cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_local_package() {
|
|
|
|
load_installed_pkg_config "${1}"
|
|
|
|
PAYLOADFILES_PATH="${AL_PKG_PACKAGE_PATH}/payloadfiles"
|
|
|
|
|
|
|
|
if [ ! -e "${PAYLOADFILES_PATH}" ]; then
|
|
|
|
echo "[E] Package ${1} does not have a payloadfiles file. Exiting..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ":: Removing target ${1}..."
|
|
|
|
|
|
|
|
rm -rv $(<${PAYLOADFILES_PATH})
|
|
|
|
rm -rv ${AL_PKG_PACKAGE_PATH}
|
|
|
|
|
|
|
|
echo "[*] Removal complete for target ${AL_PKG_NAME}"
|
|
|
|
}
|
|
|
|
|
|
|
|
sync_local_repo_database() {
|
|
|
|
echo ":: Syncing local database for repo ${1}..."
|
|
|
|
if [ ! -d "${AL_LOCAL_PKG_DATABASE}/${1}" ]; then
|
|
|
|
echo ":: Local database for repo ${1} does not exist, cloning..."
|
|
|
|
git clone "${2}" "${AL_LOCAL_PKG_DATABASE}/${1}"
|
|
|
|
else
|
|
|
|
echo ":: Local database for repo ${1} exists, updating..."
|
|
|
|
cd "${AL_LOCAL_PKG_DATABASE}/${1}"
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_package_from_repo() { # NOTE(hippoz): This can get a tad confusing... ${1} is the repo and ${2} is the package
|
|
|
|
echo ":: Installing package ${2} from ${1} repo"
|
|
|
|
if [ ! -d "${AL_LOCAL_PKG_DATABASE}/${1}/${2}" ]; then
|
|
|
|
echo "[E] Package ${2} was not found in ${1}, exiting..."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
install_local_package "${AL_LOCAL_PKG_DATABASE}/${1}/${2}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
upgrade() {
|
|
|
|
echo ":: Upgrading installed packages..."
|
|
|
|
unset_config_values
|
|
|
|
cd "${AL_INSTALLED_PKG_DATABASE}"
|
|
|
|
for pkg in */; do
|
|
|
|
INSTALLED_PKG_PATH="${AL_INSTALLED_PKG_DATABASE}/${pkg}"
|
|
|
|
. ${INSTALLED_PKG_PATH}/package
|
|
|
|
AL_PKG_NAME="${INSTALLED_PKG_PATH%/}"
|
|
|
|
AL_PKG_NAME="${AL_PKG_NAME##*/}"
|
|
|
|
|
|
|
|
ALREADY_INSTALLED_VERSION=${AL_PKG_CONFIG_VER}
|
|
|
|
|
|
|
|
if [ ! -d "${AL_LOCAL_PKG_DATABASE}/${1}/${AL_PKG_NAME}" ]; then
|
|
|
|
echo "[E] Package ${AL_PKG_NAME} was not found in ${1}, exiting..."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
. "${AL_LOCAL_PKG_DATABASE}/${1}/${AL_PKG_NAME}/package"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "${ALREADY_INSTALLED_VERSION}" = "${AL_PKG_CONFIG_VER}" ]; then
|
|
|
|
echo ":: Package ${AL_PKG_NAME} is out of date, updating..."
|
|
|
|
install_package_from_repo "${1}" "${AL_PKG_NAME}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset_config_values
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2020-11-30 01:15:13 +02:00
|
|
|
if [ -f "${AL_LOCK}" ]; then
|
|
|
|
echo "[E] A lock file already exists."
|
|
|
|
echo " If you're sure no package manager is running,"
|
|
|
|
echo " remove the file ${AL_LOCK}"
|
2020-12-01 18:36:35 +02:00
|
|
|
exit 1
|
2020-11-30 01:15:13 +02:00
|
|
|
fi
|
|
|
|
touch "${AL_LOCK}"
|
|
|
|
|
2020-11-30 00:13:25 +02:00
|
|
|
case ${1} in
|
|
|
|
install)
|
|
|
|
install_local_package "${2}"
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
remove_local_package "${2}"
|
|
|
|
;;
|
|
|
|
sync)
|
|
|
|
sync_local_repo_database "official" ${official}
|
|
|
|
if [ -z "${2}" ]; then
|
|
|
|
echo "[*] No targets specified."
|
|
|
|
else
|
|
|
|
install_package_from_repo "official" "${2}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
upgrade)
|
|
|
|
upgrade "official"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "[E] Invalid option ${1}, exiting..."
|
2020-11-30 01:15:13 +02:00
|
|
|
rm "${AL_LOCK}"
|
2020-11-30 00:13:25 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
2020-11-30 01:15:13 +02:00
|
|
|
|
|
|
|
rm "${AL_LOCK}"
|
2020-11-30 00:13:25 +02:00
|
|
|
}
|
|
|
|
|
2020-11-30 01:15:13 +02:00
|
|
|
main "${1}" "${2}"
|