Created
May 21, 2012 14:52
-
-
Save alxf/2762747 to your computer and use it in GitHub Desktop.
script to help customize ubuntu installer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Script to help customize iso ubuntu installer. | |
# | |
# script constants | |
# | |
UBUNTU_MIRROR="mirror.ovh.net/ftp.ubuntu.com/releases" | |
UBUNTU_VERSION="12.04 11.10 11.04 10.04.4 8.04.4" | |
UBUNTU_ARCH="i386 amd64" | |
# script functions | |
# | |
msg_error() | |
{ | |
# Display error message to stderr | |
# $@ = the message to display | |
printf -- "E: %s\n" "$@" >> /dev/stderr | |
} | |
download_iso() | |
{ | |
# Download alternate ubuntu iso installer. | |
# $1 = ubuntu version | |
# $2 = ubuntu architecture | |
exec wget -N "http://$UBUNTU_MIRROR/$1/ubuntu-$1-alternate-$2.iso" | |
} | |
extract_iso() | |
{ | |
# Extract given iso to directory. | |
# $1 = iso path | |
# $2 = target directory | |
pv -bep "$1" | bsdtar -C "$2" -xf - | |
if [ $? -ne 0 ]; then | |
msg_error "problem when extracting iso, abort" | |
exit $? | |
fi | |
#reset permission on installer directory | |
find "$2" -type d -exec chmod 775 {} \; | |
find "$2" -type f -exec chmod 664 {} \; | |
} | |
make_iso() | |
{ | |
# Generate iso from directory | |
# $1 = iso name | |
# $2 = source directory | |
exec genisoimage -o "$1" -r -J -no-emul-boot -boot-load-size 4 \ | |
-boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat "$2" | |
} | |
# main script | |
# | |
case $1 in | |
dl|download) | |
if [ -z "$2" -o -z "$3" ]; then | |
msg_error "invalid argument, abort" | |
exit 2 | |
else | |
arch=""; version="" | |
for v in $UBUNTU_VERSION; do | |
if [ "$v" = "$2" ]; then | |
version="$2" | |
break | |
fi | |
done | |
for a in $UBUNTU_ARCH; do | |
if [ "$a" = "$3" ]; then | |
arch="$3" | |
break | |
fi | |
done | |
if [ -z "$arch" -o -z "$version" ]; then | |
msg_error "invalid argument, abort" | |
exit 2 | |
fi | |
fi | |
download_iso "$2" "$3" | |
;; | |
x|extract) | |
if [ -z "$2" -o -z "$3" ]; then | |
msg_error "invalid argument, abort" | |
exit 2 | |
else | |
if [ ! -f "$2" ]; then | |
msg_error "no such file '$2', abort" | |
exit 2 | |
fi | |
if [ ! -d "$3" ]; then | |
mkdir -vp "$3" | |
else | |
msg_error "directory already exists '$3', abort" | |
exit 2 | |
fi | |
fi | |
extract_iso "$2" "$3" | |
;; | |
iso|mkiso) | |
if [ -z "$2" -o -z "$3" ]; then | |
msg_error "invalid argument, abort" | |
exit 2 | |
else | |
if [ -f "$2" ]; then | |
msg_error "iso file already exists '$2', abort" | |
exit 2 | |
fi | |
if [ ! -d "$3" ]; then | |
msg_error "no such directory '$3', abort" | |
exit 2 | |
fi | |
fi | |
make_iso "$2" "$3" | |
;; | |
*) | |
printf -- "usage: %s [download|extract|mkiso] <argument> <argument>\n" \ | |
"$(basename $0)" | |
printf -- "\n" | |
printf -- "commands:\n" | |
printf -- " download [version] [architecture]\n" | |
printf -- " extract [iso] [directory]\n" | |
printf -- " mkiso [directory] [iso]\n" | |
printf -- "\n" | |
printf -- "architectures: %s\n" "$UBUNTU_ARCH" | |
printf -- "\n" | |
printf -- "versions: %s\n" "$UBUNTU_VERSION" | |
printf -- "\n" | |
;; | |
esac | |
#end program | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment