# Systemd dynamic instance names are BASE64 encoded due to issue we have encountered in RDK v444 image for MAG540 (rm#36204)
# Old implementation (PROGRAM=="/bin/systemd-escape %E{DEVPATH}") did not work for some reason
# and systemd instance name was broken ('\' symbols were missed in the result string)

KERNEL=="sd[a-z][0-9]", SUBSYSTEMS=="usb", ACTION=="add" TAG+="systemd", PROGRAM=="/bin/sh -c '/bin/echo $devpath | /bin/base64 | tr -d \\n'", ENV{SYSTEMD_WANTS}+="usb-mount@%c.service"

KERNEL=="sd[a-z][0-9]", SUBSYSTEMS=="usb", ACTION=="remove", PROGRAM=="/bin/sh -c '/bin/echo $devpath | /bin/base64 | tr -d \\n'",  RUN+="/bin/systemctl stop usb-mount@%c.service"

KERNEL=="sd[a-z]", SUBSYSTEMS=="usb", ACTION=="add" TAG+="systemd", PROGRAM=="/bin/sh -c '/bin/echo $devpath | /bin/base64 | tr -d \\n'",  ENV{SYSTEMD_WANTS}+="usb-mount@%c.service"

KERNEL=="sd[a-z]", SUBSYSTEMS=="usb", ACTION=="remove", PROGRAM=="/bin/sh -c '/bin/echo $devpath | /bin/base64 | tr -d \\n'",  RUN+="/bin/systemctl stop usb-mount@%c.service"
