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

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Ah, that's actually good news. This is the location that my script would place a symlink back onto the default volume.

From memory, the default is for no autorun.sh to be present there.

So, this is progress. ;)

I'll have to integrate the mount commands used in that script you just ran into my own script. But I'll need some time to do this. Maybe a day or two. Then I'll upload a new autorun package.

Thanks for trying that German script. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ugduibill
Starting out
Posts: 10
Joined: Wed Feb 01, 2017 1:28 am

Re: [SCRIPT] autorun.sh installer

Post by ugduibill »

btw, I got the same result using these commands (taken from the other thread I linked to you )

/sbin/ubiattach -m 6 -d 2
/bin/mount -t ubifs ubi2:config /tmp/config

so I just create an autorun.sh script, make it executable, place it in that folder and unmount , and should be done?

EDIT:

I created and tested my autorun.sh, it runs manualli just fine. As soon as I reboot the NAS I'll let you know if everything is working fine
I cannot do it right now, I'm copying back all my data, it'll take several hours

thanks again for the help!
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

ugduibill wrote:btw, I got the same result using these commands (taken from the other thread I linked to you )

/sbin/ubiattach -m 6 -d 2
/bin/mount -t ubifs ubi2:config /tmp/config
Yes, that's the eventual result for your specific NAS. The rest of the script on the German forum was written to automatically determine that info. ;)
ugduibill wrote:so I just create an autorun.sh script, make it executable, place it in that folder and unmount , and should be done?
Yes, that is correct. However, each time you want to modify your autorun.sh, you need to mount (and unmount) that partition again. That's one of the differences between this solution and my solution shown in the first post for this thread. Mine does not require mounting the system device partition each time a mod is required. I'd like to integrate support for models like yours. But, I've no way to test it in those models as I don't have any available to me. So, I have to be careful with the script coding. :geek:

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
ugduibill
Starting out
Posts: 10
Joined: Wed Feb 01, 2017 1:28 am

Re: [SCRIPT] autorun.sh installer

Post by ugduibill »

ok, I can confirm it works :) thank you!

if you need help I can test your script on my system, and a couple more (4 and 6 disks)
just let me know if you need help!
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

ugduibill wrote:ok, I can confirm it works :) thank you!
:D
ugduibill wrote:if you need help I can test your script on my system, and a couple more (4 and 6 disks)
just let me know if you need help!
That would be great - I will. :geek:

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

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Looks like the wiki Admin has now updated the wiki page to include this. ;)

Unfortunately, the ubidetach parameter shown appears to be incorrect. From the script included in this thread, should be '-m', not '-p'.

And the Wiki refuses my attempted correction:
*** Forbidden. Message seems to be spam. ***
Perhaps the admin would be kind enough to correct this?

Thanks.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
schumaku
Guru
Posts: 43579
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: [SCRIPT] autorun.sh installer

Post by schumaku »

OneCD wrote:Looks like the wiki Admin has now updated the wiki page to include this.
Talked to the Wiki admin ... happened to have some invisible garbage bytes in my notepad making my test fail, too.

In your script it needs to use '-m' because $CONFIG_DEV_PART is the partition number instead of device name.

Both "-p":
# ubidetach -p /dev/mtd6
and "-m":
# ubidetach -m 6
work equivalent.
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Ah, thanks Kurt. :)

I'm hoping to get the ubifs checks integrated into my own script this weekend. All this info is very helpful.

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

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

ugduibill wrote:if you need help I can test your script on my system, and a couple more (4 and 6 disks)
Okiedoke, I've updated the script to include support for UBIFS (at least, I hope so - there's been a bit of blind-coding). Can you please download the version below and try it out? (edit: removed attached file - please see first post)

As you have possibly already created an autorun.sh file in the DOM partition, this will be copied into your default volume location where the autorun program is based. For your config, this should be [/share/CACHEDEV1_DATA/.system/autorun/autorun.sh.old]. Its copied there, because this installer will place a symlink on the DOM instead and I don't want you to lose what you've already written into it.

And to extract and run:

Code: Select all

tar -zxvf create-autorun.tar.gz && ./create-autorun.sh
If everything works correctly, you'll be able to rename and move your old autorun.sh.old into the scripts directory. :geek:

edit: temporary file no longer needed here.
Last edited by OneCD on Sat Feb 04, 2017 10:23 am, edited 1 time in total.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
schumaku
Guru
Posts: 43579
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: [SCRIPT] autorun.sh installer

Post by schumaku »

OneCD wrote:I've updated the script to include support for UBIFS (at least, I hope so - there's been a bit of blind-coding)
Here we go ... looks good to me:

[/share/Public/OneCD] # ./create-autorun.sh

---| Details |-----------------------------------------------------------------
* script version : 2017-02-04.01
* NAS model : TS-X41 (TS-231+)
* QTS version : 4.3.2 #20170104
* default volume : /share/CACHEDEV1_DATA

---| Log |---------------------------------------------------------------------
√ DOM partition found : /dev/mtd6
√ created new mount-point at : /dev/shm/create-autorun.XgHp5W
UBI device number 2, total 120 LEBs (15237120 bytes, 14.5 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
√ mounted UBIFS DOM partition at : /dev/shm/create-autorun.XgHp5W
X Unable to confirm DOM partion size
√ DOM tag-file was found : /dev/shm/create-autorun.XgHp5W/uLinux.conf
√ created script store : /share/CACHEDEV1_DATA/.system/autorun/scripts
√ created script processor : /share/CACHEDEV1_DATA/.system/autorun/autorun.sh
√ created autorun symlink to : /share/CACHEDEV1_DATA/.system/autorun/autorun.sh
√ unmounted UBIFS DOM partition : /dev/shm/create-autorun.XgHp5W

---| Result |------------------------------------------------------------------
√ Autorun successfully installed!

[/share/Public/OneCD] # ls /share/CACHEDEV1_DATA/.system/autorun/autorun.sh
/share/CACHEDEV1_DATA/.system/autorun/autorun.sh*

[/share/Public/OneCD] # more /share/CACHEDEV1_DATA/.system/autorun/autorun.sh
#!/bin/bash

AUTORUN_PATH="/share/CACHEDEV1_DATA/.system/autorun"
SCRIPT_STORE_PATH="/share/CACHEDEV1_DATA/.system/autorun/scripts"
logfile="/var/log/autorun.log"

echo "$(date) ----- running autorun.sh -----" >> "$logfile"

for i in ${SCRIPT_STORE_PATH}/* ; do
if [[ -x $i ]] ; then
echo -n "$(date)" >> "$logfile"
echo " - $i " >> "$logfile"
$i 2>&1 >> "$logfile"
fi
done

Check:

[/share/Public/OneCD] # ubiattach -m 6 -d 2
UBI device number 2, total 120 LEBs (15237120 bytes, 14.5 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
[/share/Public/OneCD] # /bin/mount -t ubifs ubi2:config /tmp/config
[/share/Public/OneCD] # ls /tmp/config/ -als
0 drwxrwxr-x 2 1000 1000 520 Feb 3 22:48 ./
0 drwxrwxrwx 21 admin administ 2300 Feb 3 22:53 ../
0 lrwxrwxrwx 1 admin administ 48 Feb 3 22:48 autorun.sh -> /share/CACHEDEV1_DATA/.system/autorun/autorun.sh*
8 -rw-r--r-- 1 admin administ 7148 Jan 20 01:42 smb.conf
4 -rw-r--r-- 1 admin administ 10 Jan 20 01:42 smb.conf.cksum
4 -rw-r--r-- 1 admin administ 37 Apr 15 2016 system.map.key
12 -rw-r--r-- 1 admin administ 9557 Jan 20 01:42 uLinux.conf
[/share/Public/OneCD] # rm /tmp/config/autorun.sh
[/share/Public/OneCD] # ls /share/CACHEDEV1_DATA/.system/autorun/autorun.sh
/share/CACHEDEV1_DATA/.system/autorun/autorun.sh*
[/share/Public/OneCD] # umount /tmp/config
[/share/Public/OneCD] # ubidetach -m 6
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

schumaku wrote:Here we go ... looks good to me:
Hey, nicely done. Some good info there. :geek:

I'll redirect that ubiattach stdout to null.

Just updating the OP now with the latest version so I'll remove the test script archive.

Thanks Kurt! :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
mundeli
New here
Posts: 7
Joined: Thu Dec 29, 2016 6:48 am

Re: [SCRIPT] autorun.sh installer

Post by mundeli »

Hey OneCD--This isn't a rabbit hole you're taking me down, is it? Are you carrying a pocket watch? Is this the red pill or the blue pill?

I just wrote my first ever bash script this week, so it was fun to look at your script. Very readable, nice.

So, anyway, my older NAS-212 must have a different file structure (hah! as if I know what I'm talking about)

Here's the output from the script.
  • [/share/Public] # tar -zxvf create-autorun.tar.gz && ./create-autorun.sh
    create-autorun.sh

    ---| Details |-------------------------------------------------------
    * script version : 2017.02.05.01
    * NAS model : TS-212 ()
    * QTS version : 4.2.2 #20161214
    * default volume : /share/MD0_DATA

    ---| Log |-----------------------------------------------------------
    √ DOM partition found : /dev/mtdblock5
    X Unable to create a DOM mount-point!

    ---| Result |--------------------------------------------------------
    X Autorun installation failed!

    [/share/Public] #
Any ideas? Thanks again so much for all your work on this. Impressive.
User avatar
OneCD
Guru
Posts: 12144
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

mundeli wrote:Hey OneCD--This isn't a rabbit hole you're taking me down, is it? Are you carrying a pocket watch? Is this the red pill or the blue pill?
;)
mundeli wrote:I just wrote my first ever bash script this week,
That's great! :geek:

I hope you stick with it. It's an investment. You'll (eventually) get back far more time due to the automation of your scripts than you'll spend writing them. Well, at least, that's the theory...

Image
mundeli wrote:So, anyway, my older NAS-212 must have a different file structure (hah! as if I know what I'm talking about)
Hmmm, that's a part I didn't think would fail... :DD

Here's the relevant code:

Code: Select all

DOM_mount_point=$(mktemp -d "/dev/shm/${SCRIPT_NAME}.XXXXXX" 2> /dev/null)

if [ "$?" -ne "0" ]; then
	ShowFailed "Unable to create a DOM mount-point!"
	exitcode=3
fi
There are a couple of things that may cause this error.

First would be that mktemp is not found. However, it's built into BusyBox:

Code: Select all

[/share] # which mktemp
/bin/mktemp
/share] # file /bin/mktemp 
/bin/mktemp: symbolic link to busybox
... and to test that it works:

Code: Select all

[/share] # mktemp -d "/dev/shm/test.XXXXXX"
/dev/shm/test.b2DQlk
[/share] # echo $?
0
Or /dev/shm is not available on your system:

Code: Select all

[/share] # ll /dev/shm
drwxrwxrwt   56 admin    administ      1.1k Feb  5 10:21 ./
drwxr-xr-x   14 admin    administ     19.7k Jan 29 17:45 ../
-rw-r--r--    1 admin    administ      2.0k Feb  5 03:33 my.crontab
-rwxrwxrwx    1 admin    administ        16 Jan 28 23:53 sem.MYTRANSOCDE_DB_SEM*
drwx------    2 admin    administ        40 Feb  5 10:18 test.b2DQlk/
Can you please check for both of those and post back?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
schumaku
Guru
Posts: 43579
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: [SCRIPT] autorun.sh installer

Post by schumaku »

Not a mktemp isssue, much more the Marvell Kirkwood NAS don't have a /dev/shm/ decive folder in place.
mundeli
New here
Posts: 7
Joined: Thu Dec 29, 2016 6:48 am

Re: [SCRIPT] autorun.sh installer

Post by mundeli »

XKCD is a little bit like Saturday Night Live--sometimes to you don't know which is more appropriate: laughing or crying

I'm not sure if you were talking about an inclusive or exclusive or in your search for causes of performance being sub-optimal

Code: Select all

[/share] # ls /dev/sh*  
ls: /dev/sh*: No such file or directory
mktemp seems to be there

Code: Select all

[/share] # which mktemp
/bin/mktemp
but it appears that my version of the OS is missing the command "file"

Code: Select all

[/share] # file /bin/mktemp 
-sh: file: command not found
[/share] # which file
[/share] # 
I worked unix 35 years ago, but the memory banks closed long ago for withdrawals. I'm now making new deposits.

Code: Select all

[/share] # uname -a
Linux NAS-212 3.4.6 #1 Wed Dec 14 10:22:56 CST 2016 armv5tel unknown
What did we do before Google, I ask you! Oh yeah, Kernighan/Pike

Nothing like mysterious OS configurations to test your assumptions.

Morpheus poses a question (45 sec duration): https://www.youtube.com/watch?v=M7W2I9FGF9U
Post Reply

Return to “Users' Corner”