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/14 01:15] – [Usage] Tone, spelling, formatting, factual corrections in second paragraph maximumentropy | scripting_services_rules_examples [2025/06/07 06:59] (current) – Scripts and Wikicode crcerror | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| - The **user services** can be created and modified by the user in ''/ | - The **user services** can be created and modified by the user in ''/ | ||
| - | Each of the services may be enabled or disabled in the EmulationStation frontend: **MAIN MENU** -> **SYSTEM SETTINGS** -> **SERVICES** | + | ====== Usage ====== |
| - | + | ||
| - | ==== Usage ==== | + | |
| How to write a proper user service script: | How to write a proper user service script: | ||
| Line 20: | Line 18: | ||
| - Store your script in ''/ | - Store your script in ''/ | ||
| - Reboot your device to make the services selectable in EmulationStation. | - Reboot your device to make the services selectable in EmulationStation. | ||
| + | |||
| + | Each of the services may be enabled or disabled in the EmulationStation frontend: **MAIN MENU** -> **SYSTEM SETTINGS** -> **SERVICES**. | ||
| **Disabling** services (with '' | **Disabling** services (with '' | ||
| Line 25: | Line 25: | ||
| **Enabling** them (with '' | **Enabling** them (with '' | ||
| - | + | ===== Filename conventions | |
| - | + | ||
| - | + | ||
| - | ==== Filename conventions ==== | + | |
| For filenames there are some specfic rules! This is caused as every service-file is exported as systemvariable. So only charaters from A-Z (upper- and lowercase, mixed), the underscore and digits (Please avoid as first character) are allowed. | For filenames there are some specfic rules! This is caused as every service-file is exported as systemvariable. So only charaters from A-Z (upper- and lowercase, mixed), the underscore and digits (Please avoid as first character) are allowed. | ||
| Line 54: | Line 51: | ||
| </ | </ | ||
| - | ==== Conditions ==== | + | ===== Conditions |
| All these scripts are initiated through ''/ | All these scripts are initiated through ''/ | ||
| - | ==== Script Examples ==== | + | ===== Script Examples ===== |
| + | |||
| + | **Just some examples to show how powerful these kind of scripts can be.** | ||
| + | |||
| + | This script example is able to spawn " | ||
| + | |||
| + | |||
| + | By **stopping** the mainservice, | ||
| + | |||
| + | <code bash| PI_POWERSWITCHES> | ||
| + | # | ||
| + | # Spawn Service Script by cyperghost (second life) | ||
| + | # This is a crude example, but shows the ability of the new services | ||
| + | |||
| + | 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?** \\ | 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?** \\ | ||
| Line 69: | Line 113: | ||
| #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 76: | Line 120: | ||
| pushd / | pushd / | ||
| - | find -type f -printf ' | ||
| while read USER_SERVICE | while read USER_SERVICE | ||
| do | do | ||
| + | grep -rlq $' | ||
| + | |||
| SANATIZE=" | SANATIZE=" | ||
| SANATIZE=" | SANATIZE=" | ||
| Line 84: | Line 129: | ||
| then | then | ||
| mv -b --suffix=_bak " | mv -b --suffix=_bak " | ||
| - | USER_SERVICE=" | ||
| fi | fi | ||
| - | [[ " | + | done < < |
| - | grep -rlq $'\r' | + | |
| - | + | ||
| - | done | + | |
| popd > /dev/null | popd > /dev/null | ||
| Line 101: | Line 142: | ||
| - Setted a bash envirionment with proper seperators | - Setted a bash envirionment with proper seperators | ||
| - | Usually the command for the first codeline (line 3) would be '' | + | Nevertheless the script is able to " |
- scripting_services_rules_examples.1728868541.txt.gz
- Last modified: 20 months ago
- by maximumentropy