chown in script issue
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

my brain is not working too well.

I have a script that downloads a file and then next command works ok...inside that script

:: Code ::

chmod +x unpack.sh

but then as a local user I want to make it root owned so I tried

:: Code ::

chown root:root unpack.sh

but it is not working for me.


Any help will be appreciated.

2) I can always ask the user to open a root shell and do it by command but I am trying to reduce the commands they issue to 3 scripts....a download script....an unpack script and a repack script.

the download script they need to manually download and it downloads the other scripts and other files.

regards

gordy

< Edited by aus9 :: Mar 12, 10, 18:23 >

Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
local user can't make the file root owned, root is larger than local user, and local user is a subset of root.

When I want to make a file root owned, this is how I do it:

when I create the file, locally: chown root:root filename
then: zip filename.zip (zip file name) [list of files to zip: filename]

example:
chown root:root unpack.sh
zip unpack.zip unpack.sh

Then user downloads unpack.zip, unzips it:
unzip unpack.zip
and there is root owned unpack.sh
Back to top
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

EDIT
thanks will do....and the zip will work nicely as the last 2 scripts will be root owned.

Now that I am going to be smarter and use a zip....all non-Tinycore binaries and iso will now be in the zip.

The unzipped download.sh will then be used to download:
the tinycore iso and some tinycore binaries.

I will now append to my grub2 random thoughts

thanks heaps
Back to top
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

OK getting around to small test of root powers for zip.

only used 3 files for this test

:: Code ::

su
chown root:root script2.sh script3.sh
chmod 700 script2.sh script3.sh

 zip test.zip script*
  adding: script1.sh (deflated 76%)
  adding: script2.sh (deflated 60%)
  adding: script3.sh (deflated 48%)
  adding: test.zip (stored 0%)


so far so good....3 files in zip

file manager shows zip is owned by root

2) copy zip file to another folder and unzip it

:: Code ::

su gordy
mkdir test/
cp test.zip test
cd test/
unzip test.zip
ls -al

-rwxr--r--  1 gordy gordy 3241 Mar 21 19:46 script1.sh
-rwx------  1 gordy gordy 3643 Mar 22 08:41 script2.sh
-rwx------  1 gordy gordy 1071 Mar 21 19:37 script3.sh

-rw-r--r--  1 gordy gordy 6646 Mar 22 16:54 test.zip



I did this twice actually as I did not watch my output close enough and wanted to be sure
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
looks like you're right, I faintly remember that this used to preserve file ownership, but it doesn't seem to be doing that now.
Back to top
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

no worries...I have taken some stuff and modded it from a script from Slitaz...GPL2

so that start of those scripts are

# before anything test we are root

if test $(id -u) != 0 ;
then echo "you need to be root"
exit 0
fi


eg
:: Code ::

gordy@sid:~$ ./script2.sh
you need to be root
gordy@sid:~$

Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
oh, you just wanted to check for root? you should have asked me, of course, that's a trivial test, all the xi scripts check for root for various reasons, I was wondering why you were wanting root ownership but didn't really give it much thought.

:: Code ::
if [ "$(whoami)" != "root" ];then
   error_handler 'not-root' $FUNCNAME
fi

Back to top
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

1) could not get your thing to work as I have not defined it so modded it to

:: Code ::

if test $(whoami) != 0 ;
then echo "you need to be root"
exit 0
fi


2) No sorry....back to square one....I needed zip to maintain root permissions but it does not.

So now.....I need a test for scripts 2 & 3 because they need to be run as root.

So I now modded script1 to tell the USER to make them root...in a echo in case they can't read my simple scripts

3) Anything too technical goes over my head as I am still not a script guy but greatly appreciate your efforts


PS if I seem a little abrupt its because I have to find a new file sharing free site....stashbox seems to baulk at my over 40 meg upload of my iso.

grrrrr

No I am not going to pay money.
No I am not going to Mediafire who blast users with so many freaking ads the user is likely to leave pronto.

If anyone cares to suggest a good site for iso uploads feel free to suggest please

regards
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
:: Code ::
if [ "$(whoami)" != "root" ];then
   echo "you need to be root"
   exit 0
fi

I hate those test... statements, and refuse to use them, along with many other horrible bashisms, they are non-standard programming syntax and almost impossible to read or debug.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours