LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-13-2004, 12:37 PM   #1
SheldonPlankton
Member
 
Registered: Jun 2004
Posts: 129

Rep: Reputation: 15
How do I write a make install Makefile that determines if user is root?


Hi,

I am having trouble writing a Makefile that can determine what command to run based on who the user is.

Code:
bash-2.05b$ cat Makefile
NOTES_INSTALL_DIR = /tmp
install:
        runner=`whoami` ; \
        if test $$runner != "root" ; \
        then \
                echo "You are not root. Have password ready"; \
                su -c "cp index.html bookmarks.html notes.css ${NOTES_INSTALL_DIR}"; \
        else \
                echo "You are root" ; \
                cp index.html bookmarks.html notes.css ${NOTES_INSTALL_DIR}"; \
        fi
bash-2.05b$ make install
runner=`whoami` ; \
if test $runner != "root" ; \
then \
        echo "You are not root. Have password ready"; \
        su -c "cp index.html bookmarks.html notes.css /tmp"; \
else \
        echo "You are root" ; \
        cp index.html bookmarks.html notes.css /tmp"; \
fi
/bin/sh: -c: line 1: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 2: syntax error: unexpected end of file
make: *** [install] Error 2
bash-2.05b$

Should that work ?

Last edited by SheldonPlankton; 08-13-2004 at 12:40 PM.
 
Old 08-13-2004, 04:32 PM   #2
DanTheKiwi
LQ Newbie
 
Registered: Aug 2004
Location: Sydney, Australia
Distribution: FreeBSD, Fedora Core 2
Posts: 20

Rep: Reputation: 0
Lightbulb

I believe the problem is that little quote mark hidden after the word '/tmp', it's trying to match it to another one, but you only have one.

Hope that helps.
 
Old 08-13-2004, 04:44 PM   #3
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Rep: Reputation: 45
Quote:
Originally posted by DanTheKiwi
I believe the problem is that little quote mark hidden after the word '/tmp', it's trying to match it to another one, but you only have one.

Hope that helps.
Yeh, that's what I looks like to me also. When I first read the thread title I was thinking something like
Code:
ls /root && <rootcommand>
else
su 
<rootcommand>
But your way also works.
 
Old 08-13-2004, 05:39 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
/sigh...

Come on Sheldon, you got an answer (the same I might add) in your first two posts of this problem. One by me, here:
http://www.linuxquestions.org/questi...hreadid=217247

And the other by vasudevadas here:
http://www.linuxquestions.org/questi...hreadid=217246

I copied the text for your makefile, fixed the quotation problem, and it worked fine. I don't understand why you continue to post the question when it has been answered twice.

Code:
cp index.html bookmarks.html notes.css ${NOTES_INSTALL_DIR}"; \
needs to be changed to

Code:
cp index.html bookmarks.html notes.css "${NOTES_INSTALL_DIR}"; \
I don't know how else to say it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware 10.0 Samba: root can write, user cannot bhicks Slackware 15 11-18-2004 11:46 PM
Cannot write to SMB share as user, can as root GT_Onizuka Linux - Networking 3 10-03-2004 06:52 PM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM
How do I make a user equal to root ? joncolby Mandriva 3 02-27-2004 02:54 PM
Need To Make a User for myself, besides Root Scarface Linux - Newbie 2 10-26-2003 05:24 PM


All times are GMT -5. The time now is 07:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration