LPI-Learning-Material-102-500-en-122-164.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting.vimrc The file contains a mixture of files and directories, some with blank spaces in their names. This is a suitable scenario for the builtin Bash command mapfile, which will parse any given text content and create an array variabl...

LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting.vimrc The file contains a mixture of files and directories, some with blank spaces in their names. This is a suitable scenario for the builtin Bash command mapfile, which will parse any given text content and create an array variable from it, placing each line as an individual array item. The script file will be named sync.sh, containing the following script: #!/bin/bash set -ef # List of items to sync FILE=~/.sync.list # Origin directory FROM=$1 # Destination directory TO=$2 # Check if both directories are valid if [ ! -d "$FROM" -o ! -d "$TO" ] then echo Usage: echo "$0 " exit 1 fi # Create array from file mapfile -t LIST < $FILE # Sync items for (( IDX = 0; IDX < ${#LIST[*]}; IDX++ )) do echo -e "$FROM/${LIST[$IDX]} \u2192 $TO/${LIST[$IDX]}"; rsync -qa --delete "$FROM/${LIST[$IDX]}" "$TO"; done The first action the script does is to redefine two shell parameters with command set: option -e will exit execution immediately if a command exits with a non-zero status and option -f will disable file name globbing. Both options can be shortened as -ef. This is not a mandatory step, but helps diminish the probability of unexpected behaviour. 112 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 105.2 Customize or write simple scripts The actual application oriented instructions of the script file can be divided in three parts: 1. Collect and check script parameters The FILE variable is the path to the file containing the list of items to be copied: ~/.sync.list. Variables FROM and TO are the origin and destination paths, respectively. Since these last two parameters are user provided, they go through a simple validation test performed by the if construct: if any of the two is not a valid directory — assessed by the test [ ! -d "$FROM" -o ! -d "$TO" ] — the script will show a brief help message and then terminate with an exit status of 1. 2. Load list of files and directories After all the parameters are defined, an array containing the list of items to be copied is created with the command mapfile -t LIST < $FILE. Option -t of mapfile will remove the trailing newline character from each line before including it in the array variable named LIST. The contents of the file indicated by the variable FILE — ~/.sync.list — is read via input redirection. 3. Perform the copy and inform the user A for loop using double parenthesis notation traverses the array of items, with the IDX variable keeping track of the index increment. The echo command will inform the user of each item being copied. The escaped unicode character — \u2192 — for the right arrow character is present in the output message, so the -e option of command echo must be used. Command rsync will selectively copy only the modified file pieces from the origin, thus its use is recommended for such tasks. rsync options -q and -a, condensed in -qa, will inhibit rsync messages and activate the archive mode, where all file properties are preserved. Option --delete will make rsync delete an item in the destination that does not exist in the origin anymore, so it should be used with care. Assuming all the items in the list exist in the home directory of user carol, /home/carol, and the destination directory /media/carol/backup points to a mounted external storage device, the command sync.sh /home/carol /media/carol/backup will generate the following output: $ sync.sh /home/carol /media/carol/backup /home/carol/Documents → /media/carol/backup/Documents /home/carol/"To do" → /media/carol/backup/"To do" /home/carol/Work → /media/carol/backup/Work /home/carol/"Family Album" → /media/carol/backup/"Family Album" /home/carol/.config → /media/carol/backup/.config /home/carol/.ssh → /media/carol/backup/.ssh Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 113 LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting /home/carol/.bash_profile → /media/carol/backup/.bash_profile /home/carol/.vimrc → /media/carol/backup/.vimrc The example also assumes the script is executed by root or by user carol, as most of the files would be unreadable by other users. If script.sh is not inside a directory listed in the PATH environment variable, then it should be specified with its full path. 114 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 105.2 Customize or write simple scripts Guided Exercises 1. How could command test be used to verify if the file path stored in the variable FROM is newer than a file whose path is stored in the variable TO? 2. The following script should print a number sequence from 0 to 9, but instead it indefinitely prints 0. What should be done in order to get the expected output? #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ] do echo $COUNTER done 3. Suppose a user wrote a script that requires a sorted list of usernames. The resulting sorted list is presented as the following on his computer: carol Dave emma Frank Grace henry However, the same list is sorted as the following on his colleague’s computer: Dave Frank Grace carol emma henry What could explain the differences between the two sorted lists? Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 115 LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting 116 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 105.2 Customize or write simple scripts Explorational Exercises 1. How could all of the script’s command line arguments be used to initialize a Bash array? 2. Why is it that, counter intuitively, the command test 1 > 2 evaluates as true? 3. How would a user temporarily change the default field separator to the newline character only, while still being able to revert it to its original content? Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 117 LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting Summary This lesson takes a deeper look at the tests available for the test command and at other conditional and loop constructs, necessary to write more elaborate shell scripts. A simple file synchronization script is given as an example of a practical shell script application. The lesson goes through the following steps: Extended tests for the if and case conditional constructs. Shell loop constructs: for, until and while. Iterating through arrays and parameters. The commands and procedures addressed were: test Perform a comparison between items supplied to the command. if A logic construct used in scripts to evaluate something as either true or false, then branch command execution based on results. case Evaluate several values against a single variable. Script command execution is then carried out depending on the case command’s result. for Repeat execution of a command based on a given criteria. until Repeat the execution of a command until an expression evaluates to false. while Repeat the execution of a command while a given expression evaluates to true. 118 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 105.2 Customize or write simple scripts Answers to Guided Exercises 1. How could command test be used to verify if the file path stored in the variable FROM is newer than a file whose path is stored in the variable TO? The command test "$FROM" -nt "$TO" will return a status code of 0 if the file in the FROM variable is newer than the file in the TO variable. 2. The following script should print a number sequence from 0 to 9, but instead it indefinitely prints 0. What should be done in order to get the expected output? #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ] do echo $COUNTER done The COUNTER variable should be incremented, which could be done with the arithmetic expression COUNTER=$(( $COUNTER + 1 )), to eventually reach the stop criteria and end the loop. 3. Suppose a user wrote a script that requires a sorted list of usernames. The resulting sorted list is presented as the following in his computer: carol Dave emma Frank Grace henry However, the same list is sorted as the following in his colleague computer: Dave Frank Grace carol emma Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 119 LPIC-1 (102) (Version 5.0) | Topic 105: Shells and Shell Scripting henry What could explain the differences between the two sorted lists? The sorting is based on the current system’s locale. To avoid the inconsistencies, sorting tasks should be performed with the LANG environment variable set to C. 120 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 105.2 Customize or write simple scripts Answers to Explorational Exercises 1. How could all of the script’s command line arguments be used to initialize a Bash array? The commands PARAMS=( $* ) or PARAMS=( "$@" ) will create an array called PARAMS with all the arguments. 2. Why is it that, counter intuitively, the command test 1 > 2 evaluates as true? Operator > is intended to be used with string tests, no numerical tests. 3. How would a user temporarily change the default field separator to the newline character only, while still being able to revert it to its original content? A copy of the IFS variable can be stored in another variable: OLDIFS=$IFS. Then the new line separator is defined with IFS=$'\n' and the IFS variable can be reverted back with IFS=$OLDIFS. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 121 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Topic 106: User Interfaces and Desktops 122 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 106.1 Install and configure X11 Reference to LPI objectives LPIC-1 version 5.0, Exam 102, Objective 106.1 Weight 2 Key knowledge areas Understanding of the X11 architecture. Basic understanding and knowledge of the X Window configuration file. Overwrite specific aspects of Xorg configuration, such as keyboard layout. Understand the components of desktop environments, such as display managers and window managers. Manage access to the X server and display applications on remote X servers. Awareness of Wayland. Partial list of the used files, terms and utilities /etc/X11/xorg.conf /etc/X11/xorg.conf.d/ ~/.xsession-errors xhost xauth DISPLAY X Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 123 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops 106.1 Lesson 1 Certificate: LPIC-1 Version: 5.0 Topic: 106 User Interfaces and Desktops Objective: 106.1 Install and configure X11 Lesson: 1 of 1 Introduction The X Window System is a software stack that is used to display text and graphics on a screen. The overall look and design of an X client is not dictated by the X Window System, but is instead handled by each individual X client, a window manager (e.g. Window Maker, Tab Window Manager), or a complete desktop environment such as KDE, GNOME, or Xfce. Desktop environments will be covered in a later lesson. This lesson will focus on the underlying architecture and common tools for the X Window System that an administrator would use to configure X. The X Window System is cross-platform and runs on various operating systems such as Linux, the BSDs, Solaris and other Unix-like systems. There are also implementations available for Apple’s macOS and Microsoft Windows. The primary version of the X protocol used in modern Linux distributions is X.org version 11, commonly written as X11. The X protocol is the communication mechanism between the X client and X server. The differences between the X client and X server will be discussed below. The X Window System’s predecessor was a window system called W and was a NOTE 124 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 joint development effort between IBM, DEC and MIT. This software was born out of Project Athena in 1984. When the developers started work on a new display server, they chose the next letter in the English alphabet: “X”. The X Window System’s evolution is currently controlled by the MIT X Consortium. X Window System Architecture The X Window System provides the mechanisms for drawing basic two dimensional shapes (and three dimensional shapes through extensions) on a display. It is divided into a client and a server, and in most installations where a graphical desktop is needed both of these components are on the same computer. The client component takes the form of an application, such as a terminal emulator, a game or a web browser. Each client application informs the X server about its window location and size on a computer screen. The client also handles what goes into that window, and the X server puts the requested drawing up on the screen. The X Window System also handles input from devices such as mice, keyboards, trackpads and more. Basic Structure of an X Window System The X Window System is network-capable and multiple X clients from different computers on a network can make drawing requests to a single remote X server. The reasoning behind this is so that an administrator or user can have access to a graphical application on a remote system that Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 125 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops may not be available on their local system. A key feature of the X Window System is that it is modular. Over the course of the X Window System’s existence newer features have been developed and added to its framework. These new components were only added as extensions to the X server, leaving the core X11 protocol intact. These extensions are contained within Xorg library files. Examples of Xorg libraries include: libXrandr, libXcursor, libX11, libxkbfile as well as several others, each providing extended functionality to the X server. A display manager provides a graphical login to a system. This system can either be a local computer or a computer across a network. The display manager is launched after the computer boots and will start an X server session for the authenticated user. The display manager is also responsible for keeping the X server up and running. Example display managers include GDM, SDDM and LightDM. Each instance of a running X server has a display name to identify it. The display name contains the following: hostname:displaynumber.screennumber The display name also instructs a graphical application where it should be rendered and on which host (if using a remote X connection). The hostname refers to the name of the system that will display the application. If a hostname is missing from the display name, then the local host is assumed. The displaynumber references the collection of “screens” that are in use, whether that is a single laptop screen or multiple screens on a workstation. Each running X server session is given a display number starting at 0. The default screennumber is 0. This can be the case if only one physical screen or multiple physical screens are configured to work as one screen. When all screens in a multi-monitor setup are combined into one logical screen, application windows can be moved freely between the screens. In situations where each screen is configured to work independently of one another, each screen will house the application windows that open within them and the windows can not be moved from one screen to another. Each independent screen will have its own number assigned to it. If there is only one logical screen in use, then the dot and the screen number are omitted. The display name of a running X session is stored in the DISPLAY environment variable: $ echo $DISPLAY 126 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 :0 The output details the following: 1. The X server in use is on the local system, hence there is nothing printed to the left of the colon. 2. The current X server session is the first as indicated by the 0 immediately following the colon. 3. There is only one logical screen in use, so a screen number is not visible. To further illustrate this concept, refer to the following diagram: Example Display Configurations (A) A single monitor, with a single display configuration and only one screen. (B) Configured as a single display, with two physical monitors configured as one screen. Application windows can be moved freely between the two monitors. (C) A single display configuration (as indicated by the :0) however each monitor is an independent screen. Both screens will still share the same input devices such as a keyboard and mouse, however an application opened on screen :0.0 can not be moved to screen :0.1 and vice versa. To start an application on a specific screen, assign the screen number to the DISPLAY environment variable prior to launching the application: $ DISPLAY=:0.1 firefox & This command would start the Firefox web browser on the screen to the right in the diagram above. Some toolkits also provide command line options to instruct an application to run on a specified screen. See --screen and --display in the gtk-options(7) man page for an example. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 127 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops X Server Configuration Traditionally, the primary configuration file that is used to configure an X server is the /etc/X11/xorg.conf file. On modern Linux distributions, the X server will configure itself at runtime when the X server is started and so no xorg.conf file may exist. The xorg.conf file is divided up into separate stanzas called sections. Each section begins with the term Section and following this term is the section name which refers to a component’s configuration. Each Section is terminated by a corresponding EndSection. The typical xorg.conf file contains the following sections: InputDevice Used to configure a specific model of keyboard or mouse. InputClass In modern Linux distributions this section is typically found in a separate configuration file located under /etc/X11/xorg.conf.d/. The InputClass is used to configure a class of hardware devices such as keyboards and mice rather than a specific piece of hardware. Below is an example /etc/X11/xorg.conf.d/00-keyboard.conf file: Section "InputClass" Identifier "system-keyboard" MatchIsKeyboard "on" Option "XkbLayout" "us" Option "XkbModel" "pc105" EndSection The option for XkbLayout determines the layout of the keys on a keyboard, such as Dvorak, left or right handed, QWERTY and language. The option for XkbModel is used to define the type of keyboard in use. A table of models, layouts and their descriptions can be found within xkeyboard-config(7). The files associated with keyboard layouts can be found within /usr/share/X11/xkb. An example Greek Polytonic keyboard layout on a Chromebook computer would look like the following: Section "InputClass" Identifier "system-keyboard" MatchIsKeyboard "on" Option "XkbLayout" "gr(polytonic)" Option "XkbModel" "chromebook" EndSection 128 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 Alternatively, a keyboard’s layout can be modified during a running X session with the setxkbmap command. Here is an example of this command setting up the Greek Polytonic layout on a Chromebook computer: $ setxkbmap -model chromebook -layout "gr(polytonic)" This setting will only last as long as the X session in use. To make such changes permanent, modify the /etc/X11/xorg.conf.d/00-keyboard.conf file to include the settings required. The setxkbmap command makes use of the X Keyboard Extension (XKB). This is NOTE an example of the additive functionality of the X Window System through its use of extensions. Modern Linux distributions provide the localectl command via systemd which can also be used to modify a keyboard layout and will automatically create the /etc/X11/xorg.conf.d/00-keyboard.conf configuration file. Once more, here is an example setting up a Greek Polytonic keyboard on a Chromebook, this time using the localectl command: $ localectl --no-convert set-x11-keymap "gr(polytonic)" chromebook The --no-convert option is used here to prevent localectl from modifying the host’s console keymap. Monitor The Monitor section describes the physical monitor that is used and where it is connected. Here is an example configuration showing a hardware monitor connected to the second display port and is used as the primary monitor. Section "Monitor" Identifier "DP2" Option "Primary" "true" EndSection Device The Device section describes the physical video card that is used. The section will also contain the kernel module used as the driver for the video card, along with its physical location on the motherboard. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 129 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Section "Device" Identifier "Device0" Driver "i915" BusID "PCI:0:2:0" EndSection Screen The Screen section ties the Monitor and Device sections together. An example Screen section could look like the following; Section "Screen" Identifier "Screen0" Device "Device0" Monitor "DP2" EndSection ServerLayout The ServerLayout section groups all of the sections such as mouse, keyboard and screens into one X Window System interface. Section "ServerLayout" Identifier "Layout-1" Screen "Screen0" 0 0 InputDevice "mouse1" "CorePointer" InputDevice "system-keyboard" "CoreKeyboard" EndSection Not all sections may be found within a configuration file. In instances where a NOTE section is missing, default values are provided by the running X server instance instead. User-specified configuration files also reside in /etc/X11/xorg.conf.d/. Configuration files provided by the distribution are located in /usr/share/X11/xorg.conf.d/. The configuration files located within /etc/X11/xorg.conf.d/ are parsed prior to the /etc/X11/xorg.conf file if it exists on the system. The xdpyinfo command is used on a computer to display information about a running X server instance. Below is sample output from the command: 130 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 $ xdpyinfo name of display: :0 version number: 11.0 vendor string: The X.Org Foundation vendor release number: 12004000 X.Org version: 1.20.4 maximum request size: 16777212 bytes motion buffer size: 256 bitmap unit, bit order, padding: 32, LSBFirst, 32 image byte order: LSBFirst number of supported pixmap formats: 7 supported pixmap formats: depth 1, bits_per_pixel 1, scanline_pad 32 depth 4, bits_per_pixel 8, scanline_pad 32 depth 8, bits_per_pixel 8, scanline_pad 32 depth 15, bits_per_pixel 16, scanline_pad 32 depth 16, bits_per_pixel 16, scanline_pad 32 depth 24, bits_per_pixel 32, scanline_pad 32 depth 32, bits_per_pixel 32, scanline_pad 32 keycode range: minimum 8, maximum 255 focus: None number of extensions: 25 BIG-REQUESTS Composite DAMAGE DOUBLE-BUFFER DRI3 GLX Generic Event Extension MIT-SCREEN-SAVER MIT-SHM Present RANDR RECORD RENDER SECURITY SHAPE SYNC X-Resource XC-MISC XFIXES XFree86-VidModeExtension XINERAMA XInputExtension Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 131 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops XKEYBOARD XTEST XVideo default screen number: 0 number of screens: 1 screen #0: dimensions: 3840x1080 pixels (1016x286 millimeters) resolution: 96x96 dots per inch depths (7): 24, 1, 4, 8, 15, 16, 32 root window id: 0x39e depth of root window: 24 planes number of colormaps: minimum 1, maximum 1 default colormap: 0x25 default number of colormap cells: 256 preallocated pixels: black 0, white 16777215 options: backing-store WHEN MAPPED, save-unders NO largest cursor: 3840x1080 current input event mask: 0xda0033 KeyPressMask KeyReleaseMask EnterWindowMask LeaveWindowMask StructureNotifyMask SubstructureNotifyMask SubstructureRedirectMask PropertyChangeMask ColormapChangeMask number of visuals: 270... The more relevant portions of the output are in bold, such as the name of the display (which is the same as the contents of the DISPLAY environment variable), the versioning information of the X server in use, the number and listing of Xorg extensions in use, and further information about the screen itself. Creating a Basic Xorg Configuration File Even though X will create its configuration after system startup on modern Linux installations, an xorg.conf file can still be used. To generate a permanent /etc/X11/xorg.conf file, run the following command: $ sudo Xorg -configure If there is already an X session running, you will need to specify a different DISPLAY in your command, for example: NOTE 132 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 $ sudo Xorg :1 -configure On some Linux distributions, the X command can be used in place of Xorg, as X is a symbolic link to Xorg. An xorg.conf.new file will be created in your current working directory. The contents of this file are derived from what the X server has found to be available in hardware and drivers on the local system. To use this file, it will need to be moved to the /etc/X11/ directory and renamed to xorg.conf: $ sudo mv xorg.conf.new /etc/X11/xorg.conf The following manual pages provide further information on components of the X NOTE Window System: xorg.conf(5), Xserver(1), X(1) and Xorg(1). Wayland Wayland is the newer display protocol designed to replace the X Window System. Many modern Linux distributions are using it as their default display server. It is meant to be lighter on system resources and have a smaller installation footprint than X. The project began in 2010 and is still undergoing active development, including work from active and former X.org developers. Unlike the X Window System, there is no server instance that runs between the client and kernel. Instead, a client window works with its own code or that of a toolkit (such as Gtk+ or Qt) to provide the rendering. In order to do the rendering, a request is made to the Linux kernel via the Wayland protocol. The kernel forwards the request via the Wayland protocol to the Wayland compositor, which handles device input, window management and composition. The compositor is the part of the system that combines the rendered elements into visual output on the screen. Most modern toolkits such Gtk+ 3 and Qt 5 have been updated to allow for rendering to either an X Window System or a computer running Wayland. Not all standalone applications have been written to support rendering in Wayland as of yet. For applications and frameworks that are still targeting the X Window System to run, the application can run within XWayland. The XWayland system is a separate X server that runs within a Wayland client and thus renders a client window’s contents within a standalone X server instance. Just as the X Window System uses a DISPLAY environment variable to keep track of screens in use, the Wayland protocol uses a WAYLAND_DISPLAY environment variable. Below is sample output from a system running a Wayland display: Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 133 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops $ echo $WAYLAND_DISPLAY wayland-0 This environment variable is not available on systems running X. 134 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 Guided Exercises 1. What command would you use to determine what Xorg extensions are available on a system? 2. You have just received a brand new 10-button mouse for your computer, however it will require extra configuration in order to get all of the buttons to function properly. Without modifying the rest of the X server configuration, what directory would you use to create a new configuration file for this mouse, and what specific configuration section would be used in this file? 3. What component of a Linux installation is responsible for keeping an X server running? 4. What command line switch is used with the X command to create a new xorg.conf configuration file? Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 135 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Explorational Exercises 1. What would the contents of the DISPLAY environment variable be on a system named lab01 using a single display configuration? Assume that the DISPLAY environment variable is being viewed in a terminal emulator on the third independent screen. 2. What command can be used to create a keyboard configuration file for use by the X Window System? 3. On a typical Linux installation a user can switch to a virtual terminal by pressing the Ctrl + Alt + F1 - F6 keys on a keyboard. You have been asked to set up a kiosk system with a graphical interface and need this feature disabled to prevent unauthorized tampering with the system. You decide to create a /etc/X11/xorg.conf.d/10-kiosk.conf configuration file. Using a ServerFlags section (which is used to set global Xorg options on the server), what option would need to be specified? Review the xorg(1) man page to locate the option. 136 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 Summary This lesson covered the X Window System as it is used on Linux. The X Window System is used to draw images and text on screens, as they are defined in various configuration files. The X Window System is often used to configure input devices such as mice and keyboards. This lesson discussed the following points: The X Window System architecture at a high level. What configuration files are used to configure an X Windows System, and their location on the filesystem. How to use the DISPLAY environment variable on a system running X. A brief introduction to the Wayland display protocol. The commands and configuration files addressed were: Modification of a keyboard’s layout within an Xorg installation with setxkbmap and localectl. The Xorg command for creating a new /etc/X11/xorg.conf configuration file. The contents of the Xorg configuration files located at: /etc/X11/xorg.conf, /etc/X11/xorg.conf.d/ and /usr/share/X11/xorg.conf.d/. The xdpyinfo command for displaying general information about a running X server session. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 137 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Answers to Guided Exercises 1. What command would you use to determine what Xorg extensions are available on a system? $ xdpyinfo 2. You have just received a brand new 10-button mouse for your computer, however it will require extra configuration in order to get all of the buttons to function properly. Without modifying the rest of the X server configuration, what directory would you use to create a new configuration file for this mouse, and what specific configuration section would be used in this file? User-defined configurations should be located in /etc/X11/xorg.conf.d/ and the specific section needed for this mouse configuration would be InputDevice. 3. What component of a Linux installation is responsible for keeping an X server running? The display manager. 4. What command line switch is used with the X command to create a new xorg.conf configuration file? -configure Remember that the X command is a symbolic link to the Xorg command. 138 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.1 Install and configure X11 Answers to Explorational Exercises 1. What would the contents of the DISPLAY environment variable be on a system named lab01 using a single display configuration? Assume that the DISPLAY environment variable is being viewed in a terminal emulator on the third independent screen. $ echo $DISPLAY lab01:0.2 2. What command can be used to create a keyboard configuration file for use by the X Window System? $ localectl 3. On a typical Linux installation a user can switch to a virtual terminal by pressing the Ctrl + Alt + F1 - F6 keys on a keyboard. You have been asked to set up a kiosk system with a graphical interface and need this feature disabled to prevent unauthorized tampering with the system. You decide to create a /etc/X11/xorg.conf.d/10-kiosk.conf configuration file. Using a ServerFlags section (which is used to set global Xorg options on the server), what option would need to be specified? Review the xorg.conf(5) man page to locate the option. Section "ServerFlags" Option "DontVTSwitch" "True" EndSection Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 139 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops 106.2 Graphical Desktops Reference to LPI objectives LPIC-1 version 5.0, Exam 102, Objective 106.2 Weight 1 Key knowledge areas Awareness of major desktop environments Awareness of protocols to access remote desktop sessions Partial list of the used files, terms and utilities KDE Gnome Xfce X11 XDMCP VNC Spice RDP 140 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops 106.2 Lesson 1 Certificate: LPIC-1 Version: 5.0 Topic: 106 User Interfaces and Desktops Objective: 106.2 Graphical Desktops Lesson: 1 of 1 Introduction Linux based operating systems are known for their advanced command line interface, but it can be intimidating for non-technical users. Intending to make computer usage more intuitive, the combination of high resolution displays with pointing devices gave birth to picture driven user interfaces. Whilst the command line interface requires prior knowledge about program names and their configuration options, with a graphical user interface (GUI) program functionality can be triggered by pointing to familiar visual elements, making the learning curve less steep. Furthermore, the graphical interface is best suited for multimedia and other visually oriented activities. Indeed, the graphical user interface is almost a synonym to computer interface and most Linux distributions come with the graphical interface installed by default. There is not, however, a single monolithic program accountable for the full featured graphical desktops available in Linux systems. Instead, each graphical desktop is in fact a large collection of programs and their dependencies, varying from distribution’s choices to the user’s personal taste. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 141 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops X Window System In Linux and other Unix-like operating systems where it’s employed, the X Window System (also known as X11 or just X) provides the low-level resources related to the graphical interface rendering and the user interaction with it, such as: The handling of the input events, like mouse movements or keystrokes. The ability to cut, copy and paste text content between separate applications. The programming interface other programs resort to draw the graphic elements. Although the X Window System is in charge of controlling the graphic display (the video driver itself is part of X), it is not intended to draw complex visual elements on its own. Shapes, colors, shades and any other visual effects are generated by the application running on top of X. This approach gives applications a lot of room to create customized interfaces, but it can also lead to development overhead that is beyond the application scope and to inconsistencies in appearance and behaviour when compared to other program interfaces. From the developer’s perspective, the introduction of the desktop environment facilitates the GUI programming bound to the underlying application development, whereas from the user’s perspective it gives a consistent experience among distinct applications. Desktop environments bring together programming interfaces, libraries and supporting programs that cooperate to deliver traditional but still evolving design concepts. Desktop Environment The traditional desktop computer GUI consists of various windows — the term window is used here to refer to any autonomous screen area — associated with running processes. As the X Window System alone offers only basic interactive features, the full user experience depends on the components provided by the desktop environment. Probably the most important component of a desktop environment, the window manager controls window placement and decorations. It is the window manager that adds the title bar to the window, the control buttons — generally associated with the minimize, maximize and close actions — and manages the switching between open windows. The basic concepts found in graphic interfaces of desktop computers came from ideas taken from actual office workspaces. Metaphorically speaking, the computer screen is the desktop, where objects like documents and folders are placed. An NOTE application window with the content of a document mimics physical acts like filling in a form or painting a picture. As actual desktops, computer desktops also 142 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops have software accessories like notepads, clocks, calendars, etc., most of them based on their “real” counterparts. All desktop environments provide a window manager that matches the look and feel of its widget toolkit. Widgets are informative or interactive visual elements, like buttons or text input fields, distributed inside the application window. The standard desktop components — like the application launcher, taskbar, etc. — and the window manager itself rely on such widget toolkits to assemble their interfaces. Software libraries, like GTK+ and Qt, provide widgets that programmers can use to build elaborate graphical interfaces for their applications. Historically, applications developed with GTK+ didn’t look like applications made with Qt and vice-versa, but the better theme support of today’s desktop environments make the distinction less obvious. Overall, GTK+ and Qt offer the same features regarding widgets. Simple interactive elements can be indistinguishable, whereas composite widgets — such as the dialog window used by applications to open or save files — can, however, look quite different. Nonetheless, applications built with distinct toolkits can run simultaneously, regardless of the widget toolkit used by the other desktop components. In addition to the basic desktop components, which could be considered individual programs on their own, desktop environments pursue the desktop metaphor by providing a minimal set of accessory applications developed under the same design guidelines. Variations of the following applications are commonly provided by all major desktop environments: System related applications Terminal emulator, file manager, package installation manager, system configuration tools. Communication and Internet Contacts manager, email client, web browser. Office applications Calendar, calculator, text editor. Desktop environments may include many other services and applications: the login screen greeter, session manager, inter-process communication, keyring agent, etc. They also incorporate features provided by third-party system services, such as PulseAudio for sound and CUPS for printing. These features do not need the graphical environment to work, but the desktop environment provides graphical frontends to facilitate the configuration and operation of such resources. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 143 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Popular Desktop Environments Many proprietary operating systems support only a single official desktop environment, which is tied to their particular release and it is not supposed to be changed. Unlike them, Linux-based operating systems support different desktop environment options that can be used in conjunction with X. Each desktop environment has its own features, but they usually share some common design concepts: An application launcher listing the builtin and third-party applications available in the system. Rules defining the default applications associated to file types and protocols. Configuration tools to customize the appearance and behaviour of the desktop environment. Gnome is one of the most popular desktop environments, being the first choice in distributions like Fedora, Debian, Ubuntu, SUSE Linux Enterprise, Red Hat Enterprise Linux, CentOS, etc. In its version 3, Gnome brought major changes in its look and structure, moving away from the desktop metaphor and introducing the Gnome Shell as its new interface. Figure 1. Gnome Shell Activities The general purpose full-screen launcher Gnome Shell Activities replaced the traditional application launcher and taskbar. However, it is still possible to use Gnome 3 with the old look by choosing the Gnome Classic option in the login screen. KDE is a large ecosystem of applications and development platform. Its latest desktop environment version, KDE Plasma, is used by default in openSUSE, Mageia, Kubuntu, etc. The employment of the Qt library is KDE’s striking feature, giving it its unmistakable appearance and a plethora of original applications. KDE even provides a configuration tool to ensure visual 144 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops cohesion with GTK+ applications. Figure 2. KDE GTK Settings Xfce is a desktop environment that aims to be aesthetically pleasing while not consuming a lot of machine resources. Its structure is highly modularized, allowing a user to activate and to deactivate components according to the user’s needs and preferences. Figure 3. The Xfce desktop There are many other desktop environments for Linux, usually provided by alternative distribution spins. The Linux Mint distribution, for example, provides two original desktop environments: Cinnamon (a fork of Gnome 3) and MATE (a fork of Gnome 2). LXDE is a desktop environment tailored to low resource consumption, which makes it a good choice for installation Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 145 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops on older equipment or single board computers. While not offering all the features of heavier desktop environments, LXDE offers all the basic features expected from a modern graphical user interface. Keyboard shortcuts play an important role in the interaction with the desktop environment. Some keyboard shortcuts — such as Alt + Tab to switch between windows or Ctrl + c to copy text — are universal across desktop environments, but each desktop TIP environment has its own keyboard shortcuts too. Keyboard shortcuts are found in the keyboard configuration tool provided by the desktop environment, where shortcuts can be added or modified. Desktop Interoperability The diversity of desktop environments in Linux-based operating systems imposes a challenge: how to make them work correctly with third-party graphical applications or system services without having to implement specific support for each of them. Shared methods and specifications across desktop environments greatly improve user experience and settles many development issues, as graphical applications must interact with the current desktop environment regardless of the desktop environment they originally were designed for. In addition to that, it is important to keep general desktop settings if the user eventually changes their desktop environment choice. A large body of specifications for desktop interoperability is maintained by the freedesktop.org organization. The adoption of the full specification is not mandatory, but many of them are widely used: Directories locations Where the personal settings and other user-specific files are located. Desktop entries Command line applications can run in the desktop environment through any terminal emulator, but it would be too confusing to make all of them available in the application launcher. Desktop entries are text files ending with.desktop which are used by the desktop environment to gather information about the available desktop applications and how to use them. Application autostart Desktop entries indicating the application that should start automatically after the user has logged in. 146 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops Drag and drop How applications should handle drag and drop events. Trash can The common location of files deleted by the file manager, as well as the methods to store and remove files from there. Icon themes The common format for interchangeable icon libraries. The ease of use provided by desktop environments has a downside compared to text interfaces such as the shell: the ability to provide remote access. While a remote machine command-line shell environment can be easily accessed with tools such as ssh, remote access to graphical environments requires different methods and may not achieve satisfactory performance on slower connections. Non-Local Access The X Window Systems adopts a design based on autonomous displays, where the same X display manager can control more than one graphical desktop session at the same time. In essence, a display is analogous to a text terminal: both refer to a machine or software application used as an entry point to establish an independent operating system session. Although the most common setup involves a singular graphical session running in the local machine, other less conventional setups are also possible: Switch between active graphical desktop sessions in the same machine. More than one set of display devices (e.g. screen, keyboard, mouse) connected to the same machine, each one controlling its own graphical desktop session. Remote graphical desktop sessions, where the graphical interface is sent through the network to a remote display. Remote desktop sessions are supported natively by X, which employs the X Display Manager Control Protocol (XDMCP) to communicate with remote displays. Due to its high bandwidth usage, XDMCP is rarely used through the internet or in low-speed LANs. Security issues are also a concern with XDMCP: the local display communicates with a privileged remote X display manager to execute remote procedures, so an eventual vulnerability could make it possible to execute arbitrary privileged commands on the remote machine. Furthermore, XDMCP requires X instances running on both ends of the connection, which can make it unfeasible if the X Windows System is not available for all the machines involved. In Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 147 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops practice, other more efficient and less invasive methods are used to establish remote graphical desktop sessions. Virtual Network Computing (VNC) is a platform-independent tool to view and control remote desktop environments using the Remote Frame Buffer protocol (RFB). Through it, events produced by the local keyboard and mouse are transmitted to the remote desktop, which in turn sends back any screen updates to be displayed locally. It is possible to run many VNC servers in the same machine, but each VNC server needs an exclusive TCP port in the network interface accepting incoming session requests. By convention, the first VNC server should use TCP port 5900, the second should use 5901, and so on. The VNC server does not need special privileges to run. An ordinary user can, for example, log in to their remote account and start their own VNC server from there. Then, in the local machine, any VNC client application can be used to access the remote desktop (assuming the corresponding network ports are reachable). The ~/.vnc/xstartup file is a shell script executed by the VNC server when it starts and can be used to define which desktop environment the VNC server will make available for the VNC client. It is important to note that VNC does not provide modern encryption and authentication methods natively, so it should be used in conjunction with a third- party application that provides such features. Methods involving VPN and SSH tunnels are often used to secure VNC connections. The Remote Desktop Protocol (RDP) is mainly used to remotely access the desktop of a Microsoft Windows operating system through the TCP 3389 network port. Although it uses Microsoft’s proprietary RDP protocol, the client implementation used in Linux systems are open-source programs licensed under the GNU General Public License (GPL) and has no legal restrictions on use. Simple Protocol for Independent Computing Environments (Spice) comprises a suite of tools aimed at accessing the desktop environment of virtualised systems, either in the local machine or in a remote location. In addition to that, the Spice protocol offers native features to integrate the local and remote systems, like the ability to access local devices (for example, the sound speakers and the connected USB devices) from the remote machine and file sharing between the two systems. There are specific client commands to connect to each one of these remote desktop protocols, but the Remmina remote desktop client provides an integrated graphical interface that facilitates the connection process, optionally storing the connection settings for later use. Remmina has plugins for each individual protocol and there are plugins for XDMCP, VNC, RDP and Spice. The choice of the right tool depends on the operating systems involved, the quality of the network connection and what features of the remote desktop environment should be available. 148 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops Guided Exercises 1. What type of application provides windowed shell sessions in the desktop environment? 2. Due to the variety of Linux desktop environments, the same application may have more than one version, each of them best suited for a particular widget toolkit. For example, the bittorrent client Transmission has two versions: transmission-gtk and transmission-qt. Which of the two should be installed to ensure maximum integration with KDE? 3. What Linux desktop environments are recommended for low-cost single board computers with little processing power? Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 149 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Explorational Exercises 1. There are two ways to copy and paste text in the X Window System: using the traditional Ctrl + c and Ctrl + v keystrokes (also available in the window menu) or to use the mouse middle-button click to paste the currently selected text. What’s the appropriate way to copy and paste text from a terminal emulator? 2. Most desktop environments assign the Alt + F2 keyboard shortcut to the Run program window, where programs can be executed in a command line fashion. In KDE, what command would execute the default terminal emulator? 3. What protocol is best suited to access a remote Windows desktop from a Linux desktop environment? 150 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops Summary This lesson is an overview of graphical desktops available for Linux systems. The X Window System alone provides only simple interface features, so desktop environments extend the user experience in the graphical windowed interface. The lesson goes through the following topics: Graphic interface and X Window System concepts. Desktop environments available for Linux. Similarities and differences between desktop environments. How to access a remote desktop environment. The concepts and programs addressed were: X Window System. Popular desktop environments: KDE, Gnome, Xfce. Remote access protocols: XDMCP, VNC, RDP, Spice. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 151 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops Answers to Guided Exercises 1. What type of application provides windowed shell sessions in the desktop environment? Any terminal emulator like Konsole, Gnome terminal, xterm, etc., will give access to a local interactive shell session. 2. Due to the variety of Linux desktop environments, the same application may have more than one version, each of them best suited for a particular widget toolkit. For example, the bittorrent client Transmission has two versions: transmission-gtk and transmission-qt. Which of the two should be installed to ensure maximum integration with KDE? KDE is built on top of the Qt library, so the Qt version — transmission-qt — should be installed. 3. What Linux desktop environments are recommended for low-cost single board computers with little processing power? Basic desktop environments that don’t use too much visual effects, such as Xfce and LXDE. 152 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13 LPIC-1 (102) (Version 5.0) | 106.2 Graphical Desktops Answers to Explorational Exercises 1. There are two ways to copy and paste text in the X Window System: using the traditional Ctrl + c and Ctrl + v keystrokes (also available in the window menu) or to use the mouse middle-button click to paste the currently selected text. What’s the appropriate way to copy and paste text from a terminal emulator? Interactive shell sessions assign the Ctrl + c keystroke to stop program execution, so the middle- button method is recommended. 2. Most desktop environments assign the Alt + F2 keyboard shortcut to the Run program window, where programs can be executed in a command line fashion. In KDE, what command would execute the default terminal emulator? The command konsole executes KDE’s terminal emulator, but generic terms like terminal also works. 3. What protocol is best suited to access a remote Windows Desktop from a Linux desktop environment? The Remote Desktop Protocol (RDP), as it is natively supported by both Windows and Linux. Version: 2023-07-13 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 153 LPIC-1 (102) (Version 5.0) | Topic 106: User Interfaces and Desktops 106.3 Accessibility Reference to LPI objectives LPIC-1 version 5.0, Exam 102, Objective 106.3 Weight 1 Key knowledge areas Basic knowledge of visual settings and themes. Basic knowledge of assistive technology. Partial list of the used files, terms and utilities High Contrast/Large Print Desktop Themes. Screen Reader. Braille Display. Screen Magnifier. On-Screen Keyboard. Sticky/Repeat keys. Slow/Bounce/Toggle keys. Mouse keys. Gestures. Voice recognition. 154 | learning.lpi.org | Licensed under CC BY-NC-ND 4.0. | Version: 2023-07-13

Tags

linux scripting bash
Use Quizgecko on...
Browser
Browser