[SCRIPT] create-autorun.sh

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
Post Reply
teedjee
New here
Posts: 5
Joined: Wed May 17, 2017 2:07 pm

Re: [SCRIPT] autorun.sh installer

Post by teedjee » Sun Jun 03, 2018 7:16 am

Hi all, hi OneCD,

Great job that your script does! It helps me a lot because I couldn't find what mount parameters to use for my TS231+ NAS, prying into /dev to no avail. Even classical command like 'parted $(getcfg system 'System Device') print' failed. And then your script did it all. Many congrats to you.

No time to analyze why yours is so powerful, I jumped directly to the next step: put a script into .../.system/autorun/scripts. A simple one that I need to start a node server that I'll hook to Apache.

This script looks like this:

Code: Select all

#!/bin/sh
/usr/local/bin/node /share/CACHEDEV1_DATA/Web/node-server/server.js &


It relies on node.js which does not depend on Entware. Anyway what works manually does not start from autorun.

Any idea why? /usr/local/bin not ready?

Thanks, cheers.
Thanks, Gerard
QNAP TS231+
ARM Cortex AL212 - A15 dual-core processor @1.7GHz and 1GiB RAM
2 x Seagate ST3000DM008-2DM166 CC26 2794.52 GiB in RAID 1

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD » Sun Jun 03, 2018 10:55 am

Hey Gerard. :)

teedjee wrote:It relies on node.js which does not depend on Entware. Anyway what works manually does not start from autorun.

Any idea why? /usr/local/bin not ready?

Could be.

How did you install Node.js? Via one of the QPKGs? If so, please note QPKGs execute after [autorun.sh]

Have you confirmed the autorun system is working? If so, a log file will be present at [/var/log/autorun.log]. This will show the launch datetime, name, stdout and stderr of each script if it was run.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

teedjee
New here
Posts: 5
Joined: Wed May 17, 2017 2:07 pm

Re: [SCRIPT] autorun.sh installer

Post by teedjee » Sun Jun 03, 2018 4:16 pm

Hi OneCd,

First thanks for your swift reply. I appreciate your signature too! Running Debian instead of QNAP firmware would be such a relief in many respects! :-)

I am not too much into QNAP architecture. I suppose QPKG is the package manager of QNAP, in other words the one called 'App Center' on the admin homepage.

Yes, I checked in the log that your autorun script starts mine. And yes the node.js package has been installed from the App Center. Thus I need a means to delay the launch of this node server. I'll see how to do this based on examples you already gave in this thread.

Have a good day.
Thanks, Gerard
QNAP TS231+
ARM Cortex AL212 - A15 dual-core processor @1.7GHz and 1GiB RAM
2 x Seagate ST3000DM008-2DM166 CC26 2794.52 GiB in RAID 1

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD » Sun Jun 03, 2018 5:10 pm

No worries, Gerard. :geek:

Remember, you’ll need to background your delay so it doesn’t hold-up execution of the QPKG registration process.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

teedjee
New here
Posts: 5
Joined: Wed May 17, 2017 2:07 pm

Re: [SCRIPT] autorun.sh installer

Post by teedjee » Sun Jun 03, 2018 5:40 pm

Yes, I saw your trick which consists of launching a function in the background, which function starts its intended job after a 5-minute delay. Neat.
Thanks, Gerard
QNAP TS231+
ARM Cortex AL212 - A15 dual-core processor @1.7GHz and 1GiB RAM
2 x Seagate ST3000DM008-2DM166 CC26 2794.52 GiB in RAID 1

User avatar
mikolajek
Starting out
Posts: 41
Joined: Wed Feb 25, 2009 6:45 pm
Location: Warsaw, Poland
Contact:

Re: [SCRIPT] autorun.sh installer

Post by mikolajek » Thu Aug 30, 2018 5:47 am

I'm getting this error when running the script :(:

Code: Select all

√ DOM partition found : /dev/sdc6
√ mounted (ext2) DOM partition at : /tmp/create-autorun.5fhmSB
X DOM tag-file was not found!
√ unmounted (ext2) DOM partition : /tmp/create-autorun.5fhmSB

Can someone kindly help me with overcoming this error DOM tag-file was not found!?

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD » Thu Aug 30, 2018 6:23 am

mikolajek wrote:

Code: Select all

X DOM tag-file was not found!

The installer checks for [uLinux.conf] in the mounted partition to ensure it has found the correct one. If that file cannot be found, then it's possible the wrong partition was mounted.

Can you please post the entire output? There should be a few other lines displayed.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

User avatar
mikolajek
Starting out
Posts: 41
Joined: Wed Feb 25, 2009 6:45 pm
Location: Warsaw, Poland
Contact:

Re: [SCRIPT] autorun.sh installer

Post by mikolajek » Thu Aug 30, 2018 3:37 pm

OneCD wrote:Can you please post the entire output? There should be a few other lines displayed.

I will do so when I get home, as I can't SSH remotely from my office :(. But there was not much more there, other than the device details (it's TS-451+) and the failure message. The "log part" of the display included only those 4 rows...
Does the script places the setup log anywhere I could post here?

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Sun Sep 16, 2018 3:55 am

Finally got around to creating a GitHub repo for this: https://github.com/OneCDOnly/create-autorun

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

coaxx
Starting out
Posts: 25
Joined: Fri Jan 06, 2012 4:58 pm

Re: [SCRIPT] create-autorun.sh

Post by coaxx » Wed Jan 30, 2019 7:59 pm

thank You!
Model: TS-453B 16GB
Disks: [RAID-5] 4 x 4TB ST4000DM000 SSD Cache: no

iam@nas
Easy as a breeze
Posts: 267
Joined: Wed Jun 15, 2016 2:49 am

Re: [SCRIPT] create-autorun.sh

Post by iam@nas » Thu Jan 31, 2019 12:32 am

No offense meant but the current installation instruction is evil. The curl -k switch disables the SSL CA validation. A man in the middle attack can not be detected. If there is one and the delivered script contains "rm -rf /*" bash will happily execute it.

Please fix it to something like

Code: Select all

curl -so "create-autorun.sh" https://raw.githubusercontent.com/onecdonly/create-autorun/master/create-autorun.sh
sha256sum "create-autorun.sh"
# Expected output: 2525067e6d90a6481ba2f0e060be6ded59d997cf613ad8e2c8d313c6507434da create-autorun.sh
sudo bash "./create-autorun.sh"
Users may still used the root/admin account to use curl but this should not be required. Having to update the SHA sum with every update makes maintaining the code / README.md and this thread a little bit harder but as long as it runs with root privileges one may want to do this.


The create-autorun.sh may want to check whether the uid is 0 as a normal user may not be able to execute it successfully.
Using 'printf' a lot is great. There are still some 'echo' commands in the file. Maybe you want to replace them also with 'printf'.

The code looks fine anyhow I'm not yet ready to run it. It seems to be a very complex script to produce an autorun.sh script with 10 lines.
Also $DEF_VOLMP is not set for TS-251+ so the AUTORUN_PATH will be '/.system/autorun'.

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Thu Jan 31, 2019 2:51 am

iam@nas wrote:
Thu Jan 31, 2019 12:32 am
No offense meant but the current installation instruction is evil.
None taken... and it's not. ;)
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
The curl -k switch disables the SSL CA validation.
Yes, because certificate validation is problematic and unreliable in QTS.
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
If there is one and the delivered script contains "rm -rf /*" bash will happily execute it.
This would fly against the mentality of MITM. When you find a MITM attack that immediately trashes the host system, I'll start worrying.
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
The create-autorun.sh may want to check whether the uid is 0 as a normal user may not be able to execute it successfully.
Not required if the user follows the very simple instructions.
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
Using 'printf' a lot is great. There are still some 'echo' commands in the file. Maybe you want to replace them also with 'printf'.
Pot-ay-to, pot-ar-to... I use the tool that suits the task best. Why do you think "using 'printf' a lot is great"?
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
It seems to be a very complex script to produce an autorun.sh script with 10 lines.
It has to perform a complex job and adapt to many different environments. Hmm... may I suggest a little less opinion and a little more studying? This is a very small shell-script.
iam@nas wrote:
Thu Jan 31, 2019 12:32 am
Also $DEF_VOLMP is not set for TS-251+ so the AUTORUN_PATH will be '/.system/autorun'.
Why do you think that? You can see how it's assigned a value, right? Examine the big picture.

In summary, it's good to see someone new take an interest in shell-scripting. Your statements tell me you're a little inexperienced, so my advice would be to ask questions instead. One-day, I hope you'll be able to produce some useful scripts to run on QTS. :geek:

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

iam@nas
Easy as a breeze
Posts: 267
Joined: Wed Jun 15, 2016 2:49 am

Re: [SCRIPT] create-autorun.sh

Post by iam@nas » Thu Jan 31, 2019 4:47 am

I would not say that I wrote more lines of bash than you even though this may be possible. $DEF_VOLMP is set by /functions, so it should work. I still think that this is a lot of code, most of it needed just to support the various models and their random configurations. Six+ different options for DOM_partition and no simple query to get it is weird for QTS. Writing compatible scripts for all QNAP variants seems to be a real challenge. Great job!
Studying scripts is quite time consuming even though bash scripts are usually simple.

You use 'echo -n' and others use 'echo -e "\c"' - both variants work fine. Anyhow I prefer 'printf' as there no one needs to know or look up what '-e' or '-n' means. I replaced 'echo' in all my scripts with 'printf'. I also use quotes where possible and ${var} instead of $var. It improves a little bit the readability for me and hopefully also for others.


I wonder why users still download and install software without verifying a checksum. As a developer one should at least offer one. 'curl | bash' looks cute. It's one step to modify the /etc/hosts file and the second step to get one to execute 'curl | bash' as written on a web page. One may indeed want to fetch and execute something better than 'rm'.

teh_niemer
Starting out
Posts: 17
Joined: Sat Nov 04, 2017 7:24 am

Re: [SCRIPT] create-autorun.sh

Post by teh_niemer » Wed Mar 20, 2019 7:26 am

Wonder if someone can help me with this script. I went through the install procedure and it seemed to have worked. I then created a file called plex.sh inside the scripts directory that was created at /share/CACHEDEV1_DATA/.system/autorun/scripts/ it has 755 permissions. This is the contents of the script

Code: Select all

#!/bin/bash
#NAS Startup Script
#Access for HW Decoder Plex
chmod -R 666 /dev/dri/
chmod 755 /dev/dri/

exit
No matter what I try in the script the contents of /dev/dri revert to 600 after every reboot, I am able to change them if I SSH into the NAS and run the command, but not with this script. I'm not totally up on scripts so hopefully it's something simple.

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Wed Mar 20, 2019 8:17 am

teh_niemer wrote:
Wed Mar 20, 2019 7:26 am
... I am able to change them if I SSH into the NAS and run the command, but not with this script.
Do you mean your script file does not execute? Have you run it manually? Or only the commands it contains?

Is anything logged to indicate your script is run during startup?

Code: Select all

cat /var/log/autorun.log

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

Post Reply

Return to “Users' Corner”