You could just do this with any version of awk so it'll work in any shell on every Unix box without needing to escape regexp metachars and without needing to repeat any parts of the string you're trying to match to be able to just print it as-is:
$ awk -v str='[etc]\ntransient = true' -v RS= '
index("\n"$0"\n","\n"str"\n") { f=1 }
{ print }
END { if (!f) print str }
' file
[composefs]
enabled = yes
[sysroot]
readonly = true
[etc]
transient = true