I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to the command opkg install <package name>
The text file is a list of over 100 packages. What I was trying to do was pass that list to opkg install in such a way that each package is output as a space delimited list.
Your suggestion helped me however. I ended up running cat PTI.txt | tr '\n' ' ' and then copy/pasting the space delimited out put from that as the argument.
Not quite as elegant as I had hoped to be, but still... works!
I don’t entirely agree, although I do see your point.
In this case, it sounds like the op is looking for a hands-off way of managing package installs. If that is true, the human intervention/decision process is likely moot unless the error conditions and resolutions are coded into the script.
Beyond that, the end of the install process will provide “collected errors” which will be a full list based on everything that happened in that singular run of opkg install. By contrast, it would be hard to read the errors from say 100 individual installation commands (if scripted) since it would be buried in tons of other lines of output in the scroll back buffer (which also needs to be deep or they get lost).
Therefore, unless a human operator is watching and running the individual install commands, there is little to no reason to run then individually, and it can actually be beneficial to run them in a single command.
why don't you build an image with imagebuilder locally or using building server with your predefined 100 packages and install that image directly? assuming you have the storage space for that.
otherwise the while read line is your best option.
Beyond that, the end of the install process will provide “collected errors” which will be a full list based on everything that happened in that singular run of opkg install.
that's not necessary true because there is a limit to command buffer so you may not able to pass all package names in one shot. read line is safer if you have a long list, passing handful of package names will work indeed with you one-liner.
Probably OT, but I figured I'd mention another tack. If your goal is to update your router firmware, then restore the packages and settings, consider the Attended Sysupgrade package
I just posted that page as a DRAFT - but I've been using the package for months without problem. Enjoy!
I was reading the POSIX reference material and the limit for a line is 2048 octets including the terminating new line char. You could probably test the limit yourself but 2047 characters might be a good value to plan on. I don't think there is a standard limit of the number of words on the command line but each app might have limits.
isn't better if you compile a version with all the packages you need? I mean, you can use Attended Sysupgrade to do that, but I don't know if it is the best option for you