Bootstrap Script for rbenv & ruby-build

I’m currently playing around with Rails Apps in virtual environments. To get started, i threw together a little script.

Update: Available as Gist now. Found some stupid things. Will update as needed.

#!/bin/bash
set -e # exit on error
### README
# * built for Ubuntu (Lucid Lynx)
# * uses GIT via SSH because of !@#$% proxy at work
# * installs your desired ruby version (1.9.2-p290 per default) using rbenv
# ** including openssl (needed by bundler)
# ** including sqlite (probably needed for rails apps)
#
# Before you start:
# * put ssh-keys in place
# * $ ssh git@github.com
# * If you're behind a proxy, be sure to set $http_proxy etc!
#
# After the Script has run:
# * reload your .profile
### /README

### CONFIG
# Ruby Version to install
RBVER='1.9.2-p290'
### /CONFIG

PROFILE=~/.profile
# update system, just in case
sudo aptitude update
#sudo aptitude full-upgrade

# install some dependancies
sudo aptitude install -y \
  build-essential zlib1g-dev \
  sqlite3 libsqlite3-dev \
  libssl-dev openssl \
  libreadline-dev \
  curl wget git-core

# build-essential zlib1g-dev  required to install ruby
# sqlite3 libsqlite3-dev      required for sqlite gem
# libssl-dev openssl          required for openssl extension
# libreadline-dev             required for IRB
# curl wget git-core          can i haz tools?

cd
### Install rbenv
test -d ~/.rbenv || git clone git@github.com:sstephenson/rbenv.git ~/.rbenv
# modify $PATH and autoload rbenv
grep 'rbenv/bin' $PROFILE &>/dev/null || echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $PROFILE
grep 'rbenv init' $PROFILE &>/dev/null || echo 'eval "$(rbenv init -)"' >> $PROFILE
# reload shell
source $PROFILE

### Install ruby-build
test -d ~/ruby-build || git clone git@github.com:sstephenson/ruby-build.git ~/ruby-build
cd ~/ruby-build && sudo ./install.sh

### Install Ruby
rbenv install $RBVER --with-openssl-dir=/usr/local
# reload binaries
rbenv rehash
# set as default version
rbenv global $RBVER

ruby -v

# set some defaults
test -s ~/.gemrc || echo 'gem: --no-rdoc --no-ri' >> ~/.gemrc
echo 'Here is your ~/.gemrc:'
cat ~/.gemrc
echo '=== end of .gemrc ==='

# install bundler
gem install bundler
rbenv rehash
grep 'BUNDLE_WITHOUT' $PROFILE &>/dev/null || echo 'export BUNDLE_WITHOUT=production' >> $PROFILE

“The MSI ” failed” when uninstalling VMware Workstation 8 on Windows 7

This has bugged me for 2 days now. There are many forum threads, KB articles and guides out there that point to the right direction, but none of them worked out for me. However, today I finally got rid of Workstation 8!

And here is what I did:

First I got the VMware installer from the VMware Homepage.
Then I opened a command prompt as a local administrator. I switched to the location of the installer, and started it in “Uninstall mode”.

C:\>cd C:\Downloads
C:\Downloads>VMware-workstation-full-8.0.1-528992.exe /x

On the dialogue I choose “Repair”. After the installer finished his work and my machine has rebooted, I was able to uninstall VMware Workstation. iWin!
Questions? Comments?

Keeping SSH-Connections open

while true; do date; sleep `rand -s $(date +%N) -M 30`; done

From `man rand`:

-s number
       the seed for the random numbers generator (default time(NULL))
-M, --max number
       the limit of the random numbers (default 32576)

By setting the seed to `date +%N` (nanoseconds) we can avoid getting multiple zeros out of rand.

How to play Minecraft via Proxy

If you google “Minecraft via proxy”, you’ll find this one:

java -Dhttp.proxyHost=yourproxyserver.com -Dhttp.proxyPort=1234 -jar minecraft.jar

However, this won’t work for current Versions. Reason: HTTPS. Solution:

java -Dhttp.proxyHost=yourproxyserver.com -Dhttp.proxyPort=1234 -Dhttps.proxyHost=yourproxyserver.com -Dhttps.proxyPort=1234 -jar minecraft.jar

Eh voila :D

(Substitute yourproxyserver.com and 1234 with your proxy server and port number)

Note for Windows Users: For Win, you have to type “Minecraft.exe” instead of “minecraft.jar” – the Rest is exactly the same!

Update: To pass proxy authentication, add this:

-Dhttp.proxyUser=someUserName -Dhttp.proxyPassword=somePassword

Project schniin.ch: First Steps

(for the beginning of Project schniin.ch see here)

So I’ve set up a basic WordPress installation and showed her where to log in. From there she found her way on her own, has choosen a nice theme (well, it’s purple, but hey, way better than the default theme! ;-) ), customized the page a bit and has already written two blog posts. Not bad for a beginner!

There was an issue with the theme selection. Unfortunately, she picked an outdated one, which displayed some nasty error messages instead of her blog posts…. resulting in my girlfriend telling me “Oops… I think i already broke it :-(

So after half a week I’m pretty impressed how easy-to-use WordPress seems to be! It’s no big deal for geeks like me, but for people usually crafting pricing spreadsheets in Excel it’s not bad! ;-)

Update

It’s not WordPress being easy-to-use, it’s me bein intelligent! :-)

Oh sorry, should have known this! :-)

Bash: SED Cheat Sheet

Kleine Zusammenfassung zum Thema SED (Stream EDitor).

Standardaufruf

[cc lang="bash"]sed COMMAND /PATH/TO/FILE[/cc]
Liest File, wendet COMMAND an und gibt aus nach stdout.

Wichtige Parameter

       -i[SUFFIX], --in-place[=SUFFIX]
              edit files in place (makes backup if extension supplied)

Standardmaessig wird nach stdout ausgegeben. Mit -i wird statdessen die Datei direkt bearbeitet (und allenfalls ein Backup angelegt)

       -r, --regexp-extended
              use extended regular expressions in the script.

Wichtig fuer das ganze Regex-Zeugs…

Zeilen Modifizieren

[cc lang="bash"]sed -i “s/search/replace/” /path/to/file[/cc]

Zeilen aus File entfernen

[cc lang="bash"]sed -i “/pattern/d” /path/to/file[/cc]
Achtung: Löscht jeweils die GANZE Zeile!

Und so weiter… Das ist mal ein Anfang, bin offen fuer Aenderungen und Erweiterungsvorschlaege.

Bash: Befehl X mal ausfuehren

[cc lang="bash"]for i in {1..10}
do
echo “Welcome $i times!”
done[/cc]

Falls ich das wieder vergessen sollte. Wichtig: GESCHWUNGENE Klammern!

Nachtrag auf Anfrage:
Der Einzeiler sieht dann so aus:
[cci lang="bash"]for i in {1..10}; do echo “Welcome $i times!”; echo “Noch ein Befehl”; done[/cci]

Linux: Ext3-Partition verkleinern

Problem

Die Partition [cci]/dev/mapper/vgdata-lvmusic[/cci], gemountet unter [cci]/data/music[/cci] ist zu gross und soll darum verkleinert werden.

Lösung

Zuerst muss das Dateisystem ausgehaengt werden. Online kann nur vergroessert werden.
Aushaengen geht mit
[cc lang="bash"]umount /data/music[/cc]
Falls eine Fehlermeldung (“umount: /data/music: device is busy”) erscheint, sind offenbar noch Dateien auf der entsprechenden Partition geoeffnet. Offene Dateien kann man sich mit
[cc lang="bash"]lsof | grep /data/music[/cc]
anzeigen lassen.

Ist das Dateisystem erst mal ausgehaengt, muss man noch einen Filesystemcheck laufen lassen. Anschliessend kann das Filesystem verkleinert werden:
[cc lang="bash"]# Den File System Check:
e2fsck -f /dev/mapper/vgdata-lvmusic

# Und verkleinern:
resize2fs -p /dev/mapper/vgdata-music 10G[/cc]
Anschliessend sollte das Dateisystem nochmals ueberprueft werden (nochmals e2fsck….)

FERTIG!

(Die Partiton muss natuerlich wieder gemountet werden: [cci lang="bash"]mount /dev/mapper/vgdata-lvmusic /data/music[/cci])

Linux: Filesysteme mit LVM online vergrössern

Problem

Unsere Ausgangslage ist ein Linux Server (hier: SLES10) mit LVM eingerichtet. Die Partitionstabelle schaut so aus:

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/system-root
                       14G  4.1G  8.9G  32% /
udev                  377M  136K  376M   1% /dev
/dev/sda1              69M  9.6M   56M  15% /boot

Nun haben wir aber ein Platzproblem, die Platte laeuft langsam voll. Zum Glueck haben wir vorausgedacht: auf /dev/sda haben wir noch 5GB ungenutzten Speicherplatz. Diesen wollen wir nun ebenfalls / zuweisen.

Lösung

Hinweis: Auch wenn diese Anleitung mit einem SLES10-System erstellt wurde (sorry, da kann ich auch nix dafuer, die Distributionswahl ist nicht in meiner Entscheidungsgewalt :P ) sollte sie fuer die meisten Linux-Distributionen gueltig sein.

Dann mal los:

Freien Speicherplatz partitionieren
Zuerst muss der freie Speicherplatz als “Linux LVM” partitioniert werden. Die ID fuer diesen Partition Type ist 8e.

Wichtig: Anschliessend muss die Partitionstabelle neu eingelesen werden, sonst ist die neue Partition nicht sichtbar. Der Befehl dazu: partprobe

Physical Volume erstellen und in VG einbinden
Weiter gehts mit ein paar LVM-Befehlen: Zuerst muss in der neuen Partition (hier: /dev/sda5) ein sog. Physical Volume eingerichtet werden:

tteam01:~ # pvcreate /dev/sda5
  Physical volume "/dev/sda5" successfully created

Sodele, fast am Ziel.

Das bestehende Volume vergroessern
Dazu muss die neue Partition zuerst der VG zugewiesen werden.

tteam01:~ # vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  system   1   2   0 wz--n- 14.93G 28.00M
tteam01:~ #
tteam01:~ # vgextend -v system /dev/sda5
    Checking for volume group "system"
    Archiving volume group "system" metadata (seqno 3).
    Adding physical volume '/dev/sda5' to volume group 'system'
    Wiping cache of LVM-capable devices
    Volume group "system" will be extended by 1 new physical volumes
    Creating volume group backup "/etc/lvm/backup/system" (seqno 4).
  Volume group "system" successfully extended
tteam01:~ #
tteam01:~ # vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  system   2   2   0 wz--n- 19.92G 5.02G

Und nun muss noch das LV vergroessert werden. Wir vergroessern das LV hier einfach auf die maximale Groesse:

tteam01:~ # lvextend -v -l +100%FREE /dev/system/root
    Finding volume group system
    Archiving volume group "system" metadata (seqno 10).
  Extending logical volume root to 18.82 GB
    Creating volume group backup "/etc/lvm/backup/system" (seqno 11).
    Found volume group "system"
    Found volume group "system"
    Loading system-root table
    Suspending system-root (253:0)
    Found volume group "system"
    Resuming system-root (253:0)
  Logical volume root successfully resized
tteam01:~ # vgs
 VG     #PV #LV #SN Attr   VSize  VFree
 system   2   2   0 wz--n- 19.92G    0

Aha, aus unsern ~15GB sind ~20GB geworden. War einfach, nicht? Aber wir sind noch nicht ganz fertig!

Die bestehende Partition vergroessern
Die Root-Partition ist nun aber immer noch auf der alten Groesse, wir haben ja nur das LV vergroessert. Auch das ist kein Problem:

tteam01:~ # ext2online -d /dev/mapper/system-root
[... viel viel Text ...]
tteam01:~ # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/system-root
                       19G  4.1G   14G  23% /
udev                  377M  136K  376M   1% /dev
/dev/sda1              69M  9.6M   56M  15% /boot

Das wars! Cool, nicht?

Howto: Disk-Images erstellen unter Linux

Aus aktuellem Anlass: Wie erstelle ich von meiner Disk ein (komrpimiertes) Image?

Update: Anstatt mit dd lässt sich das auch mit Umleitungen machen! Siehe Variante 2.

Ausgangslage:

Angenommen ich will meine /boot-Partition sichern, bzw ein Image davon erstellen.
[cc lang="bash"](14:14)mhutter@ganymede:~$
df -h
Filesystem            Size  Used Avail Use% Mounted on
*schnipp*
/dev/md0              221M   31M  179M  15% /boot[/cc]
Hinweis: Die meisten dd-Befehle müssen mit Root-Rechten ausgeführt werden.

Variante 1: Ohne Komprimierung

(NICHT empfohlen)
[cc lang="bash"](14:21)root@ganymede:~#
dd if=/dev/md0 of=/backup/boot.img bs=4M
58+1 records in
58+1 records out
246611968 bytes (247 MB) copied, 0.366272 s, 673 MB/s
(14:22)root@ganymede:~#
ls -lah /backup
total 236M
-rw-r–r– 1 root root 236M 2009-10-30 14:22 boot.img[/cc]
Das ging zwar sehr schnell (0,3sek), aber das Image ist so gross wie die ganze Partition! Klar kann man nachträglich noch gzippen oder so, aber ich bevorzuge

Variante 2: Direkt komprimieren

(empfohlen!)
[cc lang="bash"](14:24)root@ganymede:~#
dd if=/dev/md0 | gzip -c > /backup/boot.img.gz
481664+0 records in
481664+0 records out
246611968 bytes (247 MB) copied, 3.52991 s, 69.9 MB/s
# NACHTRAG! Das geht auch einfacher!
# Das Ergebnis ist genau dasselbe:
gzip -c < /dev/md0 > /backup/boot.img.gz
# Ende Nachtrag
(14:25)root@ganymede:~#
ls -lah /backup
total 29M
-rw-r–r– 1 root root 29M 2009-10-30 14:25 boot.img.gz[/cc]
Das hat jetzt zwar rund 10mal länger gedauert, aber siehe da: Das Image ist nur noch 29MB gross! Win!

Zusatzinfo

Images entpacken und mounten

Das Entpacken klappt einfach mit [cci]gunzip boot.img.gz[/cci] Und so wird nachher gemountet:
[cc lang="bash"]mount -o loop /backup/boot.img /mnt/boot/
# Manchmal muss man auch den Dateisystemtyp angeben:
mount -o loop -t ext2 /backup/boot.img /mnt/boot/[/cc]