Monday, July 25, 2011

tipp: eclean-dist with custom DISTDIR

If you are using http-replicator you probably have all your distfiles in a seperate directory. Usually eclean-dist just cleans up the directory in the $DISTDIR variable, thus not in the directory where http-replicator stores the files. So how to clean this directory?

Solution:
DISTDIR="/home/michael/backups/distfiles/" eclean-dist

Easy i know :) I put that into my crontab, so i never have to care about old packages.

Wednesday, July 20, 2011

custom dependencies in openrc

Anyone ever searched for such a option? I did. The reason is simple. I have a really neat alix system with gentoo on it. The problem with this system is that it has no battery, means, every time you boot it up the time is set to 01012000. A good solution to update the time is via ntp-client and since its the gateway to the internet for my local network, it also has an ntpd damon for the local pcs.

Now i also run darkstat on this alix device, just for fun to see the traffic. Well, i said every time i boot it up the time is set to 01012000. The darkstat init script usually always runs before the ntp-client and thus getting the date from 2000. It's a funny because if i look at the darkstat site it shows something like "running for 4234 days, since 2000-01-01". Though that would be awesome but unfortunately its wrong.

A solution now would be to edit the darkstat init script and add to depend() "need ntp-client". It's a oneliner but it's not the correct way and with every update or reinstall of darkstat etc-update would overwrite it (though updates of darkstat are really seldom). Anyway there is a better (and correct) solution. Via /etc/rc.conf you can add/remove dependencies for any init scripts in gentoo.

The correct onliner in /etc/rc.conf is rc_darkstat_after="ntp-client"

That's all and it works perfectly.

Tuesday, July 19, 2011

new script: getlatestinstall

I play alot around with kvm, thus i also need quite often the install-cds for gentoo. Unfortunately i never use the latest install-cds because i'm to lazy to download the media first. It's not a big problem, but i wanted to have a nice solution to have always the latest install-cds. Now i wrote a small script which does the downloads for me.

The Features are:
  • check if the passed directories exist and if they are writeable
  • download the latest iso images from gentoo.distfiles.com + checksum files
  • check the md5sum of the iso-image, if failed delete the downloaded files, and try again (3 times)
  • if passed, create a link to the iso-image
  • works for amd64,x86,alpha and ia64
I think it's quite useful and i put it into my cronjobs to run it every sunday. Maybe someone else can use it too.

There is also a small discription included if you run the script without arguments. Don't forget to change the ${DOWNLOADDIR} and ${LINKSDIR} vars. Suggestions, bugs and improvements are welcome ;)

Download: Link

#!/bin/sh
# Datei: getlatestinstall
# Autor: Michael Mair-Keimberger (m DOT mairkeimberger AT gmail DOT com)

# Copyright (C) 2011  Michael Mair-Keimberger
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# Discription:
# A script which automaticly download the latest
# gentoo install cds for x86,amd64,alpha,ia64
# checks the md5sum and make symbolic links to the iso

# programs to use
MD5SUM=/usr/bin/md5sum
WGET=/usr/bin/wget
LN=/bin/ln
RM=/bin/rm
CAT=/bin/cat
TAIL=/bin/tail
MKDIR=/bin/mkdir
PING=/bin/ping

# make sure both directory are writeable for the user
# who execute this script
LINKSDIR="/home/${USER}"
DOWNLOADDIR="/home/${USER}"

usage(){
  echo "$0 arch (downloaddir) (linksdir)"
  echo "arch  > select between amd64,x86,alpha or ia64"
  echo "downloaddir > directory where the iso will be stored (optional)"
  echo "linksdir > directory where the links will be stored (optional)"
  echo "A script to download the latest minimal cd for gentoo"
  exit 1
}

cfgchecks(){
  # check if the directories exists and if there are writeable
  for checkdir in ${DOWNLOADDIR} ${LINKSDIR}; do
    if [ -d "${checkdir}" ]; then
      if ! [ -w "${checkdir}" ]; then
 echo "Directory \"${checkdir}\" is not writeable!"
 return 1
      fi
    else
      echo "Directory \"${checkdir}\" dosen't exists"
      return 1
    fi
  done

  # create arch dirctory if it dosen't exists
  if ! [ -d "${DOWNLOADDIR}/gentoo-${1}/" ]; then
    ${MKDIR} ${DOWNLOADDIR}/gentoo-${1}/ > /dev/null 2>&1
  fi

  # check if there is internet connection
  if ! (${PING} -c1 -q distfiles.gentoo.org > /dev/null 2>&1); then 
    echo "No internet connection"
    return 1
  fi
}

md5sumcheck(){
  cd ${DOWNLOADDIR}/gentoo-${1}/

  if [ `${MD5SUM} -c --status ${DOWNLOADDIR}/gentoo-${1}/*.DIGESTS` ]; then
    ${RM} ${DOWNLOADDIR}/gentoo-${1}/*
    echo "md5sum check failed"
    return 1
  else
    # -f because if a link already exists it has to be forced
    ${LN} -s -f ${DOWNLOADDIR}/gentoo-${1}/*.iso ${LINKSDIR}/gentoo_${1}
  fi
}

download(){
  # download the txt file which points to the latest minimal cd
  ${WGET} -q -P/tmp/ http://distfiles.gentoo.org/releases/${1}/autobuilds/latest-install-${1}-minimal.txt
  LATEST_ISO=`${CAT} /tmp/latest-install-${1}-minimal.txt | ${TAIL} -n 1`
  ${RM} /tmp/latest-install-${1}-minimal.txt > /dev/null 2>&1
  ${RM} ${DOWNLOADDIR}/gentoo-${1}/* > /dev/null 2>&1

  # download the latest iso with the checksum files
  ${WGET} -q -P${DOWNLOADDIR}/gentoo-${1}/ http://distfiles.gentoo.org/releases/${1}/autobuilds/${LATEST_ISO} \
    http://distfiles.gentoo.org/releases/${1}/autobuilds/${LATEST_ISO}.CONTENTS \
    http://distfiles.gentoo.org/releases/${1}/autobuilds/${LATEST_ISO}.DIGESTS \
    http://distfiles.gentoo.org/releases/${1}/autobuilds/${LATEST_ISO}.DIGESTS.asc
}

main() {
  if cfgchecks $1; then
    for retry in {1..3}; do
      download $1
      if md5sumcheck $1; then
 break;
      fi
    done
  fi
}


if [ $# -lt 1 ]; then
  usage;
else
  # change DOWNLOADDIR and LINKSDIR to user settings
  if [ "${2}" ]; then
    DOWNLOADDIR=${2}
  fi

  if [ "${3}" ]; then
    LINKSDIR=${3}
  fi
  main $1
fi

Monday, July 18, 2011

webspace

How to share files (pdf, doc, txt, anything) on blogger.com?

Well, there is no way, since you can only upload pictures (on picassa). Recently i've looked for a easy way to share files, in particular i wanted to upload a script on my blog. Since it's only possible to upload pictures on blogger.com i searched for some webspace. The problem is, i don't wanted to create another account on any webhoster just for a few scripts. The scripts are really small and i would be already happy with 50MB.

Luckily i found something and it's from google too. The solution is google sites! After creating a new "site" i'm able to upload content up to 100MB and the max files size can be 20MB. That's perfect for me! I think i never exceed those 100MB and even if i would, i can create new sites.

After all, the solution is a bit stupid. It would be really kind of google if they would provide some webspace for blogger.com.

Anyway - it works and now i'm able to share my scripts.

How to create a new site: Link
Storage features for a free site: Link
How to upload content on google site: Link