Compare commits

...

2 commits

Author SHA1 Message Date
019acbcb45 Scaffold imperative command calls 2024-09-13 21:57:46 -03:00
5f650f7d17 Add file tracking status query function 2024-09-13 21:57:31 -03:00
5 changed files with 55 additions and 9 deletions

View file

@ -1,3 +1,4 @@
0.7.0 2024-09-13: Imperative commands install, uninstall, track and forget
0.6.0 2024-09-03: File management with the tree strategy 0.6.0 2024-09-03: File management with the tree strategy
File backups File backups
Extract authorization command to top level Extract authorization command to top level

View file

@ -14,6 +14,7 @@ package_manager() {
if [ "$OS" = "FreeBSD" ]; then if [ "$OS" = "FreeBSD" ]; then
manager="pkg" manager="pkg"
args__get_manually_installed='query -e "%a = 0" "%n"' args__get_manually_installed='query -e "%a = 0" "%n"'
args__get_status='' # TODO
args__install='install' args__install='install'
args__uninstall='delete' args__uninstall='delete'
args__update='update' args__update='update'
@ -23,6 +24,8 @@ package_manager() {
# shellcheck disable=SC2086 # shellcheck disable=SC2086
if [ "$command" = 'get_manually_installed' ]; then if [ "$command" = 'get_manually_installed' ]; then
eval $manager "$args__get_manually_installed" eval $manager "$args__get_manually_installed"
elif [ "$command" = 'get_status' ]; then
echo unimplemented: eval $manager "$args__get_status" # TODO
elif [ "$command" = 'install' ]; then elif [ "$command" = 'install' ]; then
$AUTHORIZE_COMMAND $manager $args__install $args__user_args $AUTHORIZE_COMMAND $manager $args__install $args__user_args
elif [ "$command" = 'uninstall' ]; then elif [ "$command" = 'uninstall' ]; then

View file

@ -1,8 +1,26 @@
# functions to track, untrack and query tracked state of packages
# returns 0 if all packages are tracked, 1 if any is untracked
query_packages() {
local packages="$1"
echo "$packages" | xargs | sed 's/ /\n/g' | while read -r package; do
if ! cat "$CONFIG_ROOT/packages" | grep -q "^$package$"; then
return 1
fi
return 0
done
}
track_packages() { track_packages() {
local packages="$1" local packages="$1"
echo "$packages" | xargs | sed 's/ /\n/g' | while read -r package; do echo "$packages" | xargs | sed 's/ /\n/g' | while read -r package; do
echo "$package" >> "$CONFIG_ROOT/packages" if query_packages "$package"; then
log info "Package $package was not tracked because it is already tracked"
else
echo "$package" >> "$CONFIG_ROOT/packages"
fi
done done
} }

View file

@ -149,9 +149,13 @@ prepare_directories() {
} }
print_help() { print_help() {
printf "\n tori: configuration managent and system replication tool\n" printf "\n tori: configuration management and system replication tool\n"
printf "\n Options:\n\n" printf "\n Options:\n\n"
printf "\tcheck\t\tcompare configuration to system state\n" printf "\tcheck\t\tcompare configuration to system state\n"
printf "\tinstall\t\tinstall packages\n"
printf "\tuninstall\tuninstall packages\n"
printf "\ttrack\t\tadd a file to your configuration\n"
printf "\tforget\t\tremove a file from your configuration\n"
printf "\tcache\t\trefresh the local package cache\n" printf "\tcache\t\trefresh the local package cache\n"
printf "\n" printf "\n"
printf "\tversion\t\tprint current version with release date\n" printf "\tversion\t\tprint current version with release date\n"

34
tori
View file

@ -2,7 +2,7 @@
main() { main() {
# paths # paths
VERSION="0.6.0 2024-09-03" VERSION="0.7.0 2024-09-13"
TORI_ROOT="$HOME/.local/share/tori" TORI_ROOT="$HOME/.local/share/tori"
CONFIG_ROOT="$HOME/.config/tori" CONFIG_ROOT="$HOME/.config/tori"
BACKUP_ROOT="$HOME/.local/state/tori/backup" BACKUP_ROOT="$HOME/.local/state/tori/backup"
@ -15,8 +15,8 @@ main() {
DEBUG_DISABLED_WARNING= DEBUG_DISABLED_WARNING=
## user input ## user input
argument="$1" command="$1"
parameter="$2" argument="$2"
# import source # import source
check_core_paths check_core_paths
@ -38,13 +38,33 @@ main() {
# entry point # entry point
if [ "$argument" = check ]; then if [ "$command" = check ] || [ "$command" = c ]; then
check check
elif [ "$argument" = cache ]; then elif [ "$command" = install ] || [ "$command" = i ]; then
if package_manager install "$argument"; then
track_packages "$argument"
else
log warn "Package installation failed for $argument, no action taken"
fi
elif [ "$command" = uninstall ] || [ "$command" = u ]; then
if package_manager uninstall "$argument"; then
if package_manager; then
log warn "Package uninstallation failed for $argument, no action taken"
else
untrack_packages "$argument"
fi
else
log warn "Package uninstallation failed for $argument, no action taken"
fi
elif [ "$command" = track ] || [ "$command" = t ]; then
echo unimplemented: track "$argument" # TODO
elif [ "$command" = forget ] || [ "$command" = f ]; then
echo unimplemented: untrack "$argument" # TODO
elif [ "$command" = cache ]; then
update_package_cache --force update_package_cache --force
elif [ "$argument" = version ] || [ "$argument" = -v ] || [ "$argument" = --version ]; then elif [ "$command" = version ] || [ "$command" = -v ] || [ "$command" = --version ]; then
echo "$VERSION" echo "$VERSION"
elif [ "$argument" = help ] || [ "$argument" = -h ] || [ "$argument" = --help ]; then elif [ "$command" = help ] || [ "$command" = -h ] || [ "$command" = --help ]; then
print_help print_help
else else
echo "Use 'tori help' for usage instructions" echo "Use 'tori help' for usage instructions"