1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
#!/usr/bin/perl -w
$FVWMDIR="/etc/X11/fvwm2";
#$INSTALL_FVWM="/usr/bin/install-fvwm2menu";
$CONFIGDONE="$FVWMDIR/config.done";
$UTILDIR="/usr/doc/fvwm2/utils";
$CONVPROG="convert_users";
$MENUPROG="/etc/menu-methods/fvwm2";
$UPDATE_MENUS="/usr/bin/update-menus";
$MAINMENU_HOOK="/etc/X11/fvwm2/main-menu.hook";
#$MAIN_MENU_PRE="/etc/X11/fvwm2/main-menu-pre.hook";
$WINMGRS="/etc/X11/window-managers";
#@MAINMENUPRE_TEXT=("# Same as main-menu.hook, but entries are added at the\n",
# "# very beginning of the menu.\n");
# If we have any hook files from a previous install saved by the
# preinst, then revert to them. We do this every time, but actually,
# it's only useful when upgrading from an fvwm2 with the .hook files
# in the .deb to one without them. The preinst moves the hooks to
# foo.preinst.save, and this bit of code here moves them back. This
# foils dpkg's attempt to delete them when it notices they leave the
# file list for the package.
foreach $i (glob("$FVWMDIR/*.preinst.save"))
{
$i =~ /^(.*).preinst.save$/;
$newname = $1;
rename($i, $newname) ||
warn "fvwm2 postinst: unable to rename $i to $newname: $!\n";
}
# If we are doing an upgrade, and the old version is 2.0.45-BETA-2 or
# earlier, then fvwm2 was using the old menu system, and we need to
# truncate any existing /etc/X11/fvwm2/main-menu.hook
if ($#ARGV == 1 && $ARGV[0] eq "configure" && $ARGV[1] ne "")
{
$ret = system("dpkg --compare-versions $ARGV[1] le 2.0.45-BETA-2");
$ret >>= 8;
die "error: dpkg --compare-versions returned error code $ret\n"
if ($ret != 0 && $ret != 1);
if ($ret == 0)
{
if (-s $MAINMENU_HOOK)
{
# need to re-create /etc/X11/fvwm2/main-menu.hook
unlink($MAINMENU_HOOK)
|| die "unlink($MAINMENU_HOOK) failed: $!\n";
# it will be created later in this script
}
# This section was in versions 2.0.45-2 and 2.0.45-3, which didn't
# allow main-menu-pre.hook to be used:
# check /etc/X11/fvwm2/main-menu-pre.hook to see if it's changed
# from the default
# if (-r $MAIN_MENU_PRE)
# {
# open(F, "<$MAIN_MENU_PRE") || die "open($MAIN_MENU_PRE): $!\n";
# $linenum=0;
# $same=1;
# while(<F>)
# {
# $same=0 if (!defined($MAINMENUPRE_TEXT[$linenum]) ||
# $_ ne $MAINMENUPRE_TEXT[$linenum]);
# $linenum++;
# }
# close(F);
# if ($same)
# {
# unlink($MAIN_MENU_PRE) || warn "unlink($MAIN_MENU_PRE): $!\n";
# }
# else
# {
# print <<EOT ;
#You appear to have edited $MAIN_MENU_PRE.
#Please note that this hook file is no longer read by fvwm2, so your
#edits won't have an effect. See /usr/doc/fvwm2/README.sysrc.gz for
#more details.
#
#Press return to continue
#EOT
# $_ = <STDIN>; #' <- blame emacs
# }
# }
}
}
# If the hook files don't exist yet, create them
&defContents("$FVWMDIR/init-restart.hook",
"# Similar to init.hook and restart.hook, but these additional
# commands will be added to both InitFunction and
# RestartFunction. This is usually where commands to
# start fvwm modules are placed.
");
&defContents("$FVWMDIR/init.hook",
"# Additional commands for the InitFunction, which is
# automatically executed by fvwm upon startup. This should
# contain commands to start any programs you want to always
# start, such as a welcome screen or an xterm.
#
# The lines in init.hook should be \"continuation lines\"
# for a function, such as:
#
# + \"I\" Exec xterm
#
# See the fvwm2 manual page for details (the AddToFunction
# command).
");
&defContents("$FVWMDIR/main-menu-pre.hook",
"# Same as main-menu.hook, but entries are added at the
# very beginning of the menu.
# for example:
+ \"xterm\" Exec xterm
# and the following generates a horizontal line:
+ \"\" Nop
");
&defContents("$FVWMDIR/main-menu.hook",
"# Additional entries in the main menu. These entries come
# before the mandatory \"Exit\" entry. Each line in
# main-menu.hook should be a continuation line for a
# menu definition (see the fvwm2 manual page about the
# AddToMenu command). For example:
#
# + \"XTerm\" Exec xterm
#
# Note that main-menu.hook and init.hook (et al) have a
# different, but very similar syntax.
");
&defContents("$FVWMDIR/menudefs.hook",
"# Definitions of additional menus. A user will probably want
# to put the definitions into post.hook instead, but the
# system administrator may want to use some tools to create
# the menus automatically, and it is then simpler to have
# the definitions in a separate file.
");
&defContents("$FVWMDIR/post.hook",
"# Commands to execute after all other commands in
# system.fvwm2rc. This is usually where most customization
# is put.
");
&defContents("$FVWMDIR/pre.hook",
"# Commands to execute before any commands in system.fvwm2rc.
# This is included mostly for completeness.
");
&defContents("$FVWMDIR/restart.hook",
"# Similar to init.hook, but for the RestartFunction, which is
# executed when fvwm is restarted.
");
&defContents("$FVWMDIR/.fvwm2/null.hook",
"# This hook does nothing. It is used to keep fvwm2 from complaining.
");
# Populate user directory with symlinks
chdir("$FVWMDIR/.fvwm2")
|| die "cd to $FVWMDIR/.fvwm2 failed: $!\n";
&mksym("init-restart.hook");
&mksym("init.hook");
&mksym("main-menu-pre.hook");
&mksym("main-menu.hook");
&mksym("menudefs.hook");
&mksym("post.hook");
&mksym("pre.hook");
&mksym("restart.hook");
# Create /etc/X11/window-managers with xbase's default contents if it
# doesn't already exist. This will need to change if we move to a
# scheme using install-windowmanager or update-alternatives. But for
# now, we work around the situation.
&defContents("$WINMGRS",
"# This file contains a list of available window managers. The default
# Xsession file will start the first window manager that it can
# in this list.
/usr/X11R6/bin/fvwm2
/usr/X11R6/bin/fvwm
/usr/X11R6/bin/twm
");
# now add ourselves to /etc/X11/window-managers it we're not in it already
open(F, "<$WINMGRS") || die "Couldn't open $WINMGRS for read: $!\n";
@file = <F>;
@ret = grep(m!^/usr/X11R6/bin/fvwm2$!, @file);
&addWM("fvwm2", "/usr/X11R6/bin/fvwm2") if ($#ret == -1);
# Do the stuff required for Joost's new menu world
if (-x "$UPDATE_MENUS" && -f "$MENUPROG")
{
chmod(0755, "$MENUPROG") || warn "chmod of $MENUPROG to 0755 failed: $!\n";
$ret = system("$UPDATE_MENUS");
$ret >>= 8;
warn "warning: $UPDATE_MENUS returned error code $ret\n"
if ($ret);
}
# Don't do all the old stuff anymore
# If we already have a menus.dat file, then re-create the corresponding hooks
#if (-e "$FVWMDIR/menus.dat")
#{
# $ret = system("$INSTALL_FVWM --build");
# $ret >>= 8;
# warn "warning: $INSTALL_FVWM --build returned error code $ret\n"
# if ($ret);
#}
# If we've already translated the users' ~/.fvwmrc then we're done
exit 0 if ( -f "$CONFIGDONE" );
print <<EOT ;
Fvmw2 uses a ~/.fvwm2rc configuration file rather than fvwm's
~/.fvwmrc file. The new file is in a different format; you can't just
copy your old .fvwmrc and have it work.
Included with fvwm2 is a script which will (as far as it can) generate
an ~/.fvwm2rc from a user's ~/.fvwmrc. This process doesn't remove the
original ~/.fvwmrc. The script is installed as $UTILDIR/$CONVPROG,
and can be used at any other time.
EOT
chdir("$UTILDIR") || die "cd to $UTILDIR failed: $!\n";
$ret=system("$UTILDIR/$CONVPROG");
$ret>>=8;
exit $ret if ($ret);
# Mark that we've translated the configs
open(F, ">$CONFIGDONE") || die "Couldn't open $CONFIGDONE for write: $!\n";
print F <<EOT ;
If this file is present, then the next time you upgrade fvwm2 it won't
go round translating your users' ~/.fvwmrc file. Lack of this file means
that the translation should take place. You can also translate all users
~/.fvwmrcs by running $UTILDIR/$CONVPROG.
EOT
close(F) || die "Couldn't close $CONFIGDONE: $!\n";
# Create $file with contents $txt if it doesn't exist already
sub defContents
{
local ($file, $txt) = @_;
if (! -e "$file")
{
open(F, ">$file")
|| warn "couldn't open $file for write: $!\n" && return;
print F $txt;
close(F);
}
}
# Make a symbolic link from the null hook if it's needed
sub mksym
{
local ($target) = @_;
if (-e "$target" && ! -l "$target")
{
warn "$FVWMDIR/$target isn't a symbolic link\n";
return;
}
if (! -e "$target")
{
symlink("null.hook", "$target")
|| warn "couldn't symlink $target to null.hook: $!\n";
}
}
# add the line "$full" to /etc/X11/window-managers. This assumes it's
# not already there. Prompts asking whether "$short" should be made
# the default.
sub addWM
{
local ($short, $full) = @_;
local ($reply, $incomment, $placed);
do {
print "Should I make $short the default window manager? [Y/n] ";
$reply = <STDIN>;
chop($reply);
$reply = "y" if ($reply eq "");
$reply =~ tr/A-Z/a-z/;
$reply = substr($reply, 0, 1); # only first char counts
print "Please anwser 'y' or 'n'\n"
if ($reply ne "y" && $reply ne "n");
} until ($reply eq "y" || $reply eq "n");
open(F, "<$WINMGRS") || die "Can't open $WINMGRS for read: $!\n";
open(T, ">$WINMGRS.$$") || die "Can't open $WINMGRS.$$ for write: $!\n";
$incomment = 0; # was the prev line a comment line?
$placed = 0; # have we inserted the new line yet?
line:
while(<F>)
{
# skip comments
if (/^\s*#/)
{
print T;
$incomment = 1;
next line;
}
# should we make the WM the default?
if ($incomment && ! $placed && $reply eq "y")
{
print T "$full\n";
$placed = 1;
}
# in any case, put the non-comment line through to the output
print T;
$incomment = 0;
}
# place the WM line if we've got to the end of the file without doing so
print T "$full\n" if (!$placed);
close(F) || die "Error closing $WINMGRS: $!\n";
close(T) || die "Error closing $WINMGRS.$$: $!\n";
# swizzle the new copy into place atomically
rename("$WINMGRS.$$", "$WINMGRS") ||
die "Can't rename $WINMGRS.$$ to $WINMGRS: $!\n";
}
|