aaa/bin/a3

97 lines
3.1 KiB
Text
Raw Permalink Normal View History

2024-06-06 02:01:36 +02:00
#!/bin/sh
set -e
2024-06-06 02:10:33 +02:00
. ${A3_LIB:-/usr/lib/a3}/include.sh
2024-06-06 02:01:36 +02:00
a3include_lib a3
a3include_lib log
a3include_lib util
A3_FILE=$1
[ -z "$A3_FILE" ] && exit 1
if ! [ -f "$A3_FILE" ]; then
LOGD "lfa3"
A3_FILE=$(a3index_find $A3_FILE)
[ -z "$A3_FILE" ] && fatal_log "no a3 file found"
fi
shift
name=$(a3ff a3read_meta name)
description=$(a3ff a3read_meta description)
author=$(a3ff a3read_meta author)
url=$(a3ff a3read_meta url)
require_value meta:a3.name $name
echo "name: $name"
[ -n "$description" ] && echo "description: $description"
[ -n "$author" ] && echo "author: $author"
[ -n "$url" ] && echo "url: $url"
echo "status: $(a3index_current_status $name || echo "not installed")"
echo "---"
A3_INSTALL_BIN_PATH=${A3_INSTALL_BIN_PATH:-/usr/bin}
A3_INSTALL_LIB_PATH=${A3_INSTALL_LIB_PATH:-/usr/lib}
main() {
case $1 in
update)
a3index_is $name installed || fatal_log not installed.
a3index_update $name pending
A3_FILE=$(a3index_find $name)
main install
;;
install)
a3index_is $name installed && fatal_log "$name is already installed."
oldpwd=$(pwd)
if [ -n "$(a3ff a3read_declaration declare_workdir | head -n 1)" ]; then
cd $(a3ff a3read_declaration declare_workdir | head -n 1)
fi
a3ff a3index_create $name
a3ff a3read_declaration declare_executable | while read ex; do
[ -z "$ex" ] && continue
filename=$(basename $ex)
if [ -f "$A3_INSTALL_BIN_PATH/$filename" ]; then
LOGW "overwriting $A3_INSTALL_BIN_PATH/$filename..."
else
LOGI "copying $ex to $A3_INSTALL_BIN_PATH/$filename..."
fi
cp $ex $A3_INSTALL_BIN_PATH/$filename
chmod +x $A3_INSTALL_BIN_PATH/$filename
done
a3ff a3read_declaration declare_library | while read lib; do
[ -z "$lib" ] && continue
if [ -d "$A3_INSTALL_LIB_PATH/$name" ]; then
LOGW "overwriting $A3_INSTALL_LIB_PATH/$name..."
else
LOGI "copying library..."
fi
cp -r $lib/. $A3_INSTALL_LIB_PATH/$name
done
a3index_update $name installed
cd $oldpwd
;;
eval) shift; $@ ;;
remove)
a3index_is $name installed || fatal_log "$name is not installed."
a3ff a3read_declaration declare_executable | while read ex; do
filename=$(basename $ex)
[ -f "$A3_INSTALL_BIN_PATH/$filename" ] || fatal_log "$A3_INSTALL_BIN_PATH/$filename does not exist"
LOGI "removing $A3_INSTALL_BIN_PATH/$filename..."
rm $A3_INSTALL_BIN_PATH/$filename
done
a3ff a3read_declaration declare_library | while read lib; do
[ -d "$A3_INSTALL_LIB_PATH/$name" ] || continue
LOGI "removing library..."
rm -r $A3_INSTALL_LIB_PATH/$name
done
a3index_update $name cache
;;
list)
for f in $(find $A3_INDEX_ROOT -iname "*.a3"); do
echo "$(a3read_meta "$f" name): $(basename $(dirname $f))"
done
esac
}
main $@