LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Inserting a block of text into a text file on system boot (https://www.linuxquestions.org/questions/linux-newbie-8/inserting-a-block-of-text-into-a-text-file-on-system-boot-926584/)

krptodr 01-30-2012 04:23 PM

Inserting a block of text into a text file on system boot
 
Ok what I want to do is set the program xscreensaver settings upon loading linux.

Problem is this has to be done through a shell script and I am mainly a windows user.

Can anyone help me figure out how to do this in linux? can I simply put quotes around the entire block of text with \n at the end of each line?

This wouldn't be ideal so I hope there is an easier way.

Please let me know.

ShadowCat8 01-30-2012 05:39 PM

Well,

There are a couple of questions that I would have in regards to this:
  1. You want this to be global settings for xscreensaver for the system?
  2. Are you using a login manager (gdm or xdm) on the linux box?
  3. Is there anything in the config/settings that you are trying to insert that is dynamic? (e.g. different behaviors by time, who logs in, etc.)
  4. If it's meant to be a global system setting, how about just adding the necessary configuration to /etc/profile?

Now, the reason for these questions is because the way that xscreensaver works, the configuration for how xscreensaver will run will be stored in the user's home directory in a file called .xscreensaver. If you want a default configuration for each new user created on the system, you can add an .xscreensaver config file to /etc/skel/ so that each new user created will have the default config in their home directory. You can add the starting configuration to the /etc/profile file as I suggested above, but if the user has his own config file, I am pretty sure it will override any "global" settings for their session when they log in.

Now, if you want this to be the configuration for how xscreensaver will run when no one is logged in, then you can try adding the settings/command to the /usr/lib/X11/<display manager sub-directory>/Xsetup_0 file. I have had mixed results doing this with xdm. On some systems it works well, others it never starts xscreensaver. (Pretty sure that has to do with an issue regarding running the *dm as root and the system not wanting to run xscreensaver as root.)

So, I hope that helps and let us know.

krptodr 01-30-2012 06:08 PM

Quote:

Originally Posted by ShadowCat8 (Post 4588743)
Well,

There are a couple of questions that I would have in regards to this:
  1. You want this to be global settings for xscreensaver for the system?
  2. Are you using a login manager (gdm or xdm) on the linux box?
  3. Is there anything in the config/settings that you are trying to insert that is dynamic? (e.g. different behaviors by time, who logs in, etc.)
  4. If it's meant to be a global system setting, how about just adding the necessary configuration to /etc/profile?

1. Global settings would be fine.

2. I am using kdm and KDE4.

3. The information will be static, so one config file globally.

4. I wish to be able to do that, however I can't. I want to load it upon system booting, outside of the Xserver. I am currently using SuseStudio to build my machine. I want those settings to be set statically upon each "Testdrive" of my build. Check out www.susestudio.com to find out more on that.

ShadowCat8 02-01-2012 01:41 AM

Okay,

Actually, I am a little familiar with SuSEStudio. SuSE has had great booths at the last 2 SCaLE expos. :) They set up SuSEStudio kiosks. Just out of curiosity, are you making this a cloud appliance, USB stick, VM or live cd/dvd?

Okay, what you are going to want to do to start with is this:
  1. Log in as a user and run the xscreensaver-demo command.
  2. Set up xscreensaver the way you want it to run as a global default. Remember to set up the Advanced tab options like Image and Text Manipulation settings to something that will always work.
  3. Close the program and take a copy of the ~/.xscreensaver file.

Now, to make sure it's the default for any user that's created, you want to put a copy in /etc/skel/. On the OpenSuSE appliance, add it as an overlay file from the Files tab.

I hate to say it, but a startup script won't really work with what you are trying to do because you have to rely on the X server to start before you have a display for the xscreensaver daemon to bind to. Fortunately, the different desktops (I use Gnome.) each have their ways of setting their defaults, as does kdm, gdm and xdm. Now, from the xscreensaver docs:
Code:

USING KDE
      KDE  also has invented their own screen saver framework instead of sim-
      ply using xscreensaver.  To replace the KDE screen saver with  xscreen-
      saver, do the following:

          1: Turn off KDE's screen saver.
              Open the ``Control Center'' and select the ``Appearance & Themes
              / Screensaver'' page.  Un-check ``Start Automatically''.

          2: Find your Autostart directory.
              Open the ``System Administration -> Paths'' page, and  see  what
              your  ``Autostart  path''  is  set  to:  it  will  probably  be
              ~/.kde/Autostart/ or something similar.

          3: Make xscreensaver be an Autostart program.
              Create a  .desktop  file  in  your  autostart  directory  called
              xscreensaver.desktop that contains the following five lines:
              [Desktop Entry]
              Exec=xscreensaver
              Name=XScreenSaver
              Type=Application
              X-KDE-StartupNotify=false

          4: Make the various "lock session" buttons call xscreensaver.
              Replace  the file kdesktop_lock or krunner_lock or kscreenlocker
              in /usr/bin/ (or possibly in /usr/kde/3.5/bin/  or  possibly  in
              /usr/lib/kde4/libexec/  or  /usr/libexec/kde4/, depending on the
              distro and phase of the moon) with these two lines:
              #!/bin/sh
              xscreensaver-command -lock
              Make sure the file is executable (chmod a+x).

      Now use xscreensaver normally, controlling it via  the  usual  xscreen-
      saver-demo(1) and xscreensaver-command(1) mechanisms.

Note the Autostart file, xscreensaver.desktop. For the copy-and-paste:
Code:

[Desktop Entry]
Exec=xscreensaver
Name=XScreenSaver
Type=Application
X-KDE-StartupNotify=false

That is a file you want to set for the Desktop Autostart on your OpenSuSE appliance.
(SIDE NOTE: If you are using windows as your primary system, you may want to get an app like Notepad++ or Metapad to paste into, so you can control the way the line-feeds are written. Some shells have an issue with the CR/LF that windows puts in with Notepad.)

Now, one last question: Are you trying to run xscreensaver as the background for kdm, too?

Let us know.

krptodr 02-02-2012 10:33 AM

Quote:

Originally Posted by ShadowCat8 (Post 4590129)

Just out of curiosity, are you making this a cloud appliance, USB stick, VM or live cd/dvd?

Now, one last question: Are you trying to run xscreensaver as the background for kdm, too?

Let us know.

1. I wish to use it as a VM. Let me fill you in more on what it is I wish to do.

I am creating an OpenSuse Appliance server. This server will be an xserver for allowing remote connections from other PC's on the same network. (new topics will be created for help on this.. I am stuck in a few areas because of my choice to use KDM and not XDM. Even though KDM loads config files for XDM... ) I will then create a seperate appliance for the PC's that will be connecting to the server. This appliance will simply just connect to the server upon booting up. As I was checking more into the config files, it looks like KDM allows autologins as well, this will be handy.

2. Im not sure how I would know if xscreensaver is running as the background for KDM. I am primarily a Windows user, so background to me in this case would imply a live wallpaper of some sort. On a more technical level I am thinking xscreensaver has some ability to be a backup screensaver incase KDM fails. Can you please explain that question for me?

Thank you for your help. The information supplied has actually helped me more than you would think. I was able to learn how one can load global settings.

Can you explain a little more on the autostart file. I see that you can add a .desktop extention, but does that create it as a desktop icon? because I seen a mycomputer.desktop file and I figured that to be the icon file for the KDE desktop to access the computer file system.

Where do you store the autostart files? Do have more information on this outside of the thread?

ShadowCat8 02-14-2012 07:11 PM

Okay,

Let's take these in order:
  1. To make sure I understand, you are going to run the OpenSuSE as a VM to serve multiple KDE desktops as remote desktops to the systems that connect to the VM from the LAN?
    I'm just making sure we are on the same page, since normally having your xorg server available to be connected to from outside it's own box has been viewed as a security vulnerability for a while. In fact, AFAIK, most default installations won't allow the xorg server be connected to by anything outside of the account that started it in most distros. Of course, I can also see where doing exactly that would be a great help in a few situations, so I'm just trying to get the details correctly.
  2. Okay, for the xscreensaver as a wallpaper, I'm borrowing (READ: paraphrasing) from CrunchBang (a.k.a. '#!') Linux' Wiki:
    1. To set a screensaver as a wallpaper, first run “xscreensaver-demo”.
    2. From the list on the left, select your desired screensaver. You can preview it or tweak it's settings to your preferences, by clicking the Settings button on the right side below small preview window. This will open the Settings window for that screensaver.
    3. After you are done changing the settings to your liking, from the Settings window click on the “Advanced »” button. You will be presented with a text-box and a combo-box; The combo box contains the graphical engine and/or library for displaying the chosen screensaver. But, the text-box has the information we need: The text-box contains the command you need to run the screensaver as a wallpaper. Now, depending on what screensaver you have chosen and what settings you have set for it, the info can vary greatly. As an example, here is what I am using for my standard glmatrix screensaver:
      Code:

      glmatrix -root -density 36 -speed 3.6311
    4. Now, depending on the distribution, you may need to find the actual location of the screensaver. If the info you copied is like mine above, then you will likely have to find it. A couple default locations to look are under /usr/lib/xscreensaver/ or /usr/lib/misc/xscreensaver/. If you don't find your chosen screensaver under there, then use the following command, substituting "glmatrix" for the screensaver name you chose.
      Code:

      ~ # find /usr/ -iname "glmatrix" -print
    5. Now that you have found the exact path of the screensaver, let's test it out. Hit "ALT+F2" and when the Run dialog window comes up, use the full pathname of the screensaver with all the flags you copied from the Advanced Settings text-box. So, in my example, it would look something like this:
      Code:

      /usr/lib/misc/xscreensaver/glmatrix -root -density 36 -speed 3.6311
    6. If you now see the screensaver as your wallpaper, then you are good, and you only have to add that as the "Custom Default Wallpaper" in the kdm configuration. If you *don't* see it as your wallpaper, well, there can be a few reasons for that and we can go over those later.
  3. Now, for the autostart files, think of them as a combination between the link that you use in the "Startup" Folder of your "Start Menu" under "All Programs" combined with the additional information that is already part of Windows internal database that is the major part of Microsoft's OLE subsystem. The '.desktop' extension is telling the system what kind of information is inside the file and, to some degree, how it's formatted. And, yes, it is the same kind of file that you see on the desktop for creating links to apps and sections of the filesystem. But, the fact that it goes into the 'Autostart' folder under the KDE folders means it will always be started when KDE starts up. To check, you should open up a terminal while you are logged into the VM and run the following:
    Code:

    ~ $ ls -a
    and you will end up with something like:
    Code:

    ~ $ ls -a
    .                .emerald          .kde4                  .qt
    ..                .esd_auth          .kderc          .shcache
    .adobe                .fehbg                  .local          .shotwell
    .bash_history        .fluxbox          .m2            .ssh
    .bash_logout        .fontconfig          .macromedia          .swt
    .bash_profile        .fonts.cache-1          .mozilla          .themes
    .bashrc                .fonts.conf          .mplayer        .thumbnails
    .cache                .gimp-2.7          .nanorc          .thunderbird
    .config                .gnupg                  .netbeans          .viminfo
    .dbus                .gstreamer-0.10          .nv                  .vimrc
    Desktop                .gtk_qt_engine_rc .opera          .wine
    .dmrc                .gtkrc-2.0-kde4          .pki                  .Xauthority
    Downloads        .ICEauthority          .pulse          .xine
    .dvdcss                .icedtea          .pulse2.locator .xprofile
    .e                .isomaster          .pulse-cookie          .xscreensaver
    .emacs                .java                  .pystartup          .xsession-errors

    and in the above example, you would look for the '[Aa]utostart' (The '[Aa]' means it could be a capital or lower-case 'a'.) folder underneath the '.kde4' folder. I would show you directly, but I am running the LXDE desktop, so I don't have those files.

Well, I hope that helps out. Let us know.


All times are GMT -5. The time now is 06:41 PM.