maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [UPDATED} Quick Clip, a statusbar plugin to save text (https://talk.maemo.org/showthread.php?t=28359)

qwerty12 2009-06-03 00:28

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by BrentDC (Post 293094)
Whoa, $HOME is being interpreted as /root/ instead of /home/user/. I'm no bash expect, but something isn't right there...

I'll look into it.

$HOME` == /root because dpkg will run the package's install scripts as root.

BrentDC 2009-06-03 02:21

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by qwerty12 (Post 293156)
$HOME` == /root because dpkg will run the package's install scripts as root.

I see (although I still think it's strange it worked on some devices). What would be the correct way to get the user's home directory from a script run as root?

Thanks.

qwerty12 2009-06-03 06:55

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by BrentDC (Post 293193)
What would be the correct way to get the user's home directory from a script run as root?

Unfortunately, I'm not sure that there is one (I certainly do not know of a method of getting it cleanly anyway, perhaps someone else does?). The thing is, preinst scripts aren't really meant to install files to ~ - dpkg is, as you'll know, from Debian which can be used with multiple users (I know, doesn't sound like a feature but look at Windows 95/98/ME to understand...) and, in that world, installing files to one person's ~ isn't correct - what if a user, with a new account made after installing such a program wants use a program that relies on that method of installing files?

But, anyway, sorry for the mini-rant above (it's not intended as one! :)). I hardcode "/home/user" because this is Maemo which is ever unlikely to see apps, desktop, etc running as a different account.

I can't remember which package demonstrates this but Nokia have a way of checking for scratchbox (think it's along the lines of "if [ -e /scratchbox/tools/config ]", something like that), if that scratchbox check proves true, you may wish to do something along the lines of: "for userz in `ls /home`; do cp whatever /home/$userz; done" etc. (with the caveat that this only works for already added users, not for users that'll be added later like above).

You may just want to do "if not os.path.exists" from your python application, upon its first run, and just copy the files if not existing from that. That'll be pretty much universal as you can get the correct $HOME etc.

skatebiker 2009-06-03 07:43

Re: [UPDATED} Quick Clip, a statusbar plugin to save text
 
Code:

pocketpenguin:~# apt-get install quickclip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  quickclip
0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded.
Need to get 43.6kB of archives.
After unpacking 315kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  quickclip
Install these packages without verification [y/N]? y
Get:1 http://repository.maemo.org diablo/free quickclip 0.4.4-2 [43.6kB]
Fetched 43.6kB in 0s (60.4kB/s)
(Reading database ... 19023 files and directories currently installed.)
Unpacking quickclip (from .../quickclip_0.4.4-2_all.deb) ...
mkdir: cannot create directory '/root/MyDocs/Quick_Clip/': No such file or directory
Setting up quickclip (0.4.4-2) ...
chown: /root/MyDocs/Quick_Clip/: No such file or directory
Cache file created successfully.

still not working yet after reboot ....

BrentDC 2009-06-03 15:27

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by qwerty12 (Post 293243)
Unfortunately, I'm not sure that there is one (I certainly do not know of a method of getting it cleanly anyway, perhaps someone else does?). The thing is, preinst scripts aren't really meant to install files to ~ - dpkg is, as you'll know, from Debian which can be used with multiple users (I know, doesn't sound like a feature but look at Windows 95/98/ME to understand...) and, in that world, installing files to one person's ~ isn't correct - what if a user, with a new account made after installing such a program wants use a program that relies on that method of installing files?

But, anyway, sorry for the mini-rant above (it's not intended as one! :)). I hardcode "/home/user" because this is Maemo which is ever unlikely to see apps, desktop, etc running as a different account.

I can't remember which package demonstrates this but Nokia have a way of checking for scratchbox (think it's along the lines of "if [ -e /scratchbox/tools/config ]", something like that), if that scratchbox check proves true, you may wish to do something along the lines of: "for userz in `ls /home`; do cp whatever /home/$userz; done" etc. (with the caveat that this only works for already added users, not for users that'll be added later like above).

You may just want to do "if not os.path.exists" from your python application, upon its first run, and just copy the files if not existing from that. That'll be pretty much universal as you can get the correct $HOME etc.

Oh, please keep ranting, that was very interesting!

I already do the if not os.path.exists checks at application startup to ensure the proper files are in place, just liked using pre/post install scripts to get things running from the get-go.

I now understand this is a very sloppy way to do things, and will not try to create any user-owned directories or files during application installation.

Based on what you just said I did a bit of Googling and came across this topic at StackOverflow:

http://stackoverflow.com/questions/5...-account-linux

...and that pretty much confirms everything you've said. In addition, the poster there seemed to think using "sudo echo $HOME" would result in the correct directory being printed. This might explain why this worked fine on my device but not others (the different ways to get root? that was my initial hunch).

Thanks for the tips!

BrentDC 2009-06-03 15:27

Re: [UPDATED} Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by skatebiker (Post 293248)
Code:

pocketpenguin:~# apt-get install quickclip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  quickclip
0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded.
Need to get 43.6kB of archives.
After unpacking 315kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  quickclip
Install these packages without verification [y/N]? y
Get:1 http://repository.maemo.org diablo/free quickclip 0.4.4-2 [43.6kB]
Fetched 43.6kB in 0s (60.4kB/s)
(Reading database ... 19023 files and directories currently installed.)
Unpacking quickclip (from .../quickclip_0.4.4-2_all.deb) ...
mkdir: cannot create directory '/root/MyDocs/Quick_Clip/': No such file or directory
Setting up quickclip (0.4.4-2) ...
chown: /root/MyDocs/Quick_Clip/: No such file or directory
Cache file created successfully.

still not working yet after reboot ....

I will be updated the package soon; hang in there.

qwerty12 2009-06-03 15:51

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by BrentDC (Post 293355)
In addition, the poster there seemed to think using "sudo echo $HOME" would result in the correct directory being printed. This might explain why this worked fine on my device but not others (the different ways to get root? that was my initial hunch).

I believe this is because sudo does not inherit root's environment by default and continues to use the env. variables of the user it was invoked with.

AFAIK, the application manager uses a helper process (apt-worker) which uses sudo for its root ability and possibly does not inherit root environment variables either and runs dpkg with $HOME = /home/user - but I'm only sure on the apt-worker and sudo part, not sure about variable inheriting here. :)

BrentDC 2009-06-03 16:07

Re: [UPDATED} Quick Clip, a statusbar plugin to save text
 
1 Attachment(s)
skatebiker:

I just built a test version. Do you mind testing it out? It's attached to this post.

BrentDC 2009-06-08 22:01

Re: [UPDATED} Quick Clip, a statusbar plugin to save text
 
Hi all!

I just uploaded 0.4.4-3 to Diablo/Chinook/Fremantle extras-devel. It fixes the installation problems related to the discussion above and uses a patch by qwerty12 (to use Hildon Filechooser instead of GTK).

Test away!

P.S. The next release should have some cool new features instead of just boring bug fixes!

thp 2009-06-08 22:38

Re: [UPDATED] Quick Clip, a statusbar plugin to save text
 
Quote:

Originally Posted by qwerty12 (Post 293243)
The thing is, preinst scripts aren't really meant to install files to ~ - dpkg is, as you'll know, from Debian which can be used with multiple users (I know, doesn't sound like a feature but look at Windows 95/98/ME to understand...) and, in that world, installing files to one person's ~ isn't correct - what if a user, with a new account made after installing such a program wants use a program that relies on that method of installing files?

Here's a suggestion: The "clean" way would probably be to install any "default config" files somewhere below /usr/share/<appname>/ and then on application startup check if the files in ~ exist, and if not, copy them from /usr/share/<appname>/. This way, the package can "manage" and "upgrade" the template files in /usr/share/<appname>/ without disrupting the user's (potentially modified) config in ~. And if the files are not meant to be modified, they should go into /usr/, anyway :)

(btw: Quick Clip works great for me so far :))


All times are GMT. The time now is 14:44.

vBulletin® Version 3.8.8