aps/aps

246 lines
No EOL
8.6 KiB
Bash
Executable file

#!/bin/sh
###################
# aps. rewritten. #
###################
# OHIO: aps *needs* to be rewritten, i can't add any thing else in the aps (v0.0.8.1)
# OHIO: aps is rewritten in 9/10th's so it's no longer a debug build
# OHIO: it's rewritten however it has some old code from aps (v0.0.8.1)
# KEMAL: abandon all hope, ye who enter here.
# OHIO: ^, however my code is cleaner than the mess before.
function conf_fetch(){
if [ -f "$XDG_CONFIG_HOME/al/config" ]; then
. $XDG_CONFIG_HOME/al/config
elif [ -f "$HOME/.config/al/config" ]; then
. $HOME/.config/al/config
elif [ -f "/etc/al/config" ]; then
. /etc/al/config
elif [ -f "/etc/skel/al/config" ]; then
. /etc/skel/al/config
#elif [ -f $AL_CFG ]; then
# . $AL_CFG
else
wrn "No config file!"
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
#echo $AL_REPO
#AL_REPO=$(echo $AL_REPO | cut -d':')
#echo $AL_REPO
fi
}
case ${debug} in
on) set -x ;;
esac
function prn(){
echo -e "\e[34m==>\e[39m $1"
}
function wrn(){
echo -e "\e[34m==>\e[33m WARNING:\e[39m $1"
}
function err(){
echo -e "\e[34m==>\e[31m ERROR:\e[39m $1" &&
rm ${lock} 2> /dev/null
exit 2
}
conf_fetch
function notf(){
echo -e "\e[34m==>\e[36m NOTIFICATION:\e[39m $1"
}
function confirm(){
prn "To continue press ENTER, or to exit CTRL-C"
read -p
}
function sources(){
pkg_config_url="$1"
pkg_config_url_prefix=$(echo ${pkg_config_url} | cut -d'+' -f1)
pkg_config_url_rest=$(echo ${pkg_config_url} | cut -d+ -f2)
case $pkg_config_url_prefix in
git) mkdir pkgsrc && git clone ${pkg_config_url_rest} pkgsrc ;;
web) pkg_config_archv=$(echo ${pkg_config_url} | sed 's:.*/::')
curl -fLO "${pkg_config_url_rest}"
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) cd pkgex && gzip -d ../${pkg_config_archv} && cd .. ;;
*) ;;
esac
mkdir --parents pkgsrc
cp -r pkgex/*/* pkgsrc ;;
*) err "Old Alnux sources is probably used!"
esac
}
function sha256(){
#sha256sum $sum > $1.sha256sum
sha256sum -c "$1" 1>&2 /dev/null
if [ "$?" -eq "0" ]; then
prn "OK!"
else
err "Sha failed!"
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
# 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}"
if [ -f sources ]; then
sources "$(cat ${pkg_path}/sources)"
#"$(cat *.sources)"
fi
# for SOURCES in *.sources; do sources "$(cat $SOURCES)"; done
for SHASUM in *.sha256sum; do sha256 "$(cat $SHASUM)"; done
runbuildsh "build" "${pkg_path}/pkgsrc"
runbuildsh "predeploy" "${pkg_path}/pkgsrc"
# Old APS code from before the rewrite!
# Deploy package
if [ "${pkg_config_deploy}" = true ]; then
prn "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}/pkgsrc"
# Yet more old APS code
if [ -x "${pkg_path}/package" ]; then
prn "Adding target ${pkg_name} to installed package database..."
[ ! -d "${installed_pkg_database}/${pkg_name}" ] && mkdir -p "${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
prn "Syncing local database for $1"
if [ ! -d "${locpkg_database}/${1}" ]; then
# Local database for repo doesnt exists - clone it
git clone "${2}" "${locpkg_database}/${1}"
else
# Local database for repo already exists - sync it
cd "${locpkg_database}/${1}" || err "Could not enter local database directory. Exiting..."
git pull
fi
}
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"
pkg_local "${locpkg_database}/${1}/${2}"
[ ! -d "${locpkg_database}/${1}/${2}" ] && err "Target not found."
}
update() {
prn "Upgrading installed packages"
cd "${installed_pkg_database}" || err "Could not enter local installed package database directory. Exiting..."
for pkg in */; do
installed_pkg_path="${installed_pkg_database}/${pkg}"
. "${installed_pkg_path}/package"
pkg_name="${installed_pkg_path%/}"
pkg_name="${pkg_name##*/}"
already_installed_version=${pkg_config_ver}
[ ! -d "${locpkg_database}/${1}/${pkg_name}" ] && die "Package ${pkg_name} was not found in ${1}. Exiting..."
. "${locpkg_database}/${1}/${pkg_name}/package"
if [ ! "${already_installed_version}" = "${pkg_config_ver}" ]; then
echo ":: Updating package ${pkg_name} (out of date)"
install_package_from_repo "${1}" "${pkg_name}"
fi
unset pkg_config_deploy
unset pkg_config_ver
unset pkg_config_makedepends
unset pkg_config_depends
done
}
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(){
if [ -f "${lock}" ]; then
err "A lock file already exists (another instance of the package manager could be running). If you're sure no package manager is running, remove the file ${lock}."
fi
touch "${lock}"
case $1 in
s|sync) sync_local_repo_database "${official}" ${official}
[ -z "${2}" ] && exit 0
install_package_from_repo "${official}" "${@: -1}"
confirm ;;
i|install) pkg_local ${*: -1}
confirm ;;
u|update) update
confirm ;;
v|version) version ;;
h|help) help ;;
apsinst) if [ $APS_PKG=y ]; then
install -v aps
*) err "Invalid option"
esac
rm ${lock}
}
main $1 ${@: -1}