2007/01/18

Update: Bash-only Linux

This is an update to this old article, which works on Fedora Core 6.

Copy this script into a file, modify the grub entries with your system parameters, run it and enjoy using a dummy linux where you can only write "help", and some useless commands... swear next it'll include the nvidia driver.

#!/bin/bash -v
# Bash only filesystem on a file - rodolfoap@gmail.com

# Create an empty file
dd if=/dev/zero of=/tmp/embed bs=2k count=4k

# Make an ext2fs
/sbin/mkfs.ext2 -v -F -b 2048 /tmp/embed

# Mount it as a loop
mkdir -p /mnt/embed
mount -v /tmp/embed /mnt/embed -o loop -t ext2
cd /mnt/embed

# Create basic structure and fill it with needed files
mkdir bin dev lib
cp -av /dev/tty /dev/console /dev/ram dev/
cp -v /bin/bash bin/
# to found libs needed by bash, use # ldd /bin/bash
cp -v /lib/libtermcap.so.2 lib/
cp -v /lib/libdl.so.2 lib/
cp -v /lib/libc.so.6 lib/
cp -v /lib/ld-linux.so.2 lib/

# Create boot file
cd /tmp
umount -v /mnt/embed
gzip -v < embed > /boot/embed.gz

# Add entry in grub: change root and kernel line with your parameters
cat >> /etc/grub.conf << "EOF"
title Bash Only Filesystem
root (hd0,0)
kernel /vmlinuz-2.6.18-1.2869.fc6 ro root=/dev/ram ramdisk_blocksize=2048 init=/bin/bash
initrd /embed.gz
EOF

# Manually correct grub parameters
read -p "Press ENTER to start editing grub.conf..."
vi /etc/grub.conf

# End script. Reboot with "init 6" and choose the BASH option in GRUB.
# Toto: sos un mostro, thnx.

2006/04/09

The SED beauty

Sed is one of the unix beauties. Simple, standard, absolutely
text/driven, and overall, powerful as The Brain. Look at the examples.

Simple replace:

# sed -e 's/en_US/es_ES/g' /etc/sysconfig/i18n

Replace only on determined lines:

# sed -e '/disable/s/yes/no/' /etc/xinetd.d/pop3s

Adding after a line:

# sed -e '/ListenAddress ::/a\AllowUsers root' /etc/ssh/sshd_config

Deleting a line:

# sed -e '/only_from/d' /etc/xinetd.d/swat

Making a backup, just with "-i"

# sed -i.bak -e '/\/AutoPPP/s/\#//' /etc/mgetty+sendfax/login.config

Replace spaces on start lines:

# sed 's/^ *//' file

More than 2 spaces with one:

# sed 's/[ ]\{2,\}/ /g' file

This is my precious, my ring: Once we have to replace this text...

old: {pdf=FILE text=TEXT}
new: {pdf=FILE title=FILE text=TEXT}

... on *THOUSANDS* of "page.txt" files in a BIIIG directory tree! Of
course, "FILE" and "TEXT" were different on each. With a little help
from my friends Sed and Find, took just a minute:

# find . -name page.txt -print -exec \
> sed -i -e \
> "s/{pdf=\(.*\?\) text=\(.*\?\)}/{pdf=\1 title=\1 text=\2}/g" "{}" \;

Note: ".*" is a GREEDY expression (RT regex FM). To avoid GREEDINESS,
you should use ".*?"

Beautiful.

2006/03/11

Running Tomcat!

How to install TOMCAT on Fedora:

a) Tomcat Itself
yum install tomcat5
yum install tomcat5-webapps
yum install tomcat5-admin-webapps

a2) install java from SUN (could be using Fedora Frog)

b) Change on /etc/tomcat5/tomcat5.conf

JAVA_HOME="/opt/jre1.5.0_06"
(or which suits)

c) In /etc/tomcat5/tomcat-users.xml, put manager/admin roles to tomcat
user:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="manager,admin"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

d) Start service:

# service tomcat5 start

e) Browse http://localhost:8080/

;)