I am a little confused at exactly what work you have done to convert this script yourself?
1. Have you looked at what the differences are between ash and bash online?
2. Have you looked up any tutorials about ash to give you some ideas on what constitutes a valid line of code for if, while, process substitution, parameter substitution and arithmetic operations? (all of which are used in your bash code)
3. Your token efforts so far seem to be:
a - You altered the interpreter from bash to sh (which if not a symbolic link to ash will not make this an ash script)
b - You say you put in # marks to make up for an error about blank lines, yet I still count 14 blank lines ... so why do these ones not error?
4. The formatting referred to by keefaz is to make your code readable and easily identify where your control structures (if and while) begin and end. Without these it is like looking through a haystack to find what should be obvious
5. Another formatting inconsistency, which may or may not matter, is that some of your if tests place the semi-colon immediately after the test (ie. if [ some_test ]
while others leave a space (ie. if [ some_test ] ; ) ... maybe ash doesn't like one of these versions??
6. Have you tested any of the code individually to perhaps assist in tracking down the errors?
As you can see from the above, there would appear to have been little actual attempt made by yourself to solve this issue apart from being given code.
You need to look into most of the above if you are to understand not only the code you are trying to alter, but if those providing solutions are actually assisting or not.