include/queue: Add functions for file queues and duplicate-free queues
For certain automation tasks, it would be helpful if filesystem objects
could be passed through queues. This commit adds such functionality to
the queue module.
For passing files, these functions can be used:
- queue_put_file()
- queue_get_file()
For duplicate-free transient data:
- queue_put_unique()
- queue_get()
For other transient data:
- queue_put()
- queue_get()
There are two things worth noting:
1. The queues are line-based (transient data may not contain newlines)
2. Queues cannot be used for transient data and files at the same time
include/sem: Allow semaphores to be created in arbitrary locations
The current implementation cannot be used to created semaphores outside
of $TOOLBOX_HOME/sem. This makes it impossible to share semaphores with
scripts that are executed as a different user.
This commit changes the semaphore implementation so that only semaphore
names that don't contain slashes will be created in $TOOLBOX_HOME/sem.
The ssh_tunnel_close() and ssh_proxy_close() functions do essentially
the same thing, so they should be merged into one. Further, both of
the functions require the user to remember multiple values from the
ssh_*_open() call in order to close the connection. This seems
unnecessarily complicated.
This commit adds the ssh_close() function as a replacement for
ssh_tunnel_close() and ssh_proxy_close(). Further, the ssh_*_open()
functions now return a handle that can be passed to ssh_close() to
close the respective connection.
include/log: Remove timestamp and pid from log path
Having the timestamp and pid in the log path causes a large number of
log files to be generated, which makes it difficult to find the correct
one.
This commit removes the timestamp and pid from the log path, causing
all processes with the same name to log to the same file. To distinguish
individual processes, the log_write() function will also log the pid of
the calling process.
debian: Change architecture to "all" and fix warnings during build
The architecture in the Debian control file is set to "any", causing
architecture-specific packages to be built. This commit changes the
architecture to "all", causing the resulting packages to be usable on
any architecture.
This commit further fixes other warnings emitted by dpkg-buildpackage
with regard to the changelog and fields in the control file.
Global variables declared in the sem and acpi/* modules are not exported,
causing them to become invisible in child processes. This effectively makes
it impossible to use these modules in scripts that fork themselves to the
background.
This commit changes the declarations so that the variables are exported.
toolbox: Allow modules to be included from TOOLBOX_HOME
The current implementation requires that modules be located in the
global module search path, TOOLBOX_PATH/include. This commit modifies
the implementation so that modules may be included from the user's
TOOLBOX_HOME in addition to the global search path:
When include() is invoked, it will attempt to include the module from
the TOOLBOX_HOME/include first, and only if it didn't succeed, it will
attempt to load the module from TOOLBOX_PATH/include.
The symlink to toolbox.sh points to the absolute path of the file in the
Debian buildroot, which is an invalid location in an installed system.
This commit fixes the symlink to point to the location of the installed
file.
toolbox: Change the default prefix to appease Debian package builds
Debian package builds are failing because the installation prefix defaults
to /usr/local instead of /usr. This changes the default prefix to /usr, to
make Debian package builds happy.
A bug in _net_iface_parse_iwlist() caused found access points to be printed
multiple times. This commit fixes the bug, so that each access point is
printed only once.
Matthias Kruk [Sun, 28 Mar 2021 02:11:59 +0000 (11:11 +0900)]
include/opt: Add parser for command line parameters
Parsing of command line parameters and printing the help text adds
a significant amount of boilerplate code to any shell script (when
done thoroughly). This commit adds the opt module, which will parse
short and long parameters, execute callbacks, and print the help
text if either "-h" or "--help" were passed.
Matthias Kruk [Sun, 28 Mar 2021 01:38:52 +0000 (10:38 +0900)]
include/array: Add functions for printing and sorting arrays
Printing and sorting arrays in-line tends to be rather awkward.
This commit adds the array_to_lines() and array_sort() functions
that take over this task.
Matthias Kruk [Sat, 27 Mar 2021 03:10:05 +0000 (12:10 +0900)]
include/iface: Add function for scanning for wireless network
The output from `iwlist scan' is rather hard to look at and bothersome
to use in scripts. This commit adds a function that parses the output
into a more machine-friendly format.
Matthias Kruk [Wed, 24 Mar 2021 23:22:35 +0000 (08:22 +0900)]
include/gitlab: Add functions to call Gitlab API from the shell
Gitlab can be integrated with other software through Gitlab's REST
API. This commit adds functions that allow using various Gitlab API
functions from the shell, such as forking repositories, managing
branches, and creating merge requests.
Matthias Kruk [Wed, 24 Mar 2021 23:17:07 +0000 (08:17 +0900)]
include/iruca: Add functions to get and set somebody's iruca status
Iruca provides a REST-ful API that can be used more conveniently than
the website. This commit adds functions for setting and getting an iruca
user's status and status message from the commandline.
Matthias Kruk [Wed, 24 Mar 2021 22:26:46 +0000 (07:26 +0900)]
include/ssh: Add functions for handling SSH tunnels and proxies
SSH provides a clean way to open and close tunnels and proxies on demand
through control sockets, however keeping track of the control sockets can
be somewhat bothersome. This commit adds functions that provide an easy
way to open and close tunnels and proxies without the caller having to
bother with control sockets.
Matthias Kruk [Wed, 24 Mar 2021 22:24:30 +0000 (07:24 +0900)]
include/array: Add function for checking if an element is in an array
Bash doesn't provide a simple way to check if an element is in an array.
This commit adds the array_contains convenience function to solve that
problem.
Matthias Kruk [Wed, 24 Mar 2021 22:20:36 +0000 (07:20 +0900)]
include/json: Add functions for creating json objects and arrays
Especially when interacting with REST-ful APIs via curl, it can be handy
to have functions to quickly generate JSON objects without having to
invoke jq. This commit adds functions for generating simple JSON objects
and arrays.
Matthias Kruk [Tue, 23 Mar 2021 23:56:27 +0000 (08:56 +0900)]
include/log: Log messages to the logfile AND stderr
The log module only writes messages to the log file, which is not
enough for scripts that are running in the foreground. This commit
changes the log_write() function to log messages to the logfile as
well as to stderr.
Matthias Kruk [Mon, 22 Mar 2021 00:46:46 +0000 (09:46 +0900)]
include/acpi: Add modules for querying battery and PSU state
This commit adds the acpi/battery and acpi/ac module which can be used
to query the state of batteries and power supply units in the system
through the kernel's sysfs ACPI interface.
Matthias Kruk [Mon, 22 Mar 2021 00:43:39 +0000 (09:43 +0900)]
include/sem: Fix names of logging functions
The functions that the sem module was using for logging do not exist in
the latest log module. This commit changes the sem module to use the
right functions.
Matthias Kruk [Mon, 22 Mar 2021 00:36:25 +0000 (09:36 +0900)]
include/log: Add logging facilities
This commit adds the log module which can be adopted by scripts to log
messages to log files that are stored in TOOLBOX_HOME. The module also
provides convenience functions for highlighting output and printing
stack traces.
In certain situations, mutex are not enough for synchronization. This
commit adds a POSIX-like semaphore implementation that can be used to
implement things like queues or singleton scripts.
Scripts that access shared resources need a means to synchronize accesses
to those resources. This commit adds a symlink-based mutex implementation
that can be used for this purpose.
Matthias Kruk [Sat, 20 Mar 2021 23:23:32 +0000 (08:23 +0900)]
toolbox: Implement toolbox initialization and module loading
When writing shell scripts, I often find myself copying or rewriting
functions because bash does not provide a mechanism to easily reuse
code. This commit adds a mechanism for loadable bash "modules".