Archive

Posts Tagged ‘shell script’

Linux Server – Task 4: Creating MetaPackages

Course
Linux palvelimena [Linux server] by Tero Karvinen at Haaga-Helia University of Applied Sciences

Task
Create a metapackage, which installs some software of your choosing, and make sure it passes the lintian check. Create a package repository with reprepro. Package one of your scripts, so that the package installs a new script for the users.

Testing environment
OS: Xubuntu Linux 13.10 “Saucy Salamander” 32-bit (persistent live USB drive)
System: HP EliteBook 2570p Notebook PC

Creating the metapackage
I began by installing equivs via the terminal: $ sudo apt-get install equivs. I then proceeded to create a metapackage in a folder named packages, in my home directory, with $ equivs-control jannes-metatest.cfg. After this I edited the file with $ nano jannes-metatest.cfg to contain only the following:

Section: misc
Priority: optional
Standards-Version: 3.9.2

Package: jannes-metatest
Version: 0.1
Maintainer: Example
Depends: geoip-bin, pidgin
Description: Test MetaPackage
by Janne Varis

This particular package would now install GeoIP and Pidgin, once complete. To complete it, I executed $ equivs-build jannes-metatest.cfg in the terminal. Success. The resulting file: jannes-metatest_0.1_all.deb, located in the previously mentioned packages folder.

Passing lintian and testing
I tested the metapackage in lintian next with $ lintian jannes-metatest_0.1_all.deb. Success. I received no errors. Next I needed to install gdebi with $ sudo apt-get install gdebi-core -y to test my metapackage in use, which I did with $ sudo gdebi -n jannes-metatest_0.1_all.deb. The metapackage worked flawlessly, and GeoIP and Pidgin were installed.

Creating the package repository with reprepro
To begin, I created a folder structure in the public_html folder in my home directory by entering $ mkdir -p repository/conf in the terminal, after having navigated to the public_html folder. I also created a file within the same folder structure with $ nano repository/conf/distributions, in which I entered details about my Xubuntu version, some of them could be printed out by entering $ lsb_release -a in the terminal. My file looked like this:

Codename: saucy
Components: main
Suite: saucy
Architectures: i386 amd64 source

Next I installed reprepro with $ sudo apt-get install reprepro -y. Then I added the latest .deb package that I had made with $ reprepro -VVVV -b public_html/repository includedeb saucy packages/jannes-metatest_0.1_all.deb.

To install the repository to clients, I needed to edit repository.list by entering $ dsudoedit /etc/apt/sources.list.d/repository.list in the terminal. I added the following line and saved the changes:

deb http://127.0.0.1/~xubuntu/repository saucy main

Finally I ran $ sudo apt-get update to update the package list, and then sucessfully installed my own package with $ sudo apt-get install jannes-metatest -y.

Packaging a script
First I created a shell script as I had done previously (located in the packages folder this time). After this was done, I edited jannes-metatest.cfg to include the script (Files line) and the desired installation location, and upped the version number to 0.2:

Section: misc
Priority: optional
Standards-Version: 3.9.2

Package: jannes-metatest
Version: 0.2
Maintainer: Example <example@example.com>
Depends: geoip-bin, pidgin
Files: mystatus /usr/local/bin/
Description: Test MetaPackage
by Janne Varis

Then I repeated the remaining steps, as described earlier in this post, to be able to install the package again and run the the script by entering $ mystatus in the terminal (with any user). Task complete.

References
Karvinen, Tero: Forensic File Recovery with Linux (http://terokarvinen.com/2013/forensic-file-recovery-with-linux)
Karvinen, Tero: Lessons 2014-2-10, Linux palvelimena [Linux server] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014)

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen

Linux Server – Task 1: Complete One Course Exam

Course
Linux palvelimena [Linux server] by Tero Karvinen at Haaga-Helia University of Applied Sciences

Task
Complete an archived Työasemat ja tietoverkot [workstations and networks] course exam. I chose this one (in Finnish).

Testing environment
OS: Xubuntu Linux 13.10 “Saucy Salamander” 32-bit (persistent live USB drive)
System: HP EliteBook 2570p Notebook PC

Creating the user accounts
After booting to the desktop, I opened the terminal prompt (super key + t). I had previously set the keyboard layout to Finnish, but I could have changed it manually by executing $ setxkbmap fi in the terminal. Next I created user accounts for the users mentioned in the exam by running $ sudo adduser “user name” in the terminal, making sure to create each person an identifiable user name and a secure password.

Installing Apache and OpenSSH
I ran $ sudo apt-get update in the terminal to update the package list, and then installed Apache server and OpenSSH via the terminal by running $ sudo apt-get install apache2 openssh-server.

Testing Apache
I created a folder named public_html for testing purposes in my home directory by running $ mkdir public_html in the terminal. I then created an index.html file in the same folder with $ nano index.html, and added the following lines to it in order to create a valid HTML5 test page:

<!doctype html>
<html>
<head>
	<title>Test</title>
</head>
<body>
	<p>Hello World!</p>
</body>
</html>

I enabled the Apache2 Userdir Module by running $ sudo a2enmod userdir in the terminal. “Apache2 userdir module is used to create a webroot in the user’s home directory. By using userdir module each user that is in the system will have the Apache2 root directory with the folder name public_html in the home directory” (Ubuntu Server Guide).

Next I restarted the apache2 daemon via $ sudo service apache2 restart. Having completed this, I tested the HTML5 page in Firefox at localhost/~username/, which returned a page with the line “Hello World!”, verifying that the everything was working as intended.

Testing SSH and user home pages
To test SSH and creating home pages for users, I logged in as one of the users (pekkawinha) via SSH by entering $ ssh pekkawinha@localhost in the terminal, and then accepted the host’s authenticity and entered the password for Pekka Winha. Doing so was OK in this case because none of the users had yet been given their passwords, and thus couldn’t have logged in yet.

At this point I repeated the procedure for creating a public_html folder and index.html file (without sudo, as the user isn’t root), this time in pekkawinha’s home directory (/home/pekkawinha/public_html/index.html).

Creating the files while logged in as the user will give the user the permissions necessary to edit the files later, when they log in for the first time. I tested the page in Firefox (the same method as before), and found that everything was working as intended. I terminated the SSH connection with $ exit and returned to my own account.

Installing MySQL and phpMyAdmin
I installed MySQL and phpMyAdmin by entering $ sudo apt-get install mysql-server phpmyadmin in the console. Following my own LAMP installation instructions (in Finnish), I set the root password and selected the correct configuration options. The database for phpMyAdmin was configured with dbconfig-common. I navigated to localhost/phpmyadmin/ in Firefox and was greeted by a login prompt – the root user login details worked, as expected.

Enabling PHP for user directories
Next I needed enable PHP for the user directories. This was accomplished by entering $ sudo nano /etc/apache2/mods-available/php5.conf in the terminal, and editing the php5.conf, which in this case simply meant commenting out the last five lines of the file. Then I restarted the apache2 daemon with $ sudo service apache2 restart.

I logged in as pekkawinha via SSH again to verify that PHP was indeed working. I created a new file in public_html with $ nano index.php, and added the following lines:

<?php
print(37.4+4.4)
?>

After this I navigated to localhost/~pekkawinha/index.php in Firefox, and the result to my query was printed: 41.8. This verified that PHP was working properly. Finally, I used $ exit to terminate the SSH connection.

Creating a global mystatus shell script
The final piece to the puzzle was creating a global shell script named mystatus. I began by creating a new file in my home directory with $ nano mystatus. I added the following lines to it for showing a computer’s disk space and IP address. Since I’m using a live USB drive, I used ifconfig to cover all my bases, but you can use something like ip addr show wlan0 if you only use one computer.

#!/bin/sh
df -h
ifconfig

Next I gave the mystatus script the necessary permissions to run it by running $ chmod a+x mystatus in the terminal. Then I tested the script via $ ./mystatus. It worked as expected. Finally, I ran $ sudo mv mystatus /usr/local/bin to move the mystatus script, so that it was globally available to all users by simply entering $ mystatus in the terminal.

References
Linux Live USB Creator (http://www.linuxliveusb.com/)
Ubuntu Server Guide (http://ubuntuserverguide.com/2012/10/how-to-enable-and-configure-apache2-userdir-module-in-ubuntu-server-12-04.html)
Karvinen, Tero: Lessons 2014-1-24, Linux palvelimena [Linux server] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014)

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen