You are not logged in.

#1 2012-11-26 20:43:21

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

Request for community help: profile-sync-daemon feature

Guys - I am attempting to modify profile-sync-daemon so that it parses out a user's $HOME/.mozilla/firefox/profile.ini and then syncs the corresponding profiles therein rather than simply syncing the entire $HOME/.mozilla/firefox directory.  I have taken a stab at it which you can find in the latest commit in the unstable branch on github:  https://github.com/graysky2/profile-syn … e/unstable

I'd like to ask for assistance.  As you can see, the modified version does indeed parse out each user's $HOME/.mozilla/firefox/profile.ini into an array.  What I can't seem to wrap my mind around is how to get the entire array to get passed down to the subsequent functions should it contain more than one element.  For files that contain more than one, only the last one is passed.

Input is welcomed and thanks in advance.

Last edited by graysky (2012-11-26 20:43:30)


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

Offline

#2 2012-11-27 00:58:58

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,699
Website

Re: Request for community help: profile-sync-daemon feature

I think you're reaching the point where switching to another language would save you some real headaches.

If I understand the problem, you want to do something with ENAME, BACKUP and DIR to each profile after set_which (a Python generator would be really useful here). I have a few ideas, but they feel a little kludgy. They should give you a starting point though.

a) Convert ENAME, BACKUP and DIR to arrays and populate them in set_which (e.g. ENAME[i++]=...).

b) Make set_which echo ENAME, BACKUP and DIR together on a single line with proper quoting or some custom separator, then use e.g. a "while read...; do...; done < <(set_which...)"*. With proper quoting you could extract the returned values with an array (foo=($line); ENAME="${foo[0]}"). With a custom separator,  you could use Bash substring functions to extract the different parts (e.g. ENAME="${line%%::*}" if the separator is '::' and ENAME is the first item).

c) Restructure the code to invert the loop nesting so that ENAME, BACKUP and DIR are passed to a function.


For (a) and (b), you will obviously need to add a loop after set_which wherever it is invoked to handle the values.




* see here or netcfg-menu for an example... ignore the rest of the messy code, it's inherited

Last edited by Xyne (2012-11-27 01:06:39)

Offline

#3 2012-11-27 09:27:38

alain
Member
From: France
Registered: 2012-11-16
Posts: 27

Re: Request for community help: profile-sync-daemon feature

Hi graysky,

My 2cents

(...)
    firefox)
              profileArr=( $(grep '[P,p]'ath= $homedir/.mozilla/firefox/profiles.ini|sed 's/[P,p]ath=//') )
              index=0                                                                     (ADDING index variable)
              for item in ${profileArr[@]}; do                                      (CHANGING DIR BY item)
                 if [[ $(echo $item| cut -c1) = "/" ]]; then                      (CHANGING DIR by item)
                       # path is not relative
                      DIR[index]="$item"                                              (DEFINING DIR)
                      #BACKUP="$DIR-backup"                                   (WILL BE CALCULATED when necessary)
                      #ENAME="$browser"                                          (WILL BE CALCULATED when necessary)
                 else
                      # we need to append the default path to give a fully qualified path
                      DIR[index]="$homedir/.mozilla/firefox/$item"         (CHANGING DIR by item)
                      /bin/true
                      #BACKUP="$DIR-backup"                                   (WILL BE CALCULATED when necessary)
                      #ENAME="$browser"                                          (WILL BE CALCULATED when necessary)
                fi
             index=$index+1                                                            (index incremented)
             done
             ;;

(...)

for item in ${DIR[ * ]}
do
    echo $item                                                                              (print all profiles folder, to be replaced by useful function)
done

For other browsers, DIR should be only an array of 1 item (except in case they also support profile management)

Last edited by alain (2012-11-27 09:28:43)

Offline

#4 2012-11-27 13:57:41

aesiris
Member
Registered: 2012-02-25
Posts: 94

Re: Request for community help: profile-sync-daemon feature

I suggest a different approach:

call set_which with "firefox:profilename" instead of "firefox"
then in set_which you can parse to a single dir: (broken example that assumes Path=somepath.profilename):

firefox:*)
 profilename=${browser##firefox:}
 DIR=$( sed -n 's/[P,p]ath=\(.*\.'$profilename'\)/\1/p' profile.ini )
...

and expand BROWSERS="chromium conkeror.mozdev.org firefox google-chrome" to BROWSERS="chromium conkeror.mozdev.org firefox:profile1 firefox:profile2 ... google-chrome" before running the for browser in $BROWSER loop

expandprofiles () {
 for i in $@; do
  if [[ "$i" == firefox ]]; then
   sed -n 's/[N,n]ame=/firefox:/p' profile.ini
  else
   echo $i
  fi 
 done
}

BROWSERS=$(expandprofiles $BROWSERS)

This has the bonus that your users can choose the profiles to sync in psd.conf

Offline

#5 2012-11-27 14:40:30

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

Re: Request for community help: profile-sync-daemon feature

@Alain and aesiris -

I think I wrapped my mind around alain's approach, and updated the unstable branch with a working copy (although not tested yet).

I don't want to make configuration in /etc/psd.conf complicated; I want the script to be just blindly parse the user's dirs and sync if they are present.  Otherwise, I can see adding extra variables for user-level profiles confusing for users.

I need to play around a bit more mentally with your suggestion,  aesiris.  If you wanna fork the stable branch and send me a pull request, that would be cool wink


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

Offline

#6 2012-11-27 17:27:22

aesiris
Member
Registered: 2012-02-25
Posts: 94

Re: Request for community help: profile-sync-daemon feature

I took a look at the unstable branch
You are still linking "$VOLATILE/$user-$browser" to "$DIR"
This now is wrong because you want multiple DIR when $browser=firefox

You need something like "$VOLATILE/$user-$browser-$item"
But not exactly since $item contains '/' characters, that you can't use as filenames.
Maybe "$VOLATILE/$user-$browser-${item##*/}" is a good solution?

EDIT:
This is my attempt: github.com/aesiris/profile-sync-daemon

Last edited by aesiris (2012-11-27 19:02:02)

Offline

#7 2012-11-27 21:24:55

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

Re: Request for community help: profile-sync-daemon feature

Thanks for the help and suggestions, all.

@aesiris - I checked out your code but found that it did not handle multiple profiles correctly.  I didn't spend too much time on it since I already invested in the array solution proposed by alain.

I just now pushed a healthy beta to the unstable branch based on your both of your suggestions (from this thread and from private email).  I have ALL supported browsers installed on my workstation and have been testing for the past 1/2 hour.  I do not see any problems.  I need a break hmm

Anyway, please test it, bang away on it, let me know what is wrong.

Note - STOP YOUR EXISTING psd FIRST.
1) sudo systemctl stop psd.service
2) Copy the unstable code from github to your /usr/bin and `sudo chmod +x /usr/bin/profile-sync-daemon`
3) Start the daemon again

EDIT:

% profile-sync-daemon debug
::DEBUG MODE::
profile-sync-daemon version: 5.01

settings in /etc/psd.conf will make profile-sync-daemon manage the following browers/user combos when invoked:

browser:psname  chromium:chromium
owner/group:    facade:users
sync target:    /home/facade/.config/chromium
backup target:  /home/facade/.config/chromium-backup
tmpfs dir:      /tmp/facade-chromium

browser:psname  conkeror.mozdev.org:xulrunner
owner/group:    facade:users
sync target:    /home/facade/.conkeror.mozdev.org
backup target:  /home/facade/.conkeror.mozdev.org-backup
tmpfs dir:      /tmp/facade-conkeror.mozdev.org

browser:psname  firefox:firefox
owner/group:    facade:users
sync target:    /home/facade/.mozilla/firefox/zzvngsqc.default
backup target:  /home/facade/.mozilla/firefox/zzvngsqc.default-backup
tmpfs dir:      /tmp/facade-firefox-zzvngsqc.default

browser:psname  firefox:firefox
owner/group:    facade:users
sync target:    /mnt/profiles/djj43fbr.943
backup target:  /mnt/profiles/djj43fbr.943-backup
tmpfs dir:      /tmp/facade-firefox-djj43fbr.943

browser:psname  google-chrome:chrome
owner/group:    facade:users
sync target:    /home/facade/.config/google-chrome
backup target:  /home/facade/.config/google-chrome-backup
tmpfs dir:      /tmp/facade-google-chrome

browser:psname  heftig-aurora:aurora
owner/group:    facade:users
sync target:    /home/facade/.mozilla/aurora/imxbinbc.default
backup target:  /home/facade/.mozilla/aurora/imxbinbc.default-backup
tmpfs dir:      /tmp/facade-heftig-aurora-imxbinbc.default

browser:psname  heftig-aurora:aurora
owner/group:    facade:users
sync target:    /mnt/profiles/poza1kl4.dv2
backup target:  /mnt/profiles/poza1kl4.dv2-backup
tmpfs dir:      /tmp/facade-heftig-aurora-poza1kl4.dv2

browser:psname  midori:midori
owner/group:    facade:users
sync target:    /home/facade/.config/midori
backup target:  /home/facade/.config/midori-backup
tmpfs dir:      /tmp/facade-midori

browser:psname  opera:opera
owner/group:    facade:users
sync target:    /home/facade/.opera
backup target:  /home/facade/.opera-backup
tmpfs dir:      /tmp/facade-opera

browser:psname  opera-next:opera-next
owner/group:    facade:users
sync target:    /home/facade/.opera-next
backup target:  /home/facade/.opera-next-backup
tmpfs dir:      /tmp/facade-opera-next

browser:psname  qupzilla:qupzilla
owner/group:    facade:users
sync target:    /home/facade/.qupzilla
backup target:  /home/facade/.qupzilla-backup
tmpfs dir:      /tmp/facade-qupzilla

Last edited by graysky (2012-11-27 21:28:05)


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

Offline

Board footer

Powered by FluxBB