noframes
Autostartmanager - Step 4

Update .xinitrc


I will write explanations as comments in the examplecode, so you can see close to each command, what it does.


autostart_save.wxbs
#!/usr/bin/wxbasicscript
include "/usr/lib/wxbasicscript/basefunctions.inc"


// -- copy file to ~/ (/home/user) , rename it to .sh

shell( "echo ~>/tmp/wxbaumhome.txt" )
homedir = trim(readfile( "/tmp/wxbaumhome.txt" ))
removefile( "/tmp/wxbaumhome.txt" )

alllines = readfiletolist( STARTDIR & "/autostart.cfg" )
writelisttofile( homedir & "/wxb-autostart.sh" , alllines )

// -- make it executable
shell( "chmod 755 ~/wxb-autostart.sh" )

// -- now test, if our configuration is already included in .xinitrc
// -- if it is, we can end this script without changing anything
// -- in this loop, we also delete the first line 

xinitrclines =  readfiletolist( homedir & "/.xinitrc" )

for i=0 to count( xinitrclines ) -1

  if xinitrclines[i] = homedir & "/wxb-autostart.sh" then
     end
  end if

next

// -- if this script is not in .xinitrc, we must add it.
// -- first, create a backup:
writelisttofile( homedir & "/.xinitrc-autostart-backup" , xinitrclines )

// -- now create a new .xinitrc with the command to run autostart.sh
// -- We can not put it in the first line, as here the script-interpreter is loaded (normally sh)
// -- so we store it in a variable, and replace the first entry in the list with autostart.sh.

theshell = xinitrclines[0]
xinitrclines[0] = homedir & "/wxb-autostart.sh"

// -- Now we can save the stored interpreterline, add finally append the rest of the list.

writestringtofile( homedir & "/.xinitrc" , theshell )

appendlisttofile( homedir & "/.xinitrc" , xinitrclines )


I made a dotpup of this example, you can download it here:
http://www.murga.org/%7Epuppy/download.php?id=894

A .tgz for other Linuxsystem you can download here: http://noforum.de/files/autostartmanager-installer.tgz.
It includes gtkdialog2, wxbasicscript, basefunctions.inc, xmessage, Xdialog and an installationscript. Size is 130 kb. Run it first as root, then as user.

Any feedback in the Puppy-Board or wxBasic-Board is welcome :)

Mark