3

I'm working on an "edgemax feature-wizard" which is kind of a plugin system. There are only three files allowed in a plugin tarball: a bash script as backend, a HTML file as frontend and a validation.json file for input validation from frontend, so please don't ask why I don't just put the deb packages into the tarball -- they get ignored.

I want to ship deb packages with that "wizard" so I have to base64 encode the files and put it into the bash script to be extracted when the script is run. Now, I know how to do all this, but I'm doing it manually by copy-pasting the base64 part into the bash file and then cut-paste into right position, which is unhandy when updating those packages to recent version.

Would there be a possibility to encode the deb files in base64 and write it to line 65 of the bash script?

I've read this article and I tried

sed -i "65i\\$(base64 package.deb)" wizard-run

but that complains with:

bash: /bin/sed: Argument list too long

Here's my code; the base64-part has to go within the double-quotes from the echo statement:

if [ $arch == 'mips' ]; then
    # base64: olsrd_0.9.0.3-1_mips.deb
    echo "
    <base64encoded-pkg>
    " | base64 -d > $cfgusrdir/olsrd_0.9.0.3-1_mips.deb
    # base64: olsrd-plugins_0.9.0.3-1_mips.deb
    echo "
    <base64encoded-pkg>
    " | base64 -d > $cfgusrdir/olsrd-plugins_0.9.0.3-1_mips.deb
fi

1 Answers1

2

Using sed and I/O redirection:

{
  sed -n '1,64p' wizard-run;
  base64 package.deb;
  sed -n '66,$p' wizard-run;
} > wizard-run.tmp && mv wizard-run.tmp wizard-run
phk
  • 5,893
  • 7
  • 41
  • 70