You are not logged in.

#1 2012-10-28 17:26:46

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Sed to fix a file on install - a violation of the Arch Way [SOLVED]

I have a variable in my software that I have redefined for various reasons.  This variable COULD reside in /etc/foo.conf which users MAY have edited to their liking and resides on their file systems if they are running an older version of my package.

Would me grepping /etc/foo.conf in the pre_upgrade function and auto correcting the outdated variable via a sed oneliner violate the Arch Way?  Should I just detect this condition and force the user to make the change via a warning message?

Thanks for the input.

Last edited by graysky (2012-10-28 21:26:23)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2012-10-28 17:38:59

ZekeSulastin
Member
Registered: 2010-09-20
Posts: 266

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Pretty much every actual arch package drops a pacnew as required (as per the logic in man pacman).  If it were me, at most I'd make a note of it in a post_upgrade echo.

Offline

#3 2012-10-28 18:04:40

Awebb
Member
Registered: 2010-05-06
Posts: 4,437

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

I agree with ZekeSulastin. I would want a foo.conf.pacnew and a post install note.  A package fiddling with an existing file in /etc would be highly uncomfortable, as I manually track the changes.

Offline

#4 2012-10-28 18:27:47

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Thanks for the opinions.  I also have to force the daemon to stop running before the upgrade or else data loss will ensue.  I figured "since I am stopping the service, might as well sed the old-->new while I'm at it as well."


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2012-10-28 18:38:58

Awebb
Member
Registered: 2010-05-06
Posts: 4,437

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Stopping a daemon automatically is also unexpected behavior. I hope that daemon does not do anything critical.

Offline

#6 2012-10-28 18:56:34

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Here is the situation: profile-sync-daemon v3.16 is the current release.  I need to change a core variable's value in the code which I am doing in git now.  The old value is "mozilla" and the new is "firefox."  Once I formally release the next version.  One key thing MUST happen to ensure no data loss:

1) Psd on the system MUST stop running before the new /usr/bin/profile-sync-daemon is rotated into place by pacman.

In stopping the daemon, the profile is sync'ed back to physical disk and the upgrade can occur. 

To start the daemon again and get the expected behavior:

2) The user needs to edit the BROWSERS array in /etc/psd.conf and change "mozilla" to "firefox" only if the user has uncommented the BROWSERS array which is optional.

I can leave part 2 to the user since NOT doing it will not hurt anything, but I feel that I MUST stop the deamon in a pre_upgrade function or else the user risks losing his/her firefox profile... and we all know that many do NOT maintain backups wink

So now that you know the whole story... what is your collective advice?

Last edited by graysky (2012-10-28 18:57:48)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2012-10-28 19:15:35

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,025
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

One option may be to have a pre-install abort if the daemon is running with a message to the user that it must be stopped before psd can be safely updated.

The disadvantage is that it would abort an update which might lead to mild annoyance.  The advantage is that it leaves control (and thus responsibility for the outcome) completely in the hands of the user.  This advantage far outweighs the disadvantage in my estimation.

But take that with a large grain of salt as I don't use psd so I would not be affected by this either way.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#8 2012-10-28 19:20:45

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

@Trilby - I like that suggestion a lot!  I have logic in place via the pre_update function in readme.install that can determine:

1) If the user is affected at all (not all users make use of the BROWSERS array in /etc/psd.conf to begin with and are therefor unaffected).
2) If the pseudo-daemon is in a "run" state.

What is the proper way to abort the installation?  Here is the logic I spoke of:

DAEMON_FILE="/run/psd"

pre_upgrade() {
  newpkgver=${1%-*}

  if [ $newpkgver > 4.00 ]; then
    # check to see if user is affected by change in v4

    if [ -n $(grep ^BROWSERS /etc/psd.conf | grep mozilla) ]; then
      echo '------------------------------------------------------------------------'
      echo ' WARNING:'
      echo
      echo 'Usage of the "mozilla" variable in the BROWSERS array in /etc/psd.conf'
      echo 'is now depreciated!'
      echo
      echo 'You must manually change it to "firefox" starting with v4.x of psd.'
      echo 

      # further check to see if user is running psd and needs to manually fix
      if [ -e $DAEMON_FILE ]; then
        echo
        echo 'I have detected that you are currently running psd.'
        echo
        echo 'In order to safely upgrade, you must do two things:'
        echo '1) Exit your browser(s)'
        echo '2) Manually stop psd now.'
        echo
        echo 'Pacman will be aborted now. Please do 1 then 2 and retry.'

        <<< INSERT SOME CODE TO KILL PACMAN'S UPDATE OF PSD >>>

      fi
      echo '------------------------------------------------------------------------'
    fi
  fi
}

P.S.  Why don't you run psd smile

Last edited by graysky (2012-10-28 19:34:55)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#9 2012-10-28 19:38:38

Awebb
Member
Registered: 2010-05-06
Posts: 4,437

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

There is no proper way of aborting an installation. If the package is built, then pacman will install it, no exeption acceptable. Don't get me wrong: I'm not trying to sabotage your effort, I'm only being as critical as possible and simulate the worst case user complaints. I would personally rather have the package sync, stop, update and restart than aborting a pacman operation, because the package thinks it might be a good idea. You know, the package has absolutely no say in what happens. It's like a piece of bread deciding, that you are fat enough already, skipping your entire meal. Imagine that package in [community], that would be a memorable moment, here on the Arch forums. :-)

EDIT: A little OT: Why not use psd? I still have mixed feelings. On the one hand, it boosts the browser performance and start-up time trendemously. On the other hand, it slows down the system boot, as it seems to delay the start of X until the profiles are in the tmpfs. Data loss is also a possibility, although I use Chromium with my google account, so there is no data to be lost and the daemon runs quite well, so chances are low. Another candidate for psd would be my netbook, but it would not like a delayed login, has "only" 2GB of RAM and a fast SSD. However, you got me now, I will re-activate the service. It must be those red, shiny eyes. :-D

EDIT2: Forget what I said about boot time. It adds 2 seconds on my netbook, so now it needs 6s insted of 4s. That is not really relevant.

EDIT3: And three seconds on the desktop, both with chromium only. I used to have delays like 10-15s in the past. Must have been a different problem. Or maybe I was unwise enough to use asd for browser stuff…

Last edited by Awebb (2012-10-28 20:15:10)

Offline

#10 2012-10-28 19:39:42

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,025
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

graysky wrote:

What is the proper way to abort the installation?

I've never tested it, but I believe a nonzero exit (eg "exit 1") would do it.

graysky wrote:

P.S.  Why don't you run psd smile

I've heard nothing but good things - and I've thought about checking it out, but I don't know that it would apply as I don't use any of the "big" browsers.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#11 2012-10-28 19:41:25

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,025
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Awebb wrote:

There is no proper way of aborting an installation. If the package is built...

I know it can be aborted at in the build function - this is an AUR package right?


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#12 2012-10-28 19:45:25

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Trilby wrote:
Awebb wrote:

There is no proper way of aborting an installation. If the package is built...

I know it can be aborted at in the build function - this is an AUR package right?

Yes.  I don't want the logic check to be applied at build time since some users might maintain their own local repos; the check and killing will need to happen on installation.  I checked and adding a `exit 1` to the code I pasted above does not stop the installation.  Where are you Allan smile

Last edited by graysky (2012-10-28 19:45:54)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#13 2012-10-28 20:28:21

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,095
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Aborting pacman mid installation is among the worst things you can do. This functionality does not exist, and will never exist.

Last edited by falconindy (2012-10-28 20:28:38)

Offline

#14 2012-10-28 20:32:41

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

falconindy wrote:

Aborting pacman mid installation is among the worst things you can do. This functionality does not exist, and will never exist.

OK... What would you recommend in this case, Dave?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#15 2012-10-28 20:36:01

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 5,377

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

Would it not be best to support both variables for a release or two, warning users that they need to change the old variable asap, or face losing their entire profile during a later update?  If the users fail to heed the notice, then it's their own fault.


Sakura:-
Mobo: ASUS P8Z77-V PRO // Processor: Intel Core i7-3770K 3.4GHz // GFX: nVidia GeForce GTX 970 Ti // RAM: 32GB (4x 8GB) Corsair DDR3 (@ 2133MHz) // Storage: 1x 3TB Seagate SATAII 5x 1TB Samsung SATAII, 2x 120GB Corsair SSD

Offline

#16 2012-10-28 20:37:19

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,095
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

graysky wrote:
falconindy wrote:

Aborting pacman mid installation is among the worst things you can do. This functionality does not exist, and will never exist.

OK... What would you recommend in this case, Dave?

Frankly, I've never been a fan of the idea of these silly sync daemons from the start. I suggest not breaking it in such a way that you necessarily lose data if its updated while running.

Offline

#17 2012-10-28 20:49:16

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,611
Website

Re: Sed to fix a file on install - a violation of the Arch Way [SOLVED]

@WorMzy - Yes, this would be optimal but the location that the new browser uses is a subset of the old location.
@Falconindy - OK.  In that case I believe the only option is for the pre_update function to stop the daemon and inform the user.

Something like:

pre_upgrade() {
  DAEMON_FILE="/run/psd"
  newpkgver=${1%-*}

  if [ $newpkgver > 4.00 ]; then
    if [ -n $(grep ^BROWSERS /etc/psd.conf | grep mozilla) ]; then
      echo '------------------------------------------------------------------------'
      echo ' WARNING:'
      echo
      echo 'Usage of the "mozilla" variable in the BROWSERS array in /etc/psd.conf'
      echo 'is now depreciated!'
      echo
      echo 'You must manually change it to "firefox" starting with v4.x of psd.'
      echo
      echo '                   "mozilla" --> "firefox" '

      if [ -e $DAEMON_FILE ]; then
        echo
        echo 'In order to safely upgrade, psd will be stopped for you now.'
        echo 'Exit your browser(s) now.'

        if ! systemd-notify --booted; then # not using systemd
          /etc/rc.d/psd stop
        else
          /usr/bin/systemctl stop psd.service
        fi
      fi

      echo '------------------------------------------------------------------------'
    fi
  fi
}

Last edited by graysky (2012-10-28 20:49:52)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB