Archive

Posts Tagged ‘Linux’

Cygwin with Tabs using Console(and still portable)

I recently found a way to use tabs with cygwin wich reduces the clutter in your taskbar. You can easily use Console to achieve this, unfortunally the instructions around the web assume your cygwin is installed in the default manner (not portable, not using rxvt as an emulator) so those of you using my instructions to set up a portable cygwin instalation will have a hard time getting Console to work with cygwin.

To use Console just make sure to set up the shell execution path to call /bin/bash and not rxvt.

In the spirit of keeping things portable you need to do the following:

  • just edit your bat file and edit the last line:

%WD%\bin\run %WD%\bin\rxvt.exe -geometry 140×40 -sl 1500 -fn “Courier New” -bg black -fg grey -sr -e %WD%\bin\bash –login -i

to

%WD%\bin\bash –login -i

  • move all Console files to the cygwin folder (same folder as CygwinPortable.exe)
  • make sure the path defined in the Console settings is relative(If you have trouble doing this just edit the console.xml file by hand):

Shell: “\App\Cygwin\cygwin.bat”

Startup Dir: “.”

Console changes some of the window behavior but you can work around that by changing the settings:

  • Mark Settings>Behavior>copy on select
  • Mark Settings>Behavior>Clear selection on copy
  • Settings>Hotkeys>Select Rename Tab on the list > hit the clear button (this will make sure you can use the bash history)
  • There might be some mouse configurations i forgot that you can change.

Links :

Cygwin Portable – (some) Linux power on a USB for Windows

January 29, 2010 6 comments

The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the POSIX system calls and environment these programs expect.

With these tools installed, it is possible to write Windows console or GUI applications that make use of significant parts of the POSIX API. As a result, it is possible to easily port many Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software (including the packages included with the Cygwin development tools themselves) as well as lots of BSD tools and packages (including OpenSSH). Even if the development tools are of little to no use to you, you may have interest in the many standard POSIX utilities provided with the package. They can be used from one of the provided Unix shells like bash, tcsh or zsh, as well as from the standard Windows command shell if you have to for some sad reason.

From Cygwin FAQ

If you google Cygwin Portable you will find several solutions:

The one that actually worked for me came from the SourceForge project called CygwinPortable. This version is designed to work with the software bundle PortableApps, but you could use it yourself outside the bundle (see bellow).

To install this software under the bundle just extract the zip file into your PortableAps folder, and on the gui launcher click on Options->Refresh App Icons. You will see two icons appear : one launches cygwin the other launches the setup.

I had some issues getting it to work as i wanted:

Subversion information

it seems the project mantainer packaged the software with svn files, you will need to remove all .svn folders from the exploded contents. I used SVN Cleaner for that.

Outdated setup.exe

The project seems to be unmaintained for some time now. Since that time a new version of cygwin came out which changed how setup.exe and setup.ini work. If you want to update or install new Cygwin packages you will need to download setup.exe from the cygwin page (see bellow for links) and replace the file cygwinsetup.exe in CygwinPortable\App\Cygwin\setup\ with the download one, i would advise you to replace it with a renamed version of the one download if you are using Portable Apps since the portable Apps link runs the original exe file. After doing this you can update and install new cygwin software without a hinch.

Cygwin is locked to the drive you updated it on

After i updated some packages on my cygwin my shell window changed into a normal cmd dos windows, which besides being ugly had the huge disadvantage of not allowing me to copy and paste with a single click. I set out to find a solution and it came in the form of rxvt. %Explain rxvt%. The problem was in my cygwin.bat file.

If you go into CygwinPortable\App\Cygwin you will find a file named cygwin.bat. This batch file is responsible for starting up cygwin. For some reason this file will be changed when you update your cygwin version and (after the setup) it will look something like bellow:

@echo off
F:
chdir F:\Software\Bin\PortableApps\CygwinPortable\App\Cygwin\bin
bash --login -i

the above just runs bash.exe from your cygwin bin dir. And worse it just locked your instalation of cygwin back to the current computer (see the two lines bellow @echo off).

In order to solve this all you have to do is open the cygwin portable zip file you downloaded and replace your cygwin.bat with the one provided in there. This will be able to determine the folder you are running CygwinPortable.exe from and open up your rxvt window.

For those of you wanting to use cygwin outside the PortableApps bundle all the above steps apply, but unfortunally there is some other work you need to do:

  1. All you need to work with cygwin is the folder “CygwinPortable\App\Cygwin” so pull that out
  2. To run cygwin you will need to execute the cygwin.bat file inside that folder. But this file is configured to be run by the CygwinPortable.exe file and not on its own. So to get it to run on is own you will need to change the first line of the script to
for /F %%A in ('cd') do set WD=%%A

Notice i only removed the last part of the line which was telling the batch file where the cygwin base folder was. Since with Portable Apps we run CygwinPortable.exe the base folder would be the file execution folder (\CygwinPortable\) plus “App\Cygwin”. But when running the batch file directly the base folder becomes the batch file execution folder. Ok this part was confusing, if you have any doubts let me know and i’ll revise this part

Enjoy your new powers.

External Links:

Linux File Permissions

November 12, 2009 Leave a comment

I’ve allways struggled with how the linux permissions work. Recently i had another one of those times where i had to change a folders permission recursively so, once again, i googled it. The 5th result is a Google Code University Lab which actually explained it in a way i could get.

This post is a simple sumary of the lab.

When you do an ls -l on your console you will see something like the following

drwxr-xr-x. 2 sapiens sapiens 4096 2009-10-19 14:20 Desktop
drwxr-xr-x. 2 sapiens sapiens 4096 2009-10-07 23:55 Documents
-rwxr-xr-x. 3 sapiens sapiens 4096 2009-11-05 18:42 myStuff.txt

If you look at the start of the line you will notice a bunch of letters, they are actually 10 of them. At first when you are getting into linux these will seem like gibberish to you and you will basicly ignore them, but when you need to actually change the folders permissions you might want to try and learn how to read them.

The letters on that text means the following :

  • d – directory;
  • r – read granted;
  • w – write granted;
  • x – execute granted;
  • – Not granted.

Tha piece of text can be divided in 4 groups (1st group composed of the first caracther, then 3 groups of 3 characters each) :

  1. first letter states wether the file is a folder or not (if it has a ‘d’ its a directory);
  2. the next 3 letters states the permissions for the file Owner
  3. The next 3 letters states the permissions for the Group
  4. the last 3 letters states the permissions for Everyone

So you’ve learned how to read it, but how do you change it well basicly you will be using chmod for that (just man it). As for the arguments you can either write the whole text for the given file or use the short hand.The following table shows you how to use short hand version to give permissions:

Number Read (r) Write (w) Execute (x)
0
1 x
2 w
3 w x
4 r
5 r x
6 r w
7 r w x

Note: The above table was directly taken from the google lab, it also presents a good way to remember this table

 

In order to change a files permission you would write a 3 digit number, using the table above,  that defines the permissions for the groups mentioned above (owner, group, everyone else) for instance:

  • 644 would change a file/folder pemission to be read-only to everyone but the owner which would have full permissions
  • 755 (probably one of the most used) would make the file executable and readable to everyone and full permissions to the file owner.

 

External Links :

VirtualBox Share Folders with Guest Machine

November 2, 2009 1 comment

VirtualBox has a nifty feature that allows you to share folders with your guest machines. This will make a specific folder of you host machine avaible to your guest.

Though the menu option is clearly visible its actually hard to understand how this all works, especially if (like me :D) you are expecting it to magicly appear on your guest OS.

The initial sharing operation is as simple as can be :

  • Just jump to Shared folders menu option;
  • Add a new Folder (choose if its temporary or not);
  • Give the path to the folder and the share name.

Now the way you access this in your guest machine depends on the Operating System you are running. Mind that you will need to install the Guest Additions in order to share folders.

For windows guest the folder will be avaible automaticly but you will need to navigate to your network places and find “VirtualBox Shared Folders”. I had to go to Network Places -> Entire Network -> VirtualBox Shared Folders, and your share should be there.
For Linux Guest (works with Ubuntu and Fedora) you will need to mount the share in order for it to be acessible. So you will do the following :

  1. Create a directory where you wish to mount your share (let’s name it myshare);
  2. execute the command sudo mount.vboxsf MyShare /path/to/myshare.

Note that mount.vboxsf has no spaces. Above MyShare would be the name you gave your shared folder in the VirtualBox GUI. After that your share will be mounted on /path/to/myshare.

References :

Categories: Linux, Virtual Box Tags: , ,

Change root password in Linpus

February 11, 2009 3 comments

Linpus asks you to input the root password on the first boot. in order to change this password open up a terminal (Alt-F2 and enter xterm into the dialog that appears) then run “sudo su” to change to root user and use the command “passwd” to change your password.

A note to people who dont use linux that often, after you run the command to change the password it will ask you to input the password twice, while you type the password nothing will change in the console, no dots or words appear as you type. This is standard procedure, just input your password normally.

GNU Screen shortcuts

December 18, 2008 1 comment

I got tired of having a bunch of xterm windows running around on my Aspire One, so i decided to try GNU Screen. The Aspire One uses Linpus Linux , to install it all i had to do was :

sudo yum install screen

after the reboot i tried running screen but nothing happened (or so i thought). well time to jump to the web and find out…. a few minutes, and a couple of links later i found out that when i run screen nothing is supposed to happen ( nothing apparent at least), and all i had to do was start using it.

So here are the bits of information i gathered:

Screen uses the command “Ctrl-A” as a signal to send commands to screen instead of the shell.

Here are a few commands i found usefull:

  1. C-a c  – Creates a new screen shell where you can run your commands
  2. C-a n or C-a p – Move to the next or the previous screen
  3. C-a ” – List the existing screens
  4. C-a S – Split the screen in two
  5. C-a TAB – Switch between split screens
  6. On a  given screen terminal run “screen command name”  – opens a new screen running the given command and names it “name”

References:

Categories: Linux Tags: , ,

Setup ZTE MF622 USB Modem in Linux

December 2, 2008 4 comments

Recently I found myself needing to install a 3g Modem for a Portuguese Service Provider (TMN). When i tried plug in the modem in all it did was deploy a new USB drive showing me the contents of what seemed to be the windows installer for the manager application. After a little digging around i found the solutions for my troubles. This post shows the solution i found. this is how i got it to work, I’m not saying its the best and I’m sure its not the only one.

Getting Linux to detect the 3g modem side of the device instead of the USB pen side

This device works as two devices in one. In windows when you plug the modem in it first mounts a hard-drive/cdrom in order to install the drivers and applications for the modem. it later removes this drive and installs itself as a modem. this last part is done by the installer so in Linux this last part never happens when you plug in the modem. What you need to do is force the system to ignore the usb pen drive side of the device.

In order to do this you need to create a file named “15-zte-mf622.rules” and put it in : “/dev/udev/rules.d” (warning you need root privileges in order to do this)

Put the following content in this file you just created:

ACTION!=“add”, GOTO=“ZTE_End”

# Is this the ZeroCD device?

SUBSYSTEM==“usb”, SYSFS{idProduct}==“2000”,

SYSFS{idVendor}==“19d2”, GOTO=“ZTE_ZeroCD”

# Is this the actual modem?

SUBSYSTEM==“usb”, SYSFS{idProduct}==“0001”,

SYSFS{idVendor}==“19d2”, GOTO=“ZTE_Modem”

LABEL=“ZTE_ZeroCD”

# This is the ZeroCD part of the card, remove

# the usb_storage kernel module so

# it does not get treated like a storage device

RUN+=“/sbin/rmmod usb_storage”

LABEL=“ZTE_Modem”

# This is the Modem part of the card, let’s

# load usbserial with the correct vendor

# and product ID’s so we get our usb serial devices

RUN+=“/sbin/modprobe usbserial vendor=0x19d2 product=0x0001”,

# Make users belonging to the dialout group

# able to use the usb serial devices.

MODE=“660”, GROUP=“dialout”

LABEL=“ZTE_End”

Note: this is the configuration for the ZTE MF622 modem.

After you have created this file run the following command, this will reload the device rules:

udevcontrol reload_rules

This rules file prevents the system from mounting the USB drive side of the device, but this constitutes a problem. Now your system wont be able to recognize USB hard drives. Don’t fret this can be solved by removing the file and reloading the rules. More on this further down the road.

If you connect your modem at this point you will see that the system now installs it as a modem and you can find it in “/dev/ttyUSB0“.

You can now use your favorite dialer (wvdial, UMTSmon, …) to connect using this device.

The ability to connect thumb drives again.

After deploy the above rules file and reloading your rules you will lose the ability to connect thumb drives to the system. All you have to do to be able to use them is remove the file and reload the rules. I got the following solution from a comment by Dorothy Hyde to the post i mention in the reference part of this article:

1. Create a folder called “/udv-rls” and put the above rules file inside it

2. Create a bash script called 3up with the following code:

#!/bin/bash

cp -v /udv-rls/15-zte-mf622.rules /etc/udev/rules.d/

devcontrol reload_rules

# end of script.

3. Create a bash script called usf with the following code:

#!/bin/bash

rm -v -f /etc/udev/rules.d/15-zte-mf622.rules

udevcontrol reload_rules

#end of script

Now before you plug in the modem run 3up, and after the system has detected the modem run usf.

Connecting to the web:

After the system has detected your modem you now have to be able to connect. I tried using wvdial and all i managed was to get my modem blocked. No matter what i tried i could never get it to connect. So i resorted to UMTSmon. You can get binaries and source from here .

After you install it you can run UMTSmon to dial in. I ran into some trouble at this point:

  • UMTSmon did not detect the modem unless i ran it with root privileges – basically in order to use the installed devices you need to add your self to the uucp group. So you need the run the following commands:

usermod -a -G uucp username

  • If you run UMTSmon without root privileges pppd will ask for root when trying to connect – You need to SUID pppd. I found the following on this matter (Reference).

Because PPP needs to set up networking devices, change the kernel routing table and so forth, it requires root privileges to do this.

If users other than root are to set up PPP connections, the pppd program should be setuid root

-rwsr-xr-x 1 root root 95225 Jul 11 00:27 /usr/sbin/pppd

If /usr/sbin/pppd is not set up this way, then as root issue the command:-

chmod u+s /usr/sbin/pppd

You should now be able to connect to the Internet using your ZTE MF622 modem.

These are the configurations i had to use in UMTSmon in order to connect (these configurations work for TMN – Portuguese Service Provider).

UMTSmon Preferences

UMTSmon Preferences

I created the following bash script which i run before plug in in the modem, it basically automates the above process. Mind that you might be required to run it using root privileges.

#!/bin/bash

rulesFileName=”15-zte-mf622.rules”
rulesFileOriginalPath=”/udv-rls/${rulesFileName}”
rulesFileDir=”/etc/udev/rules.d/”

clear
echo “******************************”
echo “* ZTE MF622 – Startup Script *”
echo “*                            *”
echo “* Developed by NFurtado      *”
echo “* Date: 02/12/2008           *”
echo “******************************”
echo “”
#copy the rules and reload the udev
echo “Copying the rules file to $rulesFileDir”

cp $rulesFileOriginalPath $rulesFileDir || { echo “ERROR: Rules file could not be copied. Script exiting.”;  exit 1; }
echo “Reloading Rules”
/sbin/udevcontrol reload_rules || { echo “ERROR: Rules could not be reloaded. Script Exiting.”; exit 1;}

#output connect modem
echo “Please connect 3g Modem.”
echo “Waiting for modem…”

#loop and wait for modem to be connected
while [ -z $ttyGrep ]
do

ttyGrep=`ls  /dev/ |grep ttyUSB0`

done

echo “Modem Detected”
echo “Cleaning up:”

#remove rules file and reload rules
echo “Removing rules file from ${rulesFileDir}”
rmCommand=”${rulesFileDir}/${rulesFileName}”

rm -v -f $rmCommand || { echo “ERROR: Rules file could not be Removed. Remove it manually.”;}
echo “Reloading Rules”
/sbin/udevcontrol reload_rules  || { echo “ERROR: Rules could not be reloaded. Script Exiting.”; exit 1;}
echo “”

echo “Modem is Setup. Use your favorite Dialer to connect.”

exit 0

As i said before I’m a newbie in these affairs so take the above instructions and scripts with a grain of salt. If you see any inconsistencies or errors just let me know

References

  1. http://tldp.org/HOWTO/PPP-HOWTO/root.html
  2. http://blog.ufsoft.org/2007/11/30/zte-mf622-usb-modem-under-linux
Categories: Linux Tags: , ,