Friday, April 10, 2009

Download, Store and Install Packages in Ubuntu Automaticly

I normaly like to have the packages I install stored, to use later on. This is helpfull you don't have an internet conection or have a slow one, or need to install the same stuff on multiple machine.

So I have made a couple off scripts in bash language, which I had never used before, so these migth no be the best scripts in the world but they get the jobe done.

The first script (download_and_store) to download and store in folders all of my favorite apps, and another that installs every apps (install_all) on those folders.


download_and_store
--------------------------------------------------------------------------------------------------

#!/bin/bash

## List of packages to download ####
L_PACKAGES_TO_DOWNLOAD="

vlc
mplayer
amarok
wireshark
k3b

"
################################

D_APTGET_CACHE="/var/cache/apt/archives"

echo "Where will you want to store the packages"
read D_DOWNLOADED_PACKAGES

# clean apt-get's cache
apt-get clean

# create the root directory for the downloaded package ##
mkdir -p $D_DOWNLOADED_PACKAGES


for i in $L_PACKAGES_TO_DOWNLOAD ; do ## go through all the packages on the list

## download apt-get packages whithout instaling them (apt-get cache) ##
apt-get install -d $i

## create the dir for the downloaded package ##
mkdir $D_DOWNLOADED_PACKAGES/$i

## move de downloaded package on apt-get chache to the created dir ##
mv $D_APTGET_CACHE/*.deb $D_DOWNLOADED_PACKAGES/$i

# clean apt-get's cache
apt-get clean

done


install_all
----------------------------------------------------------------------

#!/bin/bash
for i in $( ls -p | grep "/" ); do ## go through every dir
echo ">>>>>>>>>>>>>>>>>>>>>"
cd $i ## enter a dir (where the packages and dependecies are)
echo Dir Actual: $(pwd)
dpkg -i *.deb ## install all debs (package and its dependencies)
cd ..
echo "<<<<<<<<<<<<<<<<<<<<<" done



Now for the demonstration, lets use download_and_store to download all of you favorite apps.

# create a file for download_and_store #####
$ sudo gedit download_and_store

paste the script above, and change the list L_PACKAGES_TO_DOWNLOAD, to include you favorite packages (these are separeted by a space or newline).

# give the script permitions to execute #####
$ sudo chmod 777 /path_to_it/download_and_store

# execute download_and_store
$ cd /path_to_it
$ ./download_and_store
Where will you want to store the packages
/home/my_user/Desktop/saved_apps --> you chose this dir

Now just wait...

Once its over you will have in /home/my_user/Desktop/saved_apps a folder for each application, for example vlc, you wil have a dir named vlc whith the vlc package and all of it's dependencies.

============================
Now, lets use install_all to install all of your downloaded apps.

# create a file for install_all #####
$ sudo gedit /home/my_user/Desktop/saved_apps/install_all

as you can see install_all must be in the root dir you inputed earlier ( /home/my_user/Desktop/saved_apps), this script will install all he can find in the dirs below.

# give the script permitions to execute #####
$ sudo chmod 777 /home/my_user/Desktop/saved_apps/install_all

# execute download_and_store
$ cd /home/my_user/Desktop/saved_apps/
$ ./install_all

Now wait...

There you apps should all be installed.

These scripts are very basic, these are my first in bash programing, and aren't fully tested, but if you can get an idea from them, or even improve them I'm happy.

Thursday, April 9, 2009

Installing ZenOSS on Ubuntu 8.10 (Hardy Heron)

Hello previously, I have posted how to install Zenoss and setup a test environment (you can find it here), but there we instaled Zenoss in CentOS, here I'm going to show you how to install it on Ubuntu 8.10

# Install Apache With It's Documentation #####
$ sudo apt-get install apache2 apache2-doc

# Start Apache (it should already be started) #####
$ sudo /etc/init.d/apache2 start


# Test Apache #####

Type on Mozilla Firefox: http://127.0.0.1/
It souhld read: It works!


# Instaling MySQL and PHP necessary Dependencies #####

$ sudo apt-get install mysql-server mysql-client
Type in mySQL's root password in the upcoming textbox.


# Instaling SNMP Query tools #####
$ sudo apt-get install snmp


# Downloading ZenOSS #####

In http://www.zenoss.com/download/links?creg=no
you can see all the suported distributions,
you just have to pick yours if it's there,
otherwise pick the closets.

In runing Ubuntu 8.10, which isnt there so I go for
the Ubuntu 8.04, here's the link:
http://sourceforge.net/project/downloading.php?groupname=zenoss&filename=zenoss-stack-2.3.3-linux.bin&use_mirror=freefr

# Installing ZenOSS #####

$ cd /path_to_zenoss_executable_dir/

$ sudo chmod 777 zenoss-stack-2.3.3-linux.bin

$ sudo ./zenoss-stack-2.3.3-linux.bin

Type in the data the installer gui asks you, like the
database root login.


# Logging in into ZenOSS #####

After installing it should open your browser on the ZenOSS
login page, if not just type on your browser:

http://localhost:8080/

The default login and password are:

Login: admin
Password: zenoss

Now you can just continue the "Installing Net-SNMP on Linux Clients" on the previous post that you cam find here.

Setting Up a SNMP Server in Ubuntu

What is net-snmp ?

Simple Network Management Protocol (SNMP) is a widely used protocol for monitoring the health and welfare of network equipment (eg. routers), computer equipment and even devices like UPSs. Net-SNMP is a suite of applications used to implement SNMP v1, SNMP v2c and SNMP v3 using both IPv4 and IPv6.

Net-SNMP Tutorials
http://www.net-snmp.org/tutorial/tutorial-5/

Net-SNMP Documentation
http://www.net-snmp.org/docs/readmefiles.html

# Installing SNMP Server in Ubuntu #####

$ sudo apt-get install snmpd



# Configuring SNMP Server #####

/etc/snmp/snmpd.conf - configuration file for the Net-SNMP SNMP agent.

/etc/snmp/snmptrapd.conf - configuration file for the Net-SNMP trap daemon.


Set up the snmp server to allow read access from the other machines in your network for this you need to open the file /etc/snmp/snmpd.conf change the following Configuration and save the file.

$ sudo gedit /etc/snmp/snmpd.conf



snmpd.conf
#---------------------------------------------------------------
######################################
# Map the security name/networks into a community name.
# We will use the security names to create access groups
######################################

# sec.name source community

com2sec my_sn1 localhost my_comnt
com2sec my_sn2 192.168.10.0/24 my_comnt


####################################
# Associate the security name (network/community) to the
# access groups, while indicating the snmp protocol version
####################################

# sec.model sec.name
group MyROGroup v1 my_sn1
group MyROGroup v2c my_sn1
group MyROGroup v1 my_sn2
group MyROGroup v2c my_sn2


group MyRWGroup v1
my_sn1
group MyRWGroup v2c my_sn1
group MyRWGroup v1 my_sn2
group MyRWGroup v2c my_sn2

#######################################
# Create the views on to which the access group will have access,
# we can define these views either by inclusion or exclusion.
# inclusion - you access only that branch of the mib tree
# exclusion - you access all the branches except that one
#######################################

# incl/excl subtree mask (opcional)
view my_vw1 included .1 80
view my_vw2 included .iso.org.dod.internet.mgmt.mib-2.system

#######################################
# Finaly associate the access groups to the views and give them
# read/write access to the views.
#######################################

# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact my_vw1 none none
access MyRWGroup "" any noauth exact my_vw2 my_vw2 none
# -----------------------------------------------------------------------------


# Give access to other interfaces besides the loopback #####

$ sudo gedit /etc/default/snmpd

find the line:

SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'

and change it to:

SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid'


# Restart snmpd to load de new config #####

$ sudo /etc/init.d/snmpd restart


# Test the SNMP Server #####


$ sudo apt-get install snmp

$
sudo snmpwalk -v 2c -c my_comnt localhost system

Tuesday, January 27, 2009

Installing the SMF Forum on Linux

# Install Apache With It's Documentation #####
$ sudo apt-get install apache2 apache2-doc

# Start Apache (it should already be started) #####
$ sudo /etc/init.d/apache2 start


# Test Apache #####

Type on Mozilla Firefox: http://127.0.0.1/
It souhld read: It works!

Note: The message "It works!" can be found at the /var/www
directorie, which is apaches's root directory, wich is were
we will install SMF.



# Instaling MySQL and PHP necessary Dependencies #####

$ sudo apt-get install mysql-server mysql-client
Type in mySQL's root password in the upcoming textbox.

$ sudo apt-get install libapache2-mod-php5 libapache2-mod-perl2

$ sudo apt-get install php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-ldap

$ sudo apt-get install php5-mhash php5-mysql php5-odbc curl libwww-perl imagemagick



# Extract SMF #####

$ unzip smf_1-1-7_install.zip



# Installing SMF in Apache #####

# Copy SMF to /var/www (apache root dir)
$ sudo cp -vr smf_1-1-7_install /var/www



# Give Apache Ownership Over SMF Files (apache-user: www-data) #####

$ sudo chown www-data -vR /var/www/smf_1-1-7_install/*


# Restart Apache #####

$ sudo /etc/init.d/apache2 restart


# Delete Apache's Test Page #####

$ sudo rm -rf /var/www/index.html



# Configuring SMF #####

Type on Mozilla Firefox:
http://127.0.0.1/smf_1-1-7_install/install.php
and configure SMF acording to the presented instructions.


Now your forum is on:

http://127.0.0.1/smf_1-1-7_install/index.php
or
http://127.0.0.1/smf_1-1-7_install/

Thursday, January 8, 2009

Installing a Web Application (SugarCRM) on a WebHost

The web application in this example is SugarCRM (SugarCE-5.0.0f) which I already shown how to install on you own host here. Now I'm going to show you how to install it on a WebHost (like BlueHost or others). Installing a web application on a web host is a bit trickier because what you can do on the webhost is very limited.

Im going to assume that you have SugarCRM working on you computer using the howto about installing SugarCRM on your own webhost you can find here. We are going to use this as a basis of comparison between the configs you have localy and the ones on the webhost. You may not need this.


Lets Start...

Create on the webhost the folder SugarCRM, using an FTP client like gftp.

Upload a file php.info (below) on to the folder SugarCRM on the webhost in order to obtain information about the instaled modules and php.ini (/etc/php5/apache2/php.ini) configuration, since you can't access them directly.






Copy the phpinfo.php to your local SugarCRM folder at the apache root (/var/www), not because you are limited but to make it easyer to compare with the webhost config

$ cp /path_to_phpinfo/phpinfo.php /var/www/SugarCRM


Check if the webhost as the apache modules you need

On the browser execute:

http//www.your_domain_on_the_webhost.com/SugarCRM/phpinfo.php

and check the "Loaded Modules" for the needed modules, if you dont now the modules you need execute also:

http://127.0.0.1/SugarCRM/phpinfo.php

and compare the modules you have localy to the the ones on the webhost, the modules you have locally migth not all be needed but if your webhost has them it will work for sure. If there are missing modules contact you webhost and ask them to install them.

Extracting SugarCRM

$ unzip SugarCE-5.0.0f.zip

From now on we are going to prepare on our local machine SugarCRM, in order to upload to the webhost all thats necessary, to minimize the problems.

Defining the read and write permissions on some of SugarCRM's files

$ cd /path_to_extracted_sugar/SugarCE-Full-5.0.0f

$ sudo chmod 766 config.php

$ sudo chmod 766 custom

$ sudo chmod -R 766 data

$ sudo chmod -R 766 cache

$ sudo chmod -R 766 modules


Creating the the SugarCRM sessions directory, seen that by default SugarCRM sessions directory woul be /var/lib/php/session to wich on the webhost we won't have access.

$ cd /path_to_extracted_sugar/SugarCE-Full-5.0.0f

$ mkdir session_save

$ sudo chmod 770 session_save


Configuring php.ini via .htaccess

Seen that we dont have access to php.ini on the webhost (/etc/php5/apache2/php.ini), we are going have to put the configurations we need on the file .htaccess, notice that the configurations on .htaccess only affects the directory where it is and those bellow it.

In order to now what to put on .htaccess, what I did was, execute the phpinfo.php on my local SugarCRM folder and the Webhost, like this:

http:/www.your_domain_on_the_webhost.com/SugarCRM/phpinfo.php (Webhost SugarCRM)

http://127.0.0.1/phpinfo.php (Local SugarCRM)

And saw the differences between the different variables in "Configuration - PHP Core" (php.ini config), and changed the ones in the webhost that were different to the value the local ones had. They not all be needed but if it work locally on the web host should work to. The result was the following .htaccess:

.htaccess - put in /path_to_extracted_sugar/SugarCE-Full-5.0.0f
--------------------------------------------------------------------

php_value memory_limit 50M
php_value upload_max_filesize 10M
php_value allow_call_time_pass_reference On
php_value allow_url_fopen On
php_value display_errors On
php_value enable_dl On
php_value magic_quotes_gpc On
php_value register_long_arrays On
php_value safe_mode Off
php_value session.save_path /home/my_ftp_user_name/SugarCRM/session_save

The last value php_value session.save_path you have to ask to you webhost, where on in their machine is the top folder you access via FTP, which in my case is /home/my_user_name/, the rest is same (SugarCRM/session_save). Or you can always try to gess it /home/your_ftp_user_name.


Nowing that after the upload of SugarCRM to the webhost in order for SugarCRM to work, like any other webapp, the must be owned by the apache user. Now the problem is, that if apache owns the the files you wont be able to access the if there's some kind of problem, or even delete them.

My solution for this problem is giving the same read,write, execute permitions that the owner has, to the group and being a part of this group, like this you will have the same permitions you had before apache became the owner of the files.

In order to do that we are going to use the following script:

usertogroup
---------------------
#!/bin/ksh
echo "Enter Base Directory: "
read source_dir
for file in `find $source_dir`
do
#full=`ls -ld $file |awk '{print $1}'`
owner=`ls -ld $file | cut -c2-4`
#echo "$full $file ----------------> chmod g+$owner $file"
chmod g+$owner $file
done

$ sudo chmod 777 usertogroup

$ sh usertogroup
Enter Base Directory:
/path_to_extracted_sugar/SugarCE-Full-5.0.0f


Now that we have SugarCRM prepared in our computer, lets upload the contents off /path_to_extracted_sugar/SugarCE-Full-5.0.0f to the SugarCRM
folder that we created before, using an FTP client like gFTP.

The folowing steps you have to ask the webhost to do the following:

- Change the owner of all of the SugarCRM files to the apache user

- Add our username to the group that the file belongs to.


Now you should be able to configure SugarCRM, by executing the following in the browser:

http://www.your_domain_on_the_webhost.com/SugarCRM/install.php

and configure SugarCRM, once configure you can access SugarCRM's main page by executing the following in the web browser:

http://www.your_domain_on_the_webhost.com/SugarCRM/index.php

OR

http://www.your_domain_on_the_webhost.com/SugarCRM

And thats it, now you sould have SugarCRM up and running.

Sharing Internet on Linux

Hello there, in this post I'm going to show you how to share an Internet connection regardless off you having a public ip or not, you just need to have Internet on the computer that`s going to make the share.

I don't now if this is the most correct way to do it, but I can tell you that it worked on my machine which was running Ubuntu 8.10.

The picture below shows my test scenario, to make it easier for you to map it to your own.



click on the picture for a better viewing!!!

As you can see on the picture above I shared PC1's Internet with PC2, my PC2 was also running Linux but it could also be running Windows, MacOS, etc.

The IP configuration for the link between PC1 and PC2 was done manualy, but you can have an DHCP Server on PC1 dictating the IPs, DNS Servers, Gateway for both PCs.

What we are configuring is an IP Forwanding using the iptables, NAT MASQUERING.

As you can see on the picture you can see the DNS Servers (red an blue) I used on PC2 was the same servers that the wlan0 interface (the one with internet) on PC1, because if PC1 can reach the servers so will PC2.

First configure the interfaces that make the link between PC1 and PC2, you can configure any private network you want, i used the 10.0.0.0/8 network (see picture), gave the IP 10.0.0.1 to PC1, and 10.0.0.2 to PC2 and defined its Gateway as 10.0.0.1 (PC1) in order for it to send it's packets for the internet to PC1. On PC2 don't forget the DNS Servers that are the same that you have on PC1 in the interface with internet (wlan0), in Ubuntu you can find the DNS Servers, by tipping the following on the bash, so type this on PC1:

$ cat /etc/resolv.conf

# Generated by NetworkManager
domain hello.there
search hello.there
nameserver 192.168.1.210
nameserver 192.168.1.216
nameserver 192.168.1.215


Now that you have the link between both PCs configured (2 PCs on the same private network, and DNS Servers on PC2), just type the following on the bash in order to do the share.

$ su

# echo 1 > /proc/sys/net/ipv4/ip_forward

# exit

$ sudo iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o wlan0 -j MASQUERADE

On the last command you if you configured a different private ip range, between the two PCs, you should change the 10.0.0.0/8 onto the one you chose and change the wlan0 to the interface that has the Internet on PC1.

And now you should have Internet both on PC1 and PC2.

Note: If instead of PC2 you have a switch/hub conected to PC1, you can use PC1 to serve multiple PCs (PC2, PC3, PC4, ...), you just need to make the same IP configuration that you did for PC2, only chanaging the the IP (PC2: 10.0.0.2, PC3: 10.0.0.3, PC4: 10.0.0.4) and connect these to the switch.

OR

Another solution to share with more than one PC is PC1 having multiple interfaces onto which PC2, PC3, PC4, ..., connected directly, as above make the same IP configuration that you did for PC2, only changing the the IP (PC2: 10.0.0.2, PC3: 10.0.0.3, PC4: 10.0.0.4) and connect these to PC1.

Tuesday, December 2, 2008

Complete FTP Session - BASH

A Complete Example FTP Session

Let us now look at an examle FTP where many of the commands above are used in practice. We do the following:
  • connect to the year1 server -- open,
  • list the files -- dir,
  • change directory -- cd,
  • list directories contents -- dir,
  • set binary transfer mode: to download the gif file correctly -- (bin)ary,
  • download a single file -- get
  • turn prompt on: to allow interactive multiple get),
  • perform a multiple get: note prompt we get and MUST acknowledge -- mget, and
  • finally close the connection .

The FTP Session looks like this:

ftp> open ftp.cs.cf.ac.uk

Connected to thrall.cs.cf.ac.uk.
220-************************************************************************
220- Cardiff Computer Science campus ftp access. Access is available
220- here as anonymous, by ftp group or by username/password.
220-
220- The programs and data held on this system are the property of the
220- Department of Computer Science in the University of Wales, Cardiff.
220- They are lawfully available to authorised Departmental users only.
220- Access to any data or program must be authorised by the Department
220- of Computer Science.
220-
220- It is a criminal offence to secure unauthorised access to any programs
220- or data on this computer system or to make any unauthorised
220- modification to its contents.
220-
220- Offenders are liable to criminal prosecution. If you are not an
220- authorised user do not log in.
220-************************************************************************
220-
220-Cardiff University. Department of Computer Science.
220-This is the WUSL ftp daemon. Please report problems to
220-Robert.Evans@cs.cf.ac.uk.
220-
220 thrall.cs.cf.ac.uk FTP server (Version wu-2.6.1(1) Mon Sep 18 12:45:30 BST 2000) ready.
Name (ftp.cs.cf.ac.uk:dave): year1
331 Password required for year1.
Password:
230-
230-Welcome to the guest ftp server for Year 1 Internet Computing
230-in the Department of Computer Science at the University of Wales, Cardiff.
230-
230-Please note that all commands and transfers from this ftp account
230-are logged and kept in an audit file.
230-
230-
230 User year1 logged in. Access restrictions apply.

ftp> dir

200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 32
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_gif
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_hqx
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_text
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_uu
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_zip
drwxr-xr-x 2 y1ftp 512 Oct 18 1999 exercise
drwxrwxr-x 2 gueftp 2048 Nov 5 1999 incoming
drwx--x--x 2 staff 1024 Nov 11 1999 marker
drwxrwxr-x 2 gueftp 2048 Nov 10 1999 test
226 Transfer complete.
489 bytes received in 0.0032 seconds (148.17 Kbytes/s)

ftp> cd exercise

250 CWD command successful.
ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 156
-rw-rw-r-- 1 staff 25943 Dec 8 1997 ex.gif
-rw-rw-r-- 1 staff 53104 Oct 18 1999 ex.txt
226 Transfer complete.
117 bytes received in 0.0066 seconds (17.22 Kbytes/s)

ftp> bin

200 Type set to I.
ftp> get ex.gif
200 PORT command successful.
150 Opening BINARY mode data connection for ex.gif (25943 bytes).
226 Transfer complete.
local: ex.gif remote: ex.gif
25943 bytes received in 0.072 seconds (350.60 Kbytes/s)
ftp> prompt
Interactive mode on.

ftp> mget *.*

mget ex.gif? y
200 PORT command successful.
150 Opening BINARY mode data connection for ex.gif (25943 bytes).
226 Transfer complete.
local: ex.gif remote: ex.gif
25943 bytes received in 0.067 seconds (378.46 Kbytes/s)
mget ex.txt? y
200 PORT command successful.
150 Opening BINARY mode data connection for ex.txt (53104 bytes).
226 Transfer complete.
local: ex.txt remote: ex.txt
53104 bytes received in 0.13 seconds (387.51 Kbytes/s)

ftp> close

221-You have transferred 184037 bytes in 5 files.
221-Total traffic for this session was 186865 bytes in 9 transfers.
221-Thank you for using the FTP service on thrall.cs.cf.ac.uk.
221 Goodbye.
ftp>

Make sure that you can pick out the different ftp commands and responses in this output. Notice that the ftp responses are only displayed when the verbose feature is turned on.


Taken From: http://www.cs.cf.ac.uk/Dave/Internet/node118.html