aps/aps
2021-10-01 15:58:46 +02:00

188 lines
No EOL
6.5 KiB
Bash
Executable file

#!/bin/sh
###################
# aps. rewritten. #
###################
# OHIO: aps *needs* to be rewritten, i can't add any thing else in the aps.old.sh
temp_location="/var/tmp"
install_root="/var/tmp/alroot"
installed_pkg_database="${install_root}/var/aps/installed"
#locpkg_database="${install_root}/var/aps/repos"
lock="${install_root}/var/aps/lock"
#official="https://git.hippoz.xyz/alnux/repo"
debug=off
function prn(){
echo -e "\e[34m==>\e[39m $1"
}
function wrn(){
echo -e "\e[34m==>\e[33m WARNING:\e[39m $1"
}
#function run(){
# printf '%s\n' "$*"
# "$@"
#}
function err(){
echo -e "\e[34m==>\e[31m ERROR:\e[39m $1" &&
rm ${lock} 2> /dev/null &&
exit 2
}
function notf(){
echo -e "\e[34m==>\e[36m NOTIFICATION:\e[39m $1"
}
function confirm(){
prn "To install, press ENTER, to cancel, press CTRL+C (unix process break key)"
}
function dbg(){
wrn "This is a debug build, that may not work!"
}
function sources(){
if [ -f sources ]; then
pkg_config_url=$(cat sources)
pkg_config_archv=$(echo ${pkg_config_url} | sed 's:.*/::')
curl -fLO ${pkg_config_url}
mkdir --parents pkgex
pkg_config_archv_ft=$(file --extension ${pkg_config_archv_ft})
case $pkg_config_archv_ft in
*.tar*) prn $(tar -xf ${pkg_config_archv} -C pkgex) ;;
*.xz) prn $(cd pkgex && xz -d ../${pkg_config_archv} && cd ..) ;;
*.bz2) prn $(cd pkgex && bzip2 -d ../${pkg_config_archv} && cd ..) ;;
*.gz) prn $(cd pkgex && gzip -d ../${pkg_config_archv} && cd ..) ;;
*.zst) prn $(cd pkgex && zstd -dc && cd ..) ;;
*) wrn "Not a tar! But it will be kept!"
esac
mkdir --parents pkgsrc
cp -r pkgex/*/* pkgsrc
else
err "Sources not found, exiting!"
fi
}
function runbuildsh(){
if [ -x "${2}/${1}" ]; then
prn "Running $1"
cd "${2}" || err "Running $1 has failed, check your permissions."
"${2}/${1}" "${2}/payload" "${2}"
fi
}
function pkg_find(){
# i could not even bother, i had to copy kiss in some sense
set -- "$1" "$2" "$3" "${4:-"$AL_REPO"}"
IFS=:
for _find_path in $4 "${3:-$sys_db}"; do set +f
for _find_pkg in "$_find_path/"$1; do
test "${3:--d}" "$_find_pkg" && set -f -- "$@" "$_find_pkg"
done
done
unset IFS
# alnux search i guess
#case $2-$# in
# *-4) return 1 ;;
# -*) repo_dir=$5; repo_name=${5##*/} ;;
# *) shift 4; printf '%s\n' "$@"
#esac
}
function pkg_local(){
if [ -z "$AL_REPO" ]; then
#wrn "Alnux Repo variable is not set, setting to /var/db/repo/core!"
#prn "To set the Alnux Repo var, either:"
#prn " edit /etc/profile or your shell's profile to include your repo and sub-repos, "
#prn " much like this: export AL_REPO=/var/db/repo/core:/var/db/repo/extra OR"
#prn " export Alnux Repo var like this: export AL_REPO=/var/db/repo/core:/var/db/repo/extra"
#export AL_REPO="/var/aps/repos/official/core"
#notf "AL_REPO set to /var/db/repo/core"
#prn "Verifying if AL_REPO is set..."
#if [ -z $AL_REPO ]; then
# err "AL_REPO is not set."
#else
# prn "$(echo $AL_REPO)... yes."
#fi
err "Alnux Repo variable is not set. Will not continue"
fi
pkg_find $1
cp -prv "${1}" "${temp_location}"
# - - - - - #
# VARIABLES #
# - - - - - #
pkg_name="${1%/}"
pkg_name="${pkg_name##*/}"
pkg_name=$(echo "${pkg_name}" | cut -f 1 -d '.')
pkg_path="${temp_location}/${pkg_name}"
# - - #
# #
# - - #
mkdir -p "${pkg_path}/payload"
. "${pkg_path}/package"
cd "${pkg_path}"
sources
runbuildsh "build" "${pkg_path}"
runbuildsh "predeploy" "${pkg_path}"
# Old APS code from before the rewrite!
# Deploy package
if [ "${pkg_config_deploy}" = true ]; then
echo ":: Deploying target ${pkg_name}..."
cp -rpv "${pkg_path}/payload"/* "${install_root}" > "${temp_location}/${pkg_name}-payloaddeploylog"
sed 's/^.*-> //' "${temp_location}/${pkg_name}-payloaddeploylog" | tr -d \'\" > "${temp_location}/${pkg_name}-payloadfiles"
rm "${temp_location}/${pkg_name}-payloaddeploylog"
fi
runbuildsh "postdeploy" "${pkg_path}"
# Yet more old APS code
if [ -x "${pkg_path}/package" ]; then
echo ":: Adding target ${pkg_name} to installed package database..."
[ ! -d "${installed_pkg_database}/${pkg_name}" ] && mkdir "${installed_pkg_database}/${pkg_name}"
cp -pv "${pkg_path}/package" "${installed_pkg_database}/${pkg_name}/package"
[ -e "${temp_location}/${pkg_name}-payloadfiles" ] && cp -pv "${temp_location}/${pkg_name}-payloadfiles" "${installed_pkg_database}/${pkg_name}/payloadfiles"
else
err "Target ${pkg_name} does not have a package script (it's an invalid package!). Exiting..."
fi
# Old Cleanup, might work
rm -r "${pkg_path}"
rm "${temp_location}/${pkg_name}-payloadfiles"
cd "${install_root}" || err "Could not return to main directory. Exiting..."
unset pkg_path
unset pkg_name
unset pkg_config_deploy
unset pkg_config_ver
unset pkg_config_makedepends
unset pkg_config_depends
prn "Install complete for package ${pkg_name}"
}
sync_local_repo_database() {
# Local database for repo already exists - sync it
cd "${1}" || err "Could not enter local database directory. Exiting..."
git pull
}
install_package_from_repo() { # NOTE(hippoz): This can get a tad confusing... ${1} is the repo and ${2} is the package
prn "Installing package(s) ${2} from ${1} repo"
[ ! -d "${locpkg_database}/${1}/${2}" ] && err "Target not found."
install_local_package "${locpkg_database}/${1}/${2}"
}
function help(){
prn "h|help) prints this message"
prn "v|version) version"
prn "s|sync) install package(s), and sync repositories"
prn "u|update) update"
prn "i|install) install LOCAL package(s)"
}
function version(){
prn "APS Version 0.1.0"
}
function main(){
dbg
case $1 in
s|sync) err "This feature is currently disabled in APS" ;;
#s|sync) sync_local_repo_database "official" ${official}
# [ -z "${2}" ] && exit 0
# install_package_from_repo "official" "${2}" ;;
i|install) pkg_local ${*: -1} ;;
#u|update) update ;;
u|update) err "This feature is currently disabled in APS" ;;
v|version) version ;;
h|help) help ;;
*) err "Invalid option"
esac
}
main $1 ${@: -1}