Thorsten Glaser: synchronise environment between two shells
(First posting to Pl net Commandline! Tag: pcli)
Vutral asked in IRC how to synchronise two shells environment
while they re running. As you may know, POSIX systems cannot change
a process environment vector after it has been started, only the
process itself can. Well, the shell
can, and we ll use a variety of things for this.
This trick assumes you have $HISTFILE set to the same
pathname in both shells (obviously, they run under the same user).
It uses export -p to render the current list of exported
variables, then transforms the list from newline-separated to a
single big one-line export statement.Then it transforms all remaining newlines (which will be part of a single-quoted string, since that s mksh(1) s export format) into the sequence '$'\n'' which means: terminate current single-quoted string, append $'\n' and open up a new single-quoted string immediately; concatenate these three.
Now, $'\n' is just a fancy way of saying newline, and part of mksh because David Korn (yes, the Korn in Korn Shell) strongly suggested to me that this functionality be included but, as we can see here, it pays off.
Finally, the so transformed string is prepended by unset \$(export); which, when executed, will cause the shell to unset (and unexport) all currently exported variables. The shell parameters that are not exported, i.e. not in the environment, are not affected by this code (except for $x and $nl, but whatever).
This string is then passed to read -s (plus -r and clearing IFS to enable raw mode), which means, read into the parameter $REPLY (which we conveniently don t use but it s trashed too, thus) but store into history at the same time. Ah hah! Now, the persistent history feature comes into effect! After running the below statement in the source shell, switch into the terminal running the destination shell, press Enter once on the empty line (Ctrl-U to empty it if it wasn t), then Cursor-Up ( ) to recall voil , an insanely large line with the previously created string sorta expanded and press Enter again to run it. Now your set of exported parameters is the exact same (minus if you exported IFS, nl, x or REPLY) as in the source shell.
I ve added extra spaces and a linewrap below, this is really just one big line:
nl=$'\n'; x=$(export -p); x=$ x//$ nl export/ ;
IFS= read -rs <<<"unset \\\$(export);$ x//$nl/\'\$\'\\\\n\'\' "
Of course, this makes a nice function, for your ~/.mkshrc or somesuch.

Wonderful concert on Friday evening at
As I write this, it's the morning of June 5th, 1981. A few people scattered
across the US are waking up, going in to work, sitting down at their terminal
with a coffee, and reading Usenet. Usenet is only getting a trickle of posts
each day -- it's still in that period where it's easy to read every message
posted to it.
Many things lie in Usenet's future. It's still running
My last update about running activities is dated back to Paris
Marathon (April 10th). Time for a new update, then.
After a very busy end March-early April, with that crazy succession of
55km Ecotrail and 42km Paris marathon with only two weeks between both, I
needed a kind of "break".
Moreover, I had another goal set with the 35m trail race named "Trail
des Cerfs", on May 15th, in my neighbourhood.
So, end of April was a little bit quieter. Still, one week after
Paris marathon, I completed a very hard trail run in Seine Valley:
only 18km, but about 600-700m positive slope. That was indeed a good
moutain-style run (yes,
Hello, this is the official project report for the Debian GSoC admins and everyone. It s been few days since the official coding phase started. Most of the time I ve been figuring out the details regarding integration of non-x86 images to the Eucalyptus IaaS and working on the ARM image, as you ll learn later. I m also in the process of starting to design the set of tools we ll be delivering as part of the project.
The project s goal is to be a useful resource for Debian developers and porters. I ve joined some porters list in order to learn what are the things they are struggling with and how the project can help to address them. I ll be starting a wiki page with such topics.
Bonding period:
DECLARATIVE DIVERSIONS
======================
Introduction
A diversion is when it is possible to have dpkg not overwrite a file when it
reinstalls the package it belongs to, and to have it put the file from the
package somewhere else instead.
Declarative diversions involves a new control file with a declarative
syntax which dpkg will parse and process directly as part of the package unpack
and removal phases, eliminating the problems resulting from non-atomic
handling of diversions.
Topics
There are a number of topics involved in implementing this kind of project
* What syntax do we use for the new control file?
* What dpkg does with the control file
* How do we handle diversions to a non-existant directory?
* How do we order unpacking a new package which adds a diversion?
* How do we order unpacking a new package that removes a diversion?
* How do we order removing a package which had a diversion?
* How do we handle errors?
* What happens to dpkg-divert?
-
Details - Control File Syntax
-
It will conform to RFC2822 style with the following format:
* Divert-From:
* Divert-To:
* Blank lines and lines beginning with # will be comments
Divert-To will be optional and if it is ommitted then files being diverted
will have their filename changed to file.distrib
The above style has it s advantages, one of the main ones being that there is
no need to escape whitespace within filenames.
-
Details - Control File Handling
-
Within control.tar.gz the file should be named diversions
This file is then copied to /var/lib/info/$package.diversions
This is ensuring we have a copy of the control file just in case it is needed.
Any input on this subject would be appreciated.
-
Details - Handling Diversions to non-existant directories
-
Diverting files to directories that don t exist can cause a number of problems.
If the package does not own the directory it may be left orphaned on
removal of the package
The package is responsible for ensuring the availability of the target directory in the unpack phase.
-
Details - Ordering Requirements
-
=>Unpacking a new package that adds a diversion
*1. Unpack folders
*2. Add diversions
*3. Unpack files
==Notes==
Performing diversions this way avoids trouble with creating folders and
accidentally overwrtiting the wrong version of files.
If we don t use this method the problems that can occur include creating
folders before the package itself would create them which may cause
permission errors.
Another major problem would be extracting a new version of the file and
overwriting the old one.
This might cause the wrong version of the file to be diverted and the
package to break.
=>Unpacking a new package that removes a diversion
*1. Unpack folders
*2. Add diversions
*3. Unpack files
==Notes==
=>Removing a package which had a diversion
*1. Remove files
*2. Remove diversions
*3. Remove folders
==Notes==
This ensures that all files, diversions and folders are removed correctly
Details - Error handling
Errors in diversions will have to handled with a great deal of care due to
the fact that if they are not the package could be broken.
This means that a great deal of checks must be done to ensure that all the files
can be diverted properly before any actual diverting takes place. If they can t
the package installation/update must be stopped and rolled back to avoid the
package being installed incorrectly or broken.
-
Details - dpkg-divert
-
When we impliment the new diversion method we should keep the current
dpkg-divert. This allows maintainers to catch up with the new method without
breaking their packages. It also allows maintainers to perform some operations
that aren t support by the new method.
Example Usage #1
The file to be diverted is /usr/share/foo
It needs to be moved to /usr/share/bar
The syntax of the control file would be:
#Start File
Divert-From: /usr/share/foo
Divert-To: /usr/share/bar
#End File
Example Usage #2
In this example the maintainer doesn t want to move the file to any specific
folder
The syntax of the control file would be:
#Start File
Divert-From: /usr/share/foo
#End File
This would divert the file to /usr/share/foo.distrib
-
Footnotes
-
RFC2822 Guide:
* 

When I installed my
The BitTorrent protocol works with trackers, that track the
clients or peers that share a given file. This is one
specific design of a peer-to-peer protocol, very appropriate for official
distribution: for instance, Debian runs a tracker for distributing the
installation images.The problem
There exists many BitTorrent clients, but, for what I have seen, few
BitTorrent tracker. Within Debian, I think the only trackers available are the
original BitTorrent's one, and its fork BitTornado. Both suffer from serious
drawbacks:
You'd think it'd be easy to reboot a PC, wouldn't you? But then you'd also think that it'd be straightforward to convince people that at least making some effort to be nice to each other would be a mutually beneficial proposal, and look how well that's worked for us.
I m proud to be able to announce a new stable release of
At April 30, I took over maintenance of of
I've got a few projects which are hosted in mercurial repositories. To deploy them I manually checkout the repository, create symlinks by hand, then update