#!/usr/bin/env -S bash #PROTECTED # Sanatize Service by crcerror (second life) - or: How to fix Windows linebreaks without manually code edits? grep -rlq $'\r' "$0" && dos2unix -k -q "$0" && exit 0 # Selfrepair for called script #only on start condition [[ $1 == stop ]] && exit 0 # Sanatize Windows-CRLF to unix-style # Sanatize filenames: Use underscore for non allowed characters pushd /userdata/system/services > /dev/null find -type f -printf '%f\n' | while read USER_SERVICE do SANATIZE="${USER_SERVICE//[^0-9A-Za-z_]/_}" SANATIZE="$(echo "$SANATIZE" | sed 's/^[[:digit:]]*//')" if [[ "${USER_SERVICE}" != "${SANATIZE}" ]] then mv -b --suffix=_bak "${USER_SERVICE}" "${SANATIZE}" USER_SERVICE="-back2life-" fi [[ "${USER_SERVICE}" == "-back2life-" ]] && USER_SERVICE="${SANATIZE}" grep -rlq $'\r' "${USER_SERVICE}" && dos2unix -k -q "${USER_SERVICE}" done popd > /dev/null