Archive

Archive for the ‘Linux’ Category

linux simple router

June 16th, 2010 Comments off

Had you ever need of simple routing, like sharing your connection to other computer?

I had :) so here is a script which turns my laptop into a router, simple configuration, one command, to run it save the script as router.sh

#!/bin/bash

#configuration
IF_LOC=eth0
IP_LOC=192.168.67
IF_NET=wlan0

#script
IF_NET=$(ifconfig $IF_NET | awk ‘/inet/ {print $2}’ | grep -o ‘[0-9]*\.[0-9]*\.[0-9]*’)

#connect
iptables-save > /dev/shm/old_routes
ifconfig $IF_LOC inet $IP_LOC.1
ip route add $IP_LOC.0/24 dev $IF_LOC src $IP_LOC.1
iptables -t nat -A POSTROUTING -s $IF_NET.0/24 -j MASQUERADE

if ip route | grep $IP_LOC.1 >/dev/null
then
#message
clear
echo “Enter this information in connected machines:”
echo “IP address : $IP_LOC.2-254”
echo “Netmask : 255.255.255.0”
echo “Gateway : $IP_LOC.1”
echo “DNS : $(echo -n $(awk ‘/^nameserver/ {print $2}’ /etc/resolv.conf))”
echo “”
echo “Press ENTER to continue.”
read

#monitor connection
iftop -i $IF_LOC

else
echo “Error setting up network”
fi

#disconnect
ip route del $IP_LOC.0/24 dev $IF_LOC
ifconfig $IF_LOC down
iptables-restore < /dev/shm/old_routes rm /dev/shm/old_routes #end [/sourcecode] and give execute rights to the script: [sourcecode lang="bash"] chmod +x router.sh [/sourcecode] now just run it: [sourcecode lang="bash"] sudo ./router.sh [/sourcecode] Script will show configuration of new created network [sourcecode lang="bash"] Enter this information in connected machines: IP address : 192.168.67.2-254 Netmask : 255.255.255.0 Gateway : 192.168.67.1 DNS : 217.172.224.160 89.228.6.21 Press ENTER to continue. [/sourcecode] and start monitor its traffic, to quit routing hit q or CTRL+C It is simplest way to start sharing internet I know off

Categories: Linux Tags: , ,

my git prompt

May 26th, 2010 2 comments

After long playing around with my prompt I finally made it stable and thought it’s time to share :)

So edit your ~/.bashrc file and add following lines on the end:

shopt -s promptvars dotglob histappend no_empty_cmd_completion cdspell xpg_echo

function parse_git_dirty {
  echo -n $(git status 2>/dev/null | awk -v out=$1 -v std="dirty" '{ if ($0=="# Changes to be committed:") std = "uncommited"; last=$0 } END{ if(last!="" && last!="nothing to commit (working directory clean)") { if(out!="") print out; else print std } }')
}
function parse_git_branch {
  echo -n $(git branch --no-color 2>/dev/null | awk -v out=$1 '/^*/ { if(out=="") print $2; else print out}')
}
function parse_git_remote {
  echo -n $(git status 2>/dev/null | awk -v out=$1 '/# Your branch is / { if(out=="") print $5; else print out }')
}
export PS1='$(ppwd \l)\u@\h:\[33[33m\]\w\[33[0m\]$(parse_git_branch ":")\[33[36m\]$(parse_git_branch)\[33[0m\]$(parse_git_remote "(")\[33[35m\]$(parse_git_remote)\[33[0m\]$(parse_git_remote ")")\[33[0m\]$(parse_git_dirty  "[")\[33[31m\]$(parse_git_dirty )\[33[0m\]$(parse_git_dirty  "]")>'

I know it looks a bit complicated, unfortunately it is … this is wired bash rule that escape sequences are evaluated before evaluation of functions/variables evaluation.

Some examples of prompt using this script:

mpapis@papis:~/old_laptop/nicz-projects/content2:master> touch a
mpapis@papis:~/old_laptop/nicz-projects/content2:master[dirty]> git add .
mpapis@papis:~/old_laptop/nicz-projects/content2:master[uncommited]> git commit -m "added a file"
mpapis@papis:~/old_laptop/nicz-projects/content2:master(ahead)>git push origin master
mpapis@papis:~/old_laptop/nicz-projects/content2:master>

To make it more useful the prompt is also colored to distinguish between states of git repo.

For lazy users the script could be also replaced by very easy version, which prints git status before each prompt line (only where git is applicable):

export PS1='$(git status 2>/dev/null)\[33[0m\]\n$(ppwd \l)\u@\h:\[33[33m\]\w\[33[0m\]>'

Note: download the code from here http://niczsoft.com/files/2010/05/my-git-prompt.txt

Categories: Development, Linux Tags: , ,

opensuse 11.2 kde 3.5 is alive

February 4th, 2010 Comments off

in previous entry(opensuse 11.2 kde 3.5) I have described how it was possible to build my distro with opensuse 11.2 and kde 3.5,

right now I’m using my new distro :) and I’m quite happy with it, it’s almost ready to be used, only few changes needed to make it reproducible

I have found tutorial which describes how to use susestudio.com

I will try to release a dump of my installed apps so anybody can build his own (kde 3.5) distro but basing on my experience in this area :)

Categories: Linux Tags: , ,

opensuse 11.2 kde 3.5

February 3rd, 2010 2 comments

Did you ever dreamed of you own distribution, I know some of you did like me.
Now this becomes easily accessible to everybody with some knowledge what he wants.

Returning to theme of the article while searching for opensuse 11.2 and kde 3.5 I found worth trying one of novel services: http://susestudio.com

So gathering information from around the web and my previous trials of this configuration I did added plenty of repositories, my favorite packages to my new appliance … after some tries I was able to finally build my distribution, that’s quite orginall that I could build whole distro without using anything else then my browser.
But guess how I was surprised when under my fresh build distro I found link testdrive – I dont need anything then browser not only to create an distro, I can also test it within browser.
Ofcourse there are limitations of this site:

  • max 15GB can be stored
  • builds older then 7 days are automatically deleted
  • single testdrive can be maximally run for one hour

Does any of this limitations concern anybody? It is always possible to recreate deleted appliance, you can always launch new session of testdrive to get another hour, and 15GB – it’s a free of charge service
You can always download kiwi configuration and use it to build the distro on your machine.

Just to make it more real here is screenshot from my browser:
opensuse 11.2 kde 3.5
I’m really excited to test my new diostro on my new laptop tomorrow, probably I will write something more on it :)

Did You liked this post or maybe not, vote on it at dzone.

Categories: Linux Tags: , , ,

openSUSE rescue CD get yast running

January 9th, 2010 Comments off

As everybody knows Windows does great job during installation – makes computer start only IT :)

There are many ways to make it working again with linux, my steps were:

  • boot computer from some opensuse CD (should be possible with any)
  • select rescue bootmenu entry
  • if asked for user enter “root”
  • enter “fdisk -l” to see yours linux device – for me it was /dev/sdb3 – first one with Id 83
  • prepare access to your system

    mount /dev/sdb3 /mnt
    mount -o bind /dev/ /mnt/dev/
    mount -o bind /proc/ /mnt/proc
    chroot /mnt/ /bin/bash
    mount /sys

  • now enter “yast2 bootloader”
  • select Other (Alt+e) -> Propose new configuration (Alt+p), OK (Alt+o)
  • exit chroot with “exit” and restart computer with “reboot”

steps up to chroot are know and are quite similar to installation of gentoo system, but “mount /sys” is something new and is required to make “yast2 bootloader” or “yast2 disk” working in chroot environment.

Categories: Linux Tags: , , , , ,