03 August, 2007

HowTo fix command history in mc under Ubuntu

The program which I setup first of all after the Linux installation is mc (Midnight Commander).
It is very friendly and useful for me.

But in Ubuntu there is one problem with mc: shell's commands history is flooded with a garbage and with many ESC-symbols when I use mc.

E.g.:

cd "`echo -e '\057usr'`"
cd "`echo -e '\057usr\057X\061\061R\066\057bin'`"
cd "`echo -e '\057home'`"


I found the way how to fix this problem.
In the file .bashrc string:
export HISTCONTROL=ignoredups
should be replaced with:
export HISTCONTROL=ignoreboth

01 August, 2007

HowTo convert Windows or DOS text to Linux

If you write text file in Windows, it won't be displayed correctly in Linux, because Windows' editors add carriage return symbol (\^) to the end of each line.
I wrote very simple (but useful) script to migrate text files from Windows to Linux.
Here it is:


dos2linux.sh

#!/bin/bash

cat $1 | tr -d '\r' >$1.fixed


Command "./dos2linux.sh text.txt" reads file "text.txt" and writes fixed file to "text.txt.fixed".

It works on Linux/Unix platforms or under Cygwin environment.

31 July, 2007

HowTo synchronize directories

Sometimes it is necessary to synchronize data between desktop computer and notebook, PC and PocketPC, main and backup server or between directories within one system.
I wrote and use script to this.
This script synchronizes one directory with another.

E.g.: if you have directory "master" with these files:
master/file1.txt
master/file2.txt
master/dir1
master/dir1/file3.txt
master/dir1/file4.txt

and if you want to synchronize it with "slave" directory,
you may type this command:
./xqx_usync.sh master slave
After execution of this command, "slave" directory will contain all files from "master":
slave/dir1
slave/dir1/file3.txt
slave/dir1/file4.txt
slave/file1.txt
slave/file2.txt


At first thought, this action looks like copy, but if files in the "master" directory is changed, then after execution of this command again, all data in "slave" will be replaced with new data from "master" directory. Also, if you add new file to the "master" directory, it will be copied into "slave". This script wraps "rsync" command, that fast and high-performance.



xqx_usync.sh

#!/bin/bash

#This script synchronizes <master> and <slave> directories.

MASTER=$1/
SLAVE=$2/

echo -n Syncing $SLAVE with $MASTER...

if test -z "$MASTER" -o ! -e "$MASTER"; then
echo "Usage: usync <master directory> <slave directory>"
exit
fi

if test -z "$SLAVE"; then
SLAVE=.
fi

rsync --archive $MASTER $SLAVE
echo OK


This script is created with Ubuntu Linux.

30 July, 2007

HowTo make Ubuntu mirror

"Ubuntu 6.06 LTS (Dapper Drake)" is my favorite OS (unfortunately, my previous favorite: "RedHat 7.2 (Enigma)" is out of date for modern hardware and software).

Ubuntu 6.06 LTS is the best solution for modern computers, because it is stable, efficient, user friendly and long term supported (Desktop Edition to 2009 and Server Edition to 2011).



But, it is necessary to have wide and persistent Internet connection for updates and installing new packages. It is a good idea to create local "hard" copy of all packages from Ubuntu's site. I wrote script for this purposes and successfully use it.

This script creates FULL (~50G) mirror of "Ubuntu 6.06 LTS (Dapper Drake)".
It downloads all binary and source packages for both i386 and amd64 platforms.



xqx_mirror_dapper.sh

#!/bin/bash -x

DATE=`date +%Y.%m.%d_%H.%M.%S.%N`
LOG=~/`basename $0`-$DATE.log
touch $LOG

if test ! -w "$LOG"; then
LOG=/dev/stdout
fi

DIST=dapper

/usr/bin/debmirror -m --passive --method=ftp --progress --host=archive.ubuntulinux.org --root=ubuntu \
--dist=$DIST,$DIST-updates,$DIST-security,$DIST-proposed,$DIST-backports \
--section=main,multiverse,universe,restricted --arch=i386,amd64 \
--ignore-release-gpg --timeout=999 $DIST |tee $LOG

/usr/bin/debmirror -m --passive --method=http --progress --host=archive.canonical.com --root=ubuntu \
--dist=$DIST-commercial --section=main --arch=i386,amd64 \
--ignore-release-gpg --timeout=999 $DIST-commercial |tee -a $LOG


If you don't need sources, you may fix this script and add "--nosource" option to the "dembirror" command. Or you may select your own platform with the "--arch=" option.

When mirror created, you should switch your system to it.
I also created script for this. Here it is:



xqx_apt_update_dapper.sh

#!/bin/bash

if test -z "$1"; then
echo "Update system from new mirror."
echo "Usage: $0 <folder with mirrors>"
exit
fi

DIST=dapper
MIRRORS=$1

cat >/etc/apt/sources.list <<EOF
deb file://$MIRRORS/$DIST/ $DIST main universe multiverse restricted
deb file://$MIRRORS/$DIST/ $DIST-updates main universe multiverse restricted
deb file://$MIRRORS/$DIST/ $DIST-security main universe multiverse restricted
deb file://$MIRRORS/$DIST/ $DIST-backports main universe multiverse restricted
deb file://$MIRRORS/$DIST/ $DIST-proposed main universe multiverse restricted
deb file://$MIRRORS/$DIST-commercial/ $DIST-commercial main
EOF

echo -e "\\033[1;32m"
cat /etc/apt/sources.list
echo -e "\\033[0;39m"

echo "Continue with 'apt-get update'? [y/n]"
read
if test $REPLY = y ; then
apt-get update
else
exit
fi

echo "Continue with 'apt-get upgrade'? [y/n]"
read
if test $REPLY = y ; then
apt-get upgrade
else
exit
fi