Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| scripting_services_rules_examples [2024/10/05 21:59] – [Filename conventions] crcerror | scripting_services_rules_examples [2025/06/07 06:59] (current) – Scripts and Wikicode crcerror | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Batocera | + | ====== Batocera |
| - | This feature was introduces | + | Services are scripts that run at system startup and shutdown. |
| - | Even if **custom.sh** is still working (10/2024) it is recommended to use the service section for future proof setups. | + | Two types of services are supported: |
| + | - The **system services** are preinstalled in '' | ||
| + | - The **user services** can be created and modified by the user in ''/ | ||
| - | ==== Usage ==== | + | ====== Usage ====== |
| - | **Disabling** services (with '' | + | How to write a proper user service script: |
| - | **Enabling** them (with '' | + | - Use shell script language like bash or sh |
| + | - Use UNIX LF line termination, | ||
| + | - Make the script executable | ||
| + | | ||
| + | | ||
| + | - Store your script in '' | ||
| + | - Reboot your device to make the services selectable in EmulationStation. | ||
| - | ==== Filename conventions ==== | + | Each of the services may be enabled or disabled in the EmulationStation frontend: **MAIN MENU** -> **SYSTEM SETTINGS** -> **SERVICES**. |
| - | For filenames there are some rules! This is caused | + | **Disabling** services (with '' |
| + | |||
| + | **Enabling** them (with '' | ||
| + | |||
| + | ===== Filename conventions ===== | ||
| + | |||
| + | For filenames there are some specfic | ||
| + | |||
| + | Spaces, dots, bracketes and regional | ||
| Some file examples: | Some file examples: | ||
| Line 23: | Line 39: | ||
| * Hallöle --> not allowed | * Hallöle --> not allowed | ||
| - | You can test your script names by typing | + | You can test your script-names by typing |
| < | < | ||
| Line 35: | Line 51: | ||
| </ | </ | ||
| - | ==== Conditions ==== | + | ===== Conditions |
| - | All these scripts are initiated through | + | All these scripts are initiated through |
| - | As a bonus: These scripts can also be used on FAT-file systems and are started through bash-interpreter, | + | ===== Script Examples ===== |
| - | ==== Script Examples ==== | + | **Just some examples to show how powerful these kind of scripts can be.** |
| - | <code bash|SANATIZE_SERVICE> | + | This script example is able to spawn " |
| + | |||
| + | |||
| + | By **stopping** the mainservice, | ||
| + | |||
| + | <code bash| PI_POWERSWITCHES> | ||
| #!/bin/bash | #!/bin/bash | ||
| - | # Sanatize | + | # Spawn Service |
| - | # Selfrepair first | + | # This is a crude example, but shows the ability of the new services |
| - | grep -rlq $' | + | |
| + | switch=" | ||
| + | path="/ | ||
| + | |||
| + | # First argument for condition: start=service switched on | ||
| + | case ${1} in | ||
| + | start) | ||
| + | # Create single scripts per echo command and place them to /services | ||
| + | # The test start inside the sub-services is needed to set the system.power.switch parameter only if service is ticked | ||
| + | for i in ${switch}; | ||
| + | do | ||
| + | echo "[ \${1} == start ] && batocera-settings-set system.power.switch ${i}" > ${path}/ | ||
| + | done | ||
| + | |||
| + | # Check and set indicator to on if a proper value is found in batocera.conf, | ||
| + | active_service=$(batocera-settings-get system.power.switch) | ||
| + | if [ -n ${active_service} ]; | ||
| + | then | ||
| + | batocera-services enable PI_${active_service} | ||
| + | fi | ||
| + | ;; | ||
| + | |||
| + | stop) | ||
| + | #Remove all entries from filesystem and in batocera.conf (done through batocera-services) | ||
| + | for i in ${switch}; | ||
| + | do | ||
| + | rm -f ${path}/ | ||
| + | batocera-services disable PI_${i} | ||
| + | done | ||
| + | ;; | ||
| + | esac | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | This script will check for proper filenames and automatically alter them and even make backups. The idea was born by an interesting thread on github, where a user mentioned that downloaded scripts from this wiki got Windows linebreaks. This was just caused by browser download. The question is: **How to fix Windows linebreaks without manually Code editing?** \\ | ||
| + | Of course it an be done.... -- Run a small Sanatizer script (tools like DOS2UNIX do their best job here) | ||
| + | |||
| + | <code bash| SANATIZE_SERVICE> | ||
| + | # | ||
| + | # Sanatize Service by crcerror (second life) - or: How to fix Windows linebreaks without manually code edits? | ||
| + | grep -rlq $' | ||
| #only on start condition | #only on start condition | ||
| - | [[ $1 == stop ]] && | + | [[ $1 == start ]] || exit 0 |
| # Sanatize Windows-CRLF to unix-style | # Sanatize Windows-CRLF to unix-style | ||
| Line 57: | Line 120: | ||
| pushd / | pushd / | ||
| - | find -type f -printf ' | ||
| while read USER_SERVICE | while read USER_SERVICE | ||
| do | do | ||
| - | SANITIZE=${SERVICE// | + | grep -rlq $' |
| - | | + | |
| - | if [[ " | + | SANATIZE="${USER_SERVICE// |
| - | then | + | |
| - | | + | if [[ " |
| - | grep -rlq $' | + | then |
| - | | + | mv -b --suffix=_bak " |
| - | + | fi | |
| - | | + | |
| - | + | done < <(find -type f -printf | |
| - | done | + | |
| popd > /dev/null | popd > /dev/null | ||
| </ | </ | ||
| + | |||
| + | Some deeper explainations: | ||
| + | If you download this script in a Windows-Browser and then you copy the file to your Batocera-device, | ||
| + | As the first real code line is a logic-link-chain all commands will be executed proberly. I used two trick here: | ||
| + | - A remark ''# | ||
| + | - Setted a bash envirionment with proper seperators | ||
| + | |||
| + | Nevertheless the script is able to " | ||
- scripting_services_rules_examples.1728165598.txt.gz
- Last modified: 20 months ago
- by crcerror