[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.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

ktuimala wrote: Fri Jan 21, 2022 11:05 am grep zfs /proc/filesystems output:

Code: Select all

$ grep zfs /proc/filesystems
nodev   zfs
That's exactly what I'm after. Nice and simple. QTS doesn't support ZFS so this should be a reliable way of detecting QuTS. :geek:

Thanks for your research and efforts today, I'll begin work on adding these checks into the [create-autorun.sh] script shortly. Image

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

OneCD wrote: Fri Jan 21, 2022 11:08 am Thanks for your research and efforts today, I'll begin work on adding these checks into the [create-autorun.sh] script shortly. Image
You are very welcome. Will be more than happy to test it for you once you are done with it. I am going to reset my NAS a couple more times before I am satisfied with it. So will have no issue doing a clean test.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

ktuimala wrote: Fri Jan 21, 2022 11:21 am Will be more than happy to test it for you once you are done with it. I am going to reset my NAS a couple more times before I am satisfied with it. So will have no issue doing a clean test.
I've just pushed a few updates to the GitHub repo so this script will now support QuTS: https://github.com/OneCDOnly/create-aut ... ea49dbd15f

Can you please try this new version when you get a chance?

Code: Select all

curl -skL https://git.io/create-autorun | bash
Your existing [autorun.sh] will be backed-up to the autorun store on your default volume and replaced with a symlink. :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

OneCD wrote: Sat Jan 22, 2022 5:50 am Can you please try this new version when you get a chance?
I ran it with sudo but it yielded a failure. ZFS1_DATA looks correct. I will investigate a bit further to see if my monkeying was the cause. I was doing stuff on that volume last night.

Code: Select all

~]$ sudo curl -skL https://git.io/create-autorun | bash
Password:
create-autorun.sh (220122)

info: NAS model: TVS-872X
info: QuTS version: 5.0.0 #20211222
info: default volume: /share/ZFS1_DATA
done: found autorun partition (/dev/sdi6)
done: created mount-point (/tmp/create-autorun.N059ta)
done: mounted (ext2) autorun partition (/dev/sdi6) at (/tmp/create-autorun.N059ta)
done: found tag-file (/tmp/create-autorun.N059ta/uLinux.conf) - we're in the right place
fail: Unable to create script store! (/share/ZFS1_DATA/.system/autorun/scripts)
done: unmounted (ext2) autorun partition
done: removed mount-point (/tmp/create-autorun.N059ta)
Let me know what additional debugging you would like to see?
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

I was mistaken, that was not the one I was messing with. However, all seems appropriate. Here is a listing of the directories for you. Sudo obviously has rights and the directory is not immutable. I tested I could create a directory and files in .system.

/share/ZFS1_DATA:

Code: Select all

~]$ sudo ls -la /share/ZFS1_DATA/
total 142
drwxrwxrwx 17 admin administrators  20 2022-01-20 19:06 .
drwxrwxrwt 39 admin administrators 900 2022-01-21 15:50 ..
drwxrwxrwx  2 admin administrators   4 2022-01-19 20:31 .@backup_code_signing
drwxrwxrwx  6 admin administrators   6 2022-01-20 22:19 homes
lrwxr-xr-x  1 admin administrators  28 2022-01-19 20:30 .installation -> ../ZFS530_DATA/.installation
drwxr-xr-x  2 admin administrators  14 2022-01-20 19:06 .ldapdb
drwxr-xr-x  2 admin administrators   4 2022-01-20 23:30 .logs
drwxr-xr-x  2 admin administrators   6 2022-01-19 20:31 .nc
drwxrwxrwx  2 admin administrators   2 2022-01-19 20:31 .php_session
drwxr-xr-x  2 admin administrators   2 2022-01-20 19:00 .php_session_sys
drwxr-xr-x  3 admin administrators   3 2022-01-19 20:31 .qcoolie
-rw-r--r--  1 admin administrators  27 2022-01-19 20:30 .qextension
lrwxr-xr-x  1 admin administrators  20 2022-01-19 20:30 .qpkg -> ../ZFS530_DATA/.qpkg
drwxr-xr-x  6 admin administrators   6 2022-01-20 22:25 .samba
drwxr-xr-x  3 admin administrators   3 2022-01-20 19:04 .samba_python3
drwxr-xr-x  6 admin administrators   6 2022-01-20 00:11 .system
drwxr-xr-x  3 admin administrators   3 2022-01-21 15:39 .system_disk_data
drwxr-xr-x  2 admin administrators   3 2022-01-20 19:08 .torrent
drwxrwxrwx  2 admin administrators   2 2022-01-19 20:31 .@upload_cache
drwxrwxrwx  1 admin administrators   0 2022-01-20 19:03 .zfs
drwxr-xr-x  2 admin administrators   3 2022-01-19 20:30 .zfsPoolProfilingTool
/share/ZFS1_DATA/.system:

Code: Select all

 ~]$ sudo ls -la /share/ZFS1_DATA/.system
total 51
drwxr-xr-x  6 admin administrators  6 2022-01-20 00:11 .
drwxrwxrwx 17 admin administrators 20 2022-01-20 19:06 ..
drwxrwxr-x  2 admin administrators  4 2022-01-19 20:37 3213
drwxr-xr-x  2 admin administrators  2 2022-01-20 00:11 bluetooth
drwxr-xr-x  3 admin administrators  3 2022-01-19 20:42 root_cert
drwxr-xr-x  2 admin administrators  3 2022-01-20 19:07 wfm
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

A quick thought: can you please trying running this bit manually?

Code: Select all

sudo mkdir -p /share/ZFS1_DATA/.system/autorun/scripts; echo $?
Let's see if any error is shown.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

As expected, it worked.

Code: Select all

~]$ sudo mkdir -p /share/ZFS1_DATA/.system/autorun/scripts; echo $?
Password:
0
I nuked the autorun directory so it is ready for the next test.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Thank you.

I've just pushed a commit so we can hopefully see what the issue is when creating that path via the script. Can you please try running [create-autorun.sh] again?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

OneCD wrote: Sat Jan 22, 2022 7:07 am Thank you.

I've just pushed a commit so we can hopefully see what the issue is when creating that path via the script. Can you please try running [create-autorun.sh] again?

Code: Select all

~]$ sudo curl -skL https://git.io/create-autorun | bash
create-autorun.sh (220122b)

info: NAS model: TVS-872X
info: QuTS version: 5.0.0 #20211222
info: default volume: /share/ZFS1_DATA
done: found autorun partition (/dev/sdi6)
done: created mount-point (/tmp/create-autorun.cVG2zy)
done: mounted (ext2) autorun partition (/dev/sdi6) at (/tmp/create-autorun.cVG2zy)
done: found tag-file (/tmp/create-autorun.cVG2zy/uLinux.conf) - we're in the right place
mkdir: can't create directory '/share/ZFS1_DATA/.system/autorun/': Permission denied
fail: Unable to create script store! (/share/ZFS1_DATA/.system/autorun/scripts)
done: unmounted (ext2) autorun partition
done: removed mount-point (/tmp/create-autorun.cVG2zy)
So... interesting thing... I looked at the code pulled from your curl command and it shows "#2>" instead of a "2>" before the /dev/null. Obviously the "#" is causing the issue. Once removed no more permission denied. Friday typos.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

ktuimala wrote: Sat Jan 22, 2022 7:17 am So... interesting thing... I looked at the code pulled from your curl command and it shows "#2>" instead of a "2>" before the /dev/null. Obviously the "#" is causing the issue. Once removed no more permission denied. Friday typos.
No, that hash was placed so the stderr from 'mkdir' wouldn't be discarded which allows us to view the error message. ;)

Appears to be a 'permission denied' error there. That's the issue. Now just got to figure out why.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

OneCD wrote: Sat Jan 22, 2022 7:20 am No, that hash was placed so the stderr from 'mkdir' wouldn't be discarded which allows us to view the error message. ;)
Ah... right... So this was a bit of a red herring. In my haste after it failed with your one liner, I piped it to a file, removed the #, and it worked. So, slowing down, I realize now that it only gives the error if I run it as your one liner. If I run it directly from a file, it doesn't give the error. I have tried it a couple of times now and the results are the same.

Run direct from one liner, get the error.

Code: Select all

~]$ sudo rm -rf /share/ZFS1_DATA/.system/autorun
~]$ sudo curl -skL https://git.io/create-autorun | bash
create-autorun.sh (220122b)

info: NAS model: TVS-872X
info: QuTS version: 5.0.0 #20211222
info: default volume: /share/ZFS1_DATA
done: found autorun partition (/dev/sdi6)
done: created mount-point (/tmp/create-autorun.ZhYud4)
done: mounted (ext2) autorun partition (/dev/sdi6) at (/tmp/create-autorun.ZhYud4)
done: found tag-file (/tmp/create-autorun.ZhYud4/uLinux.conf) - we're in the right place
mkdir: can't create directory '/share/ZFS1_DATA/.system/autorun/': Permission denied
fail: Unable to create script store! (/share/ZFS1_DATA/.system/autorun/scripts)
done: unmounted (ext2) autorun partition
done: removed mount-point (/tmp/create-autorun.ZhYud4)
Save to disk and run it, it works fine:

Code: Select all

~]$ sudo rm -rf /share/ZFS1_DATA/.system/autorun
~]$ curl -skL https://git.io/create-autorun > create-autorun.sh
~]$ chmod +x create-autorun.sh
~]$ sudo ./create-autorun.sh
create-autorun.sh (220122b)

info: NAS model: TVS-872X
info: QuTS version: 5.0.0 #20211222
info: default volume: /share/ZFS1_DATA
done: found autorun partition (/dev/sdi6)
done: created mount-point (/tmp/create-autorun.bzGtHF)
done: mounted (ext2) autorun partition (/dev/sdi6) at (/tmp/create-autorun.bzGtHF)
done: found tag-file (/tmp/create-autorun.bzGtHF/uLinux.conf) - we're in the right place
done: created script store (/share/ZFS1_DATA/.system/autorun/scripts)
done: created script processor (/share/ZFS1_DATA/.system/autorun/autorun.sh)
done: created symlink from (/share/ZFS1_DATA/.system/autorun/autorun.sh) to (/tmp/create-autorun.bzGtHF/autorun.sh)
done: unmounted (ext2) autorun partition
done: removed mount-point (/tmp/create-autorun.bzGtHF)
info: please place your startup scripts into (/share/ZFS1_DATA/.system/autorun/scripts)
So what they heck would cause that? Haven't run into that one before... Again, I repeated the test a couple of times and always the same result. I even tried running the script directly from bash after creating as a file and it also work. The curl pipe to bash does not.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

I can confirm the same thing here. I've just setup a secondary administrator on my development NAS, then SSH'd into the NAS as that user (which is not the way I suggest in the OP, but that process was written long-before QNAP began allowing other users to SSH in ;) ).

Code: Select all

[test@laura ~]$ sudo curl -skL https://git.io/create-autorun | bash
create-autorun.sh (220122b)

info: NAS model: TS-230 
info: QTS version: 5.0.0 #20211221 
info: default volume: /share/CACHEDEV1_DATA 
done: found autorun partition (/dev/mmcblk0p5) 
done: created mount-point (/tmp/create-autorun.z0rSeb) 
done: mounted (ext2) autorun partition (/dev/mmcblk0p5) at (/tmp/create-autorun.z0rSeb) 
done: found tag-file (/tmp/create-autorun.z0rSeb/uLinux.conf) - we're in the right place 
mkdir: can't create directory '/share/CACHEDEV1_DATA/.system/autorun/': Permission denied
fail: Unable to create script store! (/share/CACHEDEV1_DATA/.system/autorun/scripts) 
done: unmounted (ext2) autorun partition 
done: removed mount-point (/tmp/create-autorun.z0rSeb)
If I remove the autorun structure, then login via SSH using the 'admin' account, it works fine:

Code: Select all

[~] # curl -skL https://git.io/create-autorun | bash
create-autorun.sh (220122b)

info: NAS model: TS-230 
info: QTS version: 5.0.0 #20211221 
info: default volume: /share/CACHEDEV1_DATA 
done: found autorun partition (/dev/mmcblk0p5) 
done: created mount-point (/tmp/create-autorun.mFCxGp) 
done: mounted (ext2) autorun partition (/dev/mmcblk0p5) at (/tmp/create-autorun.mFCxGp) 
done: found tag-file (/tmp/create-autorun.mFCxGp/uLinux.conf) - we're in the right place 
done: created script store (/share/CACHEDEV1_DATA/.system/autorun/scripts) 
done: created script processor (/share/CACHEDEV1_DATA/.system/autorun/autorun.sh) 
done: created symlink from (/share/CACHEDEV1_DATA/.system/autorun/autorun.sh) to (/tmp/create-autorun.mFCxGp/autorun.sh) 
done: unmounted (ext2) autorun partition 
done: removed mount-point (/tmp/create-autorun.mFCxGp) 
info: please place your startup scripts into (/share/CACHEDEV1_DATA/.system/autorun/scripts) 
So, it works if we follow the original process. However, as QNAP now include 'sudo' and do allow other users to SSH into their NAS, I really should get this working in the conventional manner. :geek:

This means I'll need to add a check for $EUID to the script to ensure it's being run as the superuser. Something like:

Code: Select all

if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root"
    exit 1
fi
Good pickup on the output from 'curl' being problematic. Image There's a very faint bell ringing in my head as to why this happens, but I just can't put my finger on it. Need to do some research.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Ah, here we go. Use 'sudo' this way:

Code: Select all

curl -skL https://git.io/create-autorun | sudo bash
Works fine. :D

Code: Select all

[test@laura ~]$ curl -skL https://git.io/create-autorun | sudo bash
Password: 
create-autorun.sh (220122b)

info: NAS model: TS-230 
info: QTS version: 5.0.0 #20211221 
info: default volume: /share/CACHEDEV1_DATA 
done: found autorun partition (/dev/mmcblk0p5) 
done: created mount-point (/tmp/create-autorun.ABTFOo) 
done: mounted (ext2) autorun partition (/dev/mmcblk0p5) at (/tmp/create-autorun.ABTFOo) 
done: found tag-file (/tmp/create-autorun.ABTFOo/uLinux.conf) - we're in the right place 
done: created script store (/share/CACHEDEV1_DATA/.system/autorun/scripts) 
done: created script processor (/share/CACHEDEV1_DATA/.system/autorun/autorun.sh) 
done: created symlink from (/share/CACHEDEV1_DATA/.system/autorun/autorun.sh) to (/tmp/create-autorun.ABTFOo/autorun.sh) 
done: unmounted (ext2) autorun partition 
done: removed mount-point (/tmp/create-autorun.ABTFOo) 
info: please place your startup scripts into (/share/CACHEDEV1_DATA/.system/autorun/scripts) 

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ktuimala
Starting out
Posts: 23
Joined: Thu Jan 20, 2022 2:46 pm

Re: [SCRIPT] create-autorun.sh

Post by ktuimala »

OneCD wrote: Sat Jan 22, 2022 11:52 am Ah, here we go. Use 'sudo' this way:

Code: Select all

curl -skL https://git.io/create-autorun | sudo bash
Works fine. :D
I am speechless.... You know how much I use sudo in my every day with many nested pipes? I have never seen sudo get rights cut after the first command. However, I don't use sudo much with a pipe to bash.... Might be a bash specific thing. Very odd...

Well, I guess for now that just means more detailed instructions for those that run it. Have to give them some flavors to try pending their situation.

At any rate, fantastic find. Things are working well over here. Glad I could help you wrangle this mess and you were able to turn it around. I was and still am fed up with qnap support. It was like explaining colors to a blind person.

Have a great weekend!
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

ktuimala wrote: Sat Jan 22, 2022 5:19 pm At any rate, fantastic find. Things are working well over here. Glad I could help you wrangle this mess and you were able to turn it around. I was and still am fed up with qnap support. It was like explaining colors to a blind person.
Cheers mate, your work on this is much appreciated. :geek:

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Post Reply

Return to “Users' Corner”