First chunk of major refactor. Move code to external files located in .includes. Better code organization and easier to deal with.

This commit is contained in:
Storm Dragon 2025-05-18 19:12:02 -04:00
parent d6cfe797bc
commit e892da65c8
5 changed files with 304 additions and 290 deletions

109
.includes/checkup.sh Executable file
View File

@ -0,0 +1,109 @@
declare -a errorList
declare -a packageList
if [[ $# -eq 0 ]]; then
echo "Checking your system..."
echo
fi
if command -v wine &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Wine is installed."
else
errorList+=("Critical: Wine is not installed. You will not be able to play any games.")
fi
packageList+=("wine")
if command -v curl &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Curl is installed."
else
errorList+=("Critical: Curl is not installed. Critical functionality will not work.")
fi
packageList+=("curl")
if command -v dialog &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Dialog is installed."
else
errorList+=("Critical: Dialog is not installed. You will not be able to install, launch, or remove any games.")
fi
packageList+=("dialog")
for i in 7z cabextract unzip xz ; do
if command -v $i &> /dev/null ; then
[[ $# -eq 0 ]] && echo "${i^} is installed."
else
errorList+=("Critical: ${i^} is not installed. You will not be able to install some games or their components.")
fi
packageList+=("$i")
done
if command -v gawk &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Gawk is installed."
else
errorList+=("Warning: gawk is not installed. Game removal with -r will not work.")
fi
packageList+=("gawk")
if command -v ocrdesktop &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Ocrdesktop is installed."
else
errorList+=("Warning: ocrdesktop is not installed. It can help if the installer gets stuck to figure out what is happening.")
fi
packageList+=("ocrdesktop")
if command -v qjoypad &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Qjoypad is installed."
else
errorList+=("Warning: qjoypad is not installed. Qjoypad allows you to play keyboard only games with a gamepad.")
fi
packageList+=("qjoypad")
if command -v sox &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Sox is installed."
else
errorList+=("Warning: Sox is not installed. Audio will not work.")
fi
packageList+=("sox")
if command -v trans &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Translate-shell is installed."
else
errorList+=("Warning: translate-shell is not installed. Games that require translation will not be translated.")
fi
packageList+=("translate-shell")
if command -v sqlite3 &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Sqlite3 is installed."
else
errorList+=("Warning: sqlite is not installed. Required for games that need to be translated.")
fi
if command -v perl &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Perl is installed."
else
errorList+=("Warning: perl is not installed. Required for games that need to be translated.")
fi
packageList+=("perl")
packageList+=("sqlite")
if command -v w3m &> /dev/null ; then
[[ $# -eq 0 ]] && echo "W3m is installed."
else
errorList+=("Warning: w3m is not installed. W3m is used to view game documentation.")
fi
packageList+=("w3m")
if command -v xclip &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Xclip is installed."
else
errorList+=("Warning: Xclip is not installed. Some games may not speak or register properly.")
fi
packageList+=("xclip")
if command -v xdotool &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Xdotool is installed."
else
errorList+=("Warning: Xdotool is not installed. Some installers may not work or may need manual intervention.")
fi
packageList+=("xdotool")
# Show the results
if [[ $# -ne 0 ]]; then
for i in "${packageList[@]}" ; do
echo "$i"
done | sort
exit 0
fi
if [[ ${#errorList[@]} -eq 0 ]]; then
echo "No problems found, you are good to go."
exit 0
fi
echo "Errors detected, here is a list along with the severity."
echo "Note that errors marked critical mean that you will not be able to install and play games until they are resolved."
for i in "${errorList[@]}" ; do
echo "$i"
done
exit 0

32
.includes/functions.sh Normal file
View File

@ -0,0 +1,32 @@
# Alerts, for when user needs to read something.
alert() {
play -qnV0 synth 3 pluck D3 pluck A3 pluck D4 pluck F4 pluck A4 delay 0 .1 .2 .3 .4 remix - chorus 0.9 0.9 38 0.75 0.3 0.5 -t
echo
read -rp "Press enter to continue." continue
}
check_requirements() {
# Make sure the minimum of curl, sox, wine, and winetricks are installed or fex-emu on aarch64
if [[ "$(uname -m)" == "aarch64" ]]; then
minimumDependencies=("FEXLoader")
wine="FEXLoader -- /usr/bin/wine"
else
minimumDependencies=("curl" "sox" "wine")
fi
for i in "${minimumDependencies[@]}" ; do
if ! command -v $i &> /dev/null ; then
echo "Please install $i before continuing."
return 1
fi
done
return 0
}
# Function to open urls across OS.
open_url() {
if [[ "$(uname)" == "Darwin" ]]; then
open "${*}" 2> /dev/null
else
xdg-open "${*}" 2> /dev/null
fi
}

98
.includes/help.sh Normal file
View File

@ -0,0 +1,98 @@
documentation() {
if [[ "$2" == "Become a Patron" ]]; then
return
fi
if [[ "$2" == "Donate" ]]; then
return
fi
if ! command -v w3m &> /dev/null ; then
echo "This feature of audiogame-manager requires w3m. Please install it before continuing."
exit 1
fi
get_bottle "$1"
echo "Loading documentation, please wait..."
# Try to find documentation based on common naming conventions.
local gamePath="$(winepath -u "$2" 2> /dev/null)"
gamePath="${gamePath%/*}"
local gameDoc="$(find "$gamePath" -type f -iname 'user_manual.htm*' -or -iname 'user manual.htm*' -or -iname '*user guide.htm*' | head -1)"
# Game name specific docs, add the name to the for loop.
if [[ -z "$gameDoc" ]]; then
for i in "troopanum.txt" "superdeekout.txt" scw.html ; do
gameDoc="$(find "$gamePath" -type f -iname "$i" -or -iname 'manual.htm' | head -1)"
done
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -path '*/Manual/index.html' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname '[A-Z]*Help.htm' -or -iname '[A-Z]*Help.html' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'manual.html' -or -iname 'manual.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'en.html' -or -iname 'en.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'readme.html' -or -iname 'readme.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'manual.txt' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'readme.txt' -or -iname 'help.txt' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname '*.url' -exec grep -i 'url=' {} \; | grep -iv 'score' | head -1)"
gameDoc="${gameDoc#*=}"
gameDoc="${gameDoc//[[:cntrl:]]/}"
fi
# Display documentation if available.
if [[ -n "$gameDoc" ]]; then
w3m "$gameDoc"
else
echo "No documentation found."
fi
exit 0
}
license() {
cat << EOF
■The contents of this file are subject to the Common Public Attribution
License Version 1.0 (the ■License■); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
https://opensource.org/licenses/CPAL-1.0. The License is based on the Mozilla Public License Version
1.1 but Sections 14 and 15 have been added to cover use of software over a
computer network and provide for limited attribution for the Original
Developer. In addition, Exhibit A has been modified to be consistent with
Exhibit B.
Software distributed under the License is distributed on an ■AS IS■ basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is audiogame manager.
The Original Developer is not the Initial Developer and is . If
left blank, the Original Developer is the Initial Developer.
The Initial Developer of the Original Code is Billy "Storm Dragon" Wolfe. All portions of
the code written by Billy Wolfe are Copyright (c) 2020, 2024. All Rights
Reserved.
Contributor Michael Taboada.
Attribution Copyright Notice: Audiogame manager copyright 2020 Storm Dragon. All rights reserved.
Attribution Phrase (not exceeding 10 words): A Stormux project
Attribution URL: https://stormgames.wolfe.casa
Graphic Image as provided in the Covered Code, if any.
Display of Attribution Information is required in Larger
Works which are defined in the CPAL as a work which combines Covered Code
or portions thereof with code not governed by the terms of the CPAL.
EOF
}

52
.includes/update.sh Normal file
View File

@ -0,0 +1,52 @@
# Check for latest news
check_news() {
# For use by update scripts that want to source functions in this file.
[[ "$agmNoLaunch" == "true" ]] && return
trap return INT
# url for news file
local newsFile="https://stormgames.wolfe.casa/media/agm.ogg"
local newsPath="${configFile%/*.conf}/.news"
local newsTag="$(curl --connect-timeout 5 -sI "$newsFile" | grep -i '^etag: "' | cut -d '"' -f2)"
if [[ -z "${newsTag}" ]]; then
return
fi
local newsOldTag="$(cat "$newsPath" 2> /dev/null)"
if [[ "$newsTag" != "$newsOldTag" ]]; then
dialog --yes-label 'Play' \
--no-label 'Later' \
--backtitle 'Audiogame Manager News' \
--yesno 'Audiogame manager news is available. Please use left and right arrows to navigate and enter to confirm.' -1 -1 || return
sox -qV0 "$newsFile" -d &> /dev/null
echo -n "$newsTag" > "$newsPath"
fi
}
# Automatic update function
# Automatic update function
update() {
if ! [[ -d ".git" ]]; then
return
fi
local url="$(git ls-remote --get-url)"
if [[ "$url" =~ ^ssh://|git@|gitea@ ]] || [[ -z "$url" ]]; then
return
fi
git remote update &> /dev/null
local upstream='@{u}'
local home="$(git rev-parse @)"
local remote="$(git rev-parse "$upstream")"
if [[ "$home" == "$remote" ]]; then
return
fi
dialog --backtitle "Audiogame Manager" \
--yesno "Updates are available. Would you like to update now?" -1 -1 --stdout || return
{ git pull
git log '@{1}..' --pretty=format:'%an: %s' | tac; }
exit $?
}
# Get latest news if available
check_news
# With no arguments, open the game launcher.
if [[ $# -eq 0 ]]; then
game_launcher
fi

View File

@ -1,113 +1,9 @@
#!/usr/bin/env bash
license() {
cat << EOF
■The contents of this file are subject to the Common Public Attribution
License Version 1.0 (the ■License■); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
https://opensource.org/licenses/CPAL-1.0. The License is based on the Mozilla Public License Version
1.1 but Sections 14 and 15 have been added to cover use of software over a
computer network and provide for limited attribution for the Original
Developer. In addition, Exhibit A has been modified to be consistent with
Exhibit B.
Software distributed under the License is distributed on an ■AS IS■ basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is audiogame manager.
The Original Developer is not the Initial Developer and is . If
left blank, the Original Developer is the Initial Developer.
The Initial Developer of the Original Code is Billy "Storm Dragon" Wolfe. All portions of
the code written by Billy Wolfe are Copyright (c) 2020, 2024. All Rights
Reserved.
Contributor Michael Taboada.
Attribution Copyright Notice: Audiogame manager copyright 2020 Storm Dragon. All rights reserved.
Attribution Phrase (not exceeding 10 words): A Stormux project
Attribution URL: https://stormgames.wolfe.casa
Graphic Image as provided in the Covered Code, if any.
Display of Attribution Information is required in Larger
Works which are defined in the CPAL as a work which combines Covered Code
or portions thereof with code not governed by the terms of the CPAL.
EOF
}
# Dialog accessibility
export DIALOGOPTS='--no-lines --visit-items'
# Alerts, for when user needs to read something.
alert() {
play -qnV0 synth 3 pluck D3 pluck A3 pluck D4 pluck F4 pluck A4 delay 0 .1 .2 .3 .4 remix - chorus 0.9 0.9 38 0.75 0.3 0.5 -t
echo
read -rp "Press enter to continue." continue
}
# Check for latest news
check_news() {
# For use by update scripts that want to source functions in this file.
[[ "$agmNoLaunch" == "true" ]] && return
trap return INT
# url for news file
local newsFile="https://stormgames.wolfe.casa/media/agm.ogg"
local newsPath="${configFile%/*.conf}/.news"
local newsTag="$(curl --connect-timeout 5 -sI "$newsFile" | grep -i '^etag: "' | cut -d '"' -f2)"
if [[ -z "${newsTag}" ]]; then
return
fi
local newsOldTag="$(cat "$newsPath" 2> /dev/null)"
if [[ "$newsTag" != "$newsOldTag" ]]; then
dialog --yes-label 'Play' \
--no-label 'Later' \
--backtitle 'Audiogame Manager News' \
--yesno 'Audiogame manager news is available. Please use left and right arrows to navigate and enter to confirm.' -1 -1 || return
sox -qV0 "$newsFile" -d &> /dev/null
echo -n "$newsTag" > "$newsPath"
fi
}
# Automatic update function
# Automatic update function
update() {
if ! [[ -d ".git" ]]; then
return
fi
local url="$(git ls-remote --get-url)"
if [[ "$url" =~ ^ssh://|git@|gitea@ ]] || [[ -z "$url" ]]; then
return
fi
git remote update &> /dev/null
local upstream='@{u}'
local home="$(git rev-parse @)"
local remote="$(git rev-parse "$upstream")"
if [[ "$home" == "$remote" ]]; then
return
fi
dialog --backtitle "Audiogame Manager" \
--yesno "Updates are available. Would you like to update now?" -1 -1 --stdout || return
{ git pull
git log '@{1}..' --pretty=format:'%an: %s' | tac; }
exit $?
}
# Function to open urls across OS.
open_url() {
if [[ "$(uname)" == "Darwin" ]]; then
open "${*}" 2> /dev/null
else
xdg-open "${*}" 2> /dev/null
fi
}
# Create desktop launcher file
desktop_launcher() {
local desktopFile="${HOME}/audiogame-manager.desktop"
@ -147,118 +43,6 @@ desktop_launcher() {
# Wine configuration section
checklist() {
declare -a errorList
declare -a packageList
if [[ $# -eq 0 ]]; then
echo "Checking your system..."
echo
fi
if command -v wine &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Wine is installed."
else
errorList+=("Critical: Wine is not installed. You will not be able to play any games.")
fi
packageList+=("wine")
if command -v curl &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Curl is installed."
else
errorList+=("Critical: Curl is not installed. Critical functionality will not work.")
fi
packageList+=("curl")
if command -v dialog &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Dialog is installed."
else
errorList+=("Critical: Dialog is not installed. You will not be able to install, launch, or remove any games.")
fi
packageList+=("dialog")
for i in 7z cabextract unzip xz ; do
if command -v $i &> /dev/null ; then
[[ $# -eq 0 ]] && echo "${i^} is installed."
else
errorList+=("Critical: ${i^} is not installed. You will not be able to install some games or their components.")
fi
packageList+=("$i")
done
if command -v gawk &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Gawk is installed."
else
errorList+=("Warning: gawk is not installed. Game removal with -r will not work.")
fi
packageList+=("gawk")
if command -v ocrdesktop &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Ocrdesktop is installed."
else
errorList+=("Warning: ocrdesktop is not installed. It can help if the installer gets stuck to figure out what is happening.")
fi
packageList+=("ocrdesktop")
if command -v qjoypad &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Qjoypad is installed."
else
errorList+=("Warning: qjoypad is not installed. Qjoypad allows you to play keyboard only games with a gamepad.")
fi
packageList+=("qjoypad")
if command -v sox &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Sox is installed."
else
errorList+=("Warning: Sox is not installed. Audio will not work.")
fi
packageList+=("sox")
if command -v trans &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Translate-shell is installed."
else
errorList+=("Warning: translate-shell is not installed. Games that require translation will not be translated.")
fi
packageList+=("translate-shell")
if command -v sqlite3 &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Sqlite3 is installed."
else
errorList+=("Warning: sqlite is not installed. Required for games that need to be translated.")
fi
if command -v perl &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Perl is installed."
else
errorList+=("Warning: perl is not installed. Required for games that need to be translated.")
fi
packageList+=("perl")
packageList+=("sqlite")
if command -v w3m &> /dev/null ; then
[[ $# -eq 0 ]] && echo "W3m is installed."
else
errorList+=("Warning: w3m is not installed. W3m is used to view game documentation.")
fi
packageList+=("w3m")
if command -v xclip &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Xclip is installed."
else
errorList+=("Warning: Xclip is not installed. Some games may not speak or register properly.")
fi
packageList+=("xclip")
if command -v xdotool &> /dev/null ; then
[[ $# -eq 0 ]] && echo "Xdotool is installed."
else
errorList+=("Warning: Xdotool is not installed. Some installers may not work or may need manual intervention.")
fi
packageList+=("xdotool")
# Show the results
if [[ $# -ne 0 ]]; then
for i in "${packageList[@]}" ; do
echo "$i"
done | sort
exit 0
fi
if [[ ${#errorList[@]} -eq 0 ]]; then
echo "No problems found, you are good to go."
exit 0
fi
echo "Errors detected, here is a list along with the severity."
echo "Note that errors marked critical mean that you will not be able to install and play games until they are resolved."
for i in "${errorList[@]}" ; do
echo "$i"
done
exit 0
}
clear_cache() {
local answer
if [[ ! -d "${cache}" ]]; then
@ -532,64 +316,6 @@ help() {
exit 0
}
documentation() {
if [[ "$2" == "Become a Patron" ]]; then
return
fi
if [[ "$2" == "Donate" ]]; then
return
fi
if ! command -v w3m &> /dev/null ; then
echo "This feature of audiogame-manager requires w3m. Please install it before continuing."
exit 1
fi
get_bottle "$1"
echo "Loading documentation, please wait..."
# Try to find documentation based on common naming conventions.
local gamePath="$(winepath -u "$2" 2> /dev/null)"
gamePath="${gamePath%/*}"
local gameDoc="$(find "$gamePath" -type f -iname 'user_manual.htm*' -or -iname 'user manual.htm*' -or -iname '*user guide.htm*' | head -1)"
# Game name specific docs, add the name to the for loop.
if [[ -z "$gameDoc" ]]; then
for i in "troopanum.txt" "superdeekout.txt" scw.html ; do
gameDoc="$(find "$gamePath" -type f -iname "$i" -or -iname 'manual.htm' | head -1)"
done
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -path '*/Manual/index.html' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname '[A-Z]*Help.htm' -or -iname '[A-Z]*Help.html' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'manual.html' -or -iname 'manual.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'en.html' -or -iname 'en.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'readme.html' -or -iname 'readme.htm' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'manual.txt' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname 'readme.txt' -or -iname 'help.txt' | head -1)"
fi
if [[ -z "$gameDoc" ]]; then
gameDoc="$(find "$gamePath" -type f -iname '*.url' -exec grep -i 'url=' {} \; | grep -iv 'score' | head -1)"
gameDoc="${gameDoc#*=}"
gameDoc="${gameDoc//[[:cntrl:]]/}"
fi
# Display documentation if available.
if [[ -n "$gameDoc" ]]; then
w3m "$gameDoc"
else
echo "No documentation found."
fi
exit 0
}
install_wine() {
# Requires wine version, e.g. 7.7 and architecture, 32|64
if [[ $# -ne 2 ]]; then
@ -1070,6 +796,7 @@ game_launcher() {
if [[ $menuCode -eq 1 ]] || [[ $menuCode -eq 255 ]]; then
exit 0
elif [[ $menuCode -eq 3 ]]; then
source .includes/help.sh # Make available in this function
documentation "$game" "$(echo "$game" | cut -d '|' -f2)"
fi
create_game_array
@ -1153,8 +880,7 @@ add_launcher() {
}
trap "exit 0" SIGINT
# Check for updates
update
# If display isn't set assume we are launching from console and an X environment is running using display :0
if [[ -z "$DISPLAY" ]]; then
export DISPLAY=":0"
@ -1196,21 +922,18 @@ export ipfsGateway="${ipfsGateway:-https://ipfs.stormux.org}"
export nvdaControllerClientDll="${ipfsGateway}/ipfs/QmWu7YdSbKMk1Qm5DKvEA5hk1YuAK8wVkwhDf2CsmPkmF1?filename=nvdaControllerClient32.dll"
# Make sure the minimum of curl, sox, wine, and winetricks are installed or fex-emu on aarch64
if [[ "$(uname -m)" == "aarch64" ]]; then
minimumDependencies=("FEXLoader")
wine="FEXLoader -- /usr/bin/wine"
else
minimumDependencies=("curl" "sox" "wine")
fi
for i in "${minimumDependencies[@]}" ; do
if ! command -v $i &> /dev/null ; then
echo "Please install $i before continuing."
exit 1
fi
done
# Source helper functions
source .includes/functions.sh
source .includes/help.sh
source .includes/update.sh
# Check minimum requirements
check_requirements || exit 1
# Check for updates
update
# Get latest news if available
check_news
# With no arguments, open the game launcher.
if [[ $# -eq 0 ]]; then
game_launcher
@ -1245,7 +968,7 @@ args="${!command[*]}"
args="${args//[[:space:]]/}"
while getopts "${args}" i ; do
case "$i" in
c) checklist;;
c) ./.includes/checkup.sh;;
C) clear_cache;;
D) desktop_launcher;;
d)