Creating Hotfixes
This page is a guide overviewing how to create and push hotfixes for the Rhino Hotfix (opens in a new tab) utility.
Built-in Variables
Variable Name | Purpose | Value | Notes |
---|---|---|---|
SRCDIR | Staging area for hotfixes | /tmp/rhino-hotfix/${hotfix}-${published} | Useful if scripts need to cd to locations and return back later |
CARCH | Current architecture running | $(dpkg --print-architecture) | Useful if scripts require downloads or perform actions based on architecture |
Standards
Hotfix scripts should conform to the following standards:
Bash Shebang
The top of the script should always start with an env bash
shebang:
#!/usr/bin/env bash
Hotfix Function
All script actions should be contained within functions, with the main function always called hotfix
:
hotfix() {
echo "This is a hotfix."
}
Localize Everything
All variables should be localized within the functions:
hotfix() {
local names=("test1" "test2")
for i in "${names[@]}"; do
echo "${i}"
done
}
Warning: Do not localize SRCDIR
or CARCH
, or they will be made inaccessible to the script.
Danger: Do not export
any variables.
Cleanup Extra Functions
If using extra functions, be sure to clean them up with unset -f
at the end of the hotfix
function:
hotfix() {
local names=("test1" "test2")
for i in "${names[@]}"; do
subprocess "${i}"
done
unset -f subprocess
}
subprocess() {
echo "${1}"
}
Warning: This is crucial, as if these are not unset, they could bleed over into other scripts.
Example Script
Putting it all together, here is what a hotfix script might look like:
#!/usr/bin/env bash
hotfix() {
local names messages
names=("test1" "test2")
messages=("This is the first message" "This is the second")
for i in "${!names[@]}"; do
subprocess "${names[i]}" "${messages[i]}"
done
unset -f subprocess
}
subprocess() {
local name="${1}" message="${2}"
echo "${name}: ${message}"
}
Adding and Publishing
Once written, the hotfix script must follow these guidelines:
- It must be placed in the
scripts/
directory of the Rhino Hotfix (opens in a new tab) repository. - While the name of the script can be flexible, it must be relevant to the thing it is fixing.
- The name of the script must end with the suffix
.sh
.
Then, from the head of the repository, run:
go run manager.go add -t HOTFIXNAME -d "Some description" -s scripts/SCRIPTNAME.sh
git add hotfixes.json scripts/SCRIPTNAME.sh
Important: HOTFIXNAME
can only use the following characters: [A-z]
, [0-9]
, [-~._+()]
Note: HOTFIXNAME
and SCRIPTNAME
do not necessarily need to match. HOTFIXNAME
will be what is called to run the hotfix (rhino-hotfix HOTFIXNAME
).