Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
scripting_services_rules_examples [2024/10/17 16:49] – Added a second script crcerrorscripting_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 ''/userdata/system/services/''   - The **user services** can be created and modified by the user in ''/userdata/system/services/''
  
-==== Usage ====+====== Usage ======
  
 How to write a proper user service script: How to write a proper user service script:
Line 25: Line 25:
 **Enabling** them (with ''batocera-services enable'') works the same. To actually **start** a service, enable it first, then restart Batocera or use ''batocera-services start''. **Enabling** them (with ''batocera-services enable'') works the same. To actually **start** a service, enable it first, then restart Batocera or use ''batocera-services start''.
  
-==== 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 51: Line 51:
 </code> </code>
  
-==== Conditions ====+===== Conditions =====
  
 All these scripts are initiated through ''/etc/init.d/S99userservices'' so there is a **start** and a **stop** condition that can be used inside the scripts. S99 will wait for all scripts to be finished in stop condition, so be aware of your scripts using sleep timers and infinite do-while loops. All these scripts are initiated through ''/etc/init.d/S99userservices'' so there is a **start** and a **stop** condition that can be used inside the scripts. S99 will wait for all scripts to be finished in stop condition, so be aware of your scripts using sleep timers and infinite do-while loops.
  
- ==== Script Examples ====+ ===== Script Examples =====
  
 **Just some examples to show how powerful these kind of scripts can be.** **Just some examples to show how powerful these kind of scripts can be.**
Line 113: Line 113:
  
 #only on start condition #only on start condition
-[[ $1 == stop ]] && exit 0+[[ $1 == start ]] || exit 0
  
 # Sanatize Windows-CRLF to unix-style # Sanatize Windows-CRLF to unix-style
Line 120: Line 120:
 pushd /userdata/system/services > /dev/null pushd /userdata/system/services > /dev/null
  
-find -type f -printf '%f\n' | 
 while read USER_SERVICE while read USER_SERVICE
 do do
 +    grep -rlq $'\r' "${USER_SERVICE}" && dos2unix -k -q "${USER_SERVICE}"
 +
     SANATIZE="${USER_SERVICE//[^0-9A-Za-z_]/_}"     SANATIZE="${USER_SERVICE//[^0-9A-Za-z_]/_}"
     SANATIZE="$(echo "$SANATIZE" | sed 's/^[[:digit:]]*//')"     SANATIZE="$(echo "$SANATIZE" | sed 's/^[[:digit:]]*//')"
Line 128: Line 129:
     then     then
         mv -b --suffix=_bak "${USER_SERVICE}" "${SANATIZE}"         mv -b --suffix=_bak "${USER_SERVICE}" "${SANATIZE}"
-        USER_SERVICE="-back2life-"  
     fi     fi
  
-    [[ "${USER_SERVICE}" == "-back2life-" ]] && USER_SERVICE="${SANATIZE}" +done < <(find -type f -printf '%f\n')
-    grep -rlq $'\r"${USER_SERVICE}" && dos2unix -k -q "${USER_SERVICE}" +
- +
-done+
  
 popd > /dev/null popd > /dev/null
Line 145: 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 ''exit 0'' but **exitcode 0** is not **exitcode 0^M** and therefore you would see an error like ''numeric argument required: exit: 0''Nevertheless the script is able to "repair" itself and will work properly if you start it up a second time or reboot Batocera twice after script activation through EmulationStation. +Nevertheless the script is able to "repair" itself and will work properly if you start it up a second time or reboot Batocera twice after script activation through EmulationStation. If you left this service active in background then at last on reboot, every user-added service script can be repaired now.
  • scripting_services_rules_examples.1729183764.txt.gz
  • Last modified: 20 months ago
  • by crcerror