diff options
Diffstat (limited to 'install-sbs')
-rwxr-xr-x | install-sbs | 285 |
1 files changed, 285 insertions, 0 deletions
diff --git a/install-sbs b/install-sbs new file mode 100755 index 0000000..89f59c0 --- /dev/null +++ b/install-sbs @@ -0,0 +1,285 @@ +#!/bin/sh + +# die: print message to stderr and exit with error code +# +# PARAMETERS +# $1 $2 ... - message to be printed +die() +{ + echo "$CE$N: fatal error: $*$CN" >&2 + echo "For detailed log, see: $LOG" + exit 1 +} + +warn() +{ + echo "$CE$N: warning: $*$CN" >&2 +} + +notice() +{ + echo "$CX$N: $*$CN" >&2 +} + +lx() +{ + notice "[exec]: $*" + "$@" +} + +# make sure we're not root +if test `id -u` = "0" +then + die "Please install SBS in a user account, not as root" +fi + +# enable colors only on terminal devices +TPUT="`which tput`" +if test -t 0 -a -t 1 -a -n "$TPUT" +then + CI="`$TPUT setf 6 || true`" + CE="`$TPUT setf 4 || true`" + CX="`$TPUT setf 2 || true`" + CN="`$TPUT sgr0 || true`" +else + CI='' + CE='' + CX='' + CN='' +fi + +N="`basename \"$0\"`" + +# default logging is none +LOG="$(mktemp /tmp/.sbs-install-XXXXXX)" +[ $? -eq 0 ] || { echo "$CE$N: error: unable to open log file$CN" >&2; exit 1; } +echo "SBS install begin" > "$LOG" +date >> "$LOG" +git rev-parse --short HEAD >> "$LOG" +echo >> "$LOG" + +echo +echo "$CI""SBS install script$CN" +echo "$CI""git version: `git rev-parse --short HEAD`$CN" +echo "$CI""last commit: `git log HEAD^1.. | grep ^Date:`$CN" +echo "$CI""For help see: http://www.tizendev.org$CN" +echo + +check_email_and_complain() +{ + local email name + + # figure out the user's single ID + while true + do + email="`git config --global --get user.email`" + + if [ "$email" ] + then + break + fi + + echo "git username and email address are not set correctly." + echo "SBS will configure these for you now." + echo "Example name: Ko Jengi" + echo "Example email: ko.jengi@samsung.com" + echo + echo -n "Your name: " + read name + echo -n "Your email: " + read email + git config --global user.name "$name" + git config --global user.email "$email" + echo + done +} + +copy_key_from_scratchbox() +{ + if ! test -f "$HOME/.ssh/id_rsa" + then + if test -f "/scratchbox/users/$USER/home/$USER/.ssh/id_rsa" + then + echo "Copying public key from old scratchbox install" + mkdir -p "$HOME/.ssh" + cp -f "/scratchbox/users/$USER/home/$USER/.ssh"/id_rsa* "$HOME/.ssh" + fi + fi +} + +check_sbs_uptodate() +{ + local branch + + # update sbs + echo -n "Updating sbs... " + + # using origin/master because this is the default setup by git + (git fetch "$REMOTE""tools/sbs" master:origin/master -q >> "$LOG") || die "failed to fetch sbs repository" + if ! git diff-index --quiet HEAD + then + echo + echo + echo "$CE""Files have been changed. Please checkin changes or remove them with:""$CN" + echo "$CE""git reset --hard origin""$CN" + echo + die "Repository not clean" + fi + + # check the current branch contains the latest we fetched from above + branch=`git branch --contains origin/master 2> /dev/null | grep "^\\* "` + if [ ! "$branch" ] + then + warn "Please update to origin. e.g. git reset --hard origin" + die "Repository not up-to-date" + fi + + echo "done" +} + +# location of server with all our source +REMOTE=${SBS_INSTALL_REMOTE:-"112.106.1.251:"} + +# our original cwd +ROOTDIR="`pwd`" + +# no user compile options, thanks +unset CC CFLAGS LDFLAGS MAKE MAKEFLAGS PANTS + +if [ ! "$SBS_INSTALL_LAX" ] +then + check_email_and_complain + copy_key_from_scratchbox +#check_sbs_uptodate +fi + +# which distribution are we installing on? +cat /etc/lsb-release >> "$LOG" 2> /dev/null + +INSTALLDIR=${SBS_INSTALL_DIR:-"$HOME/sbs-install"} +BUILDDIR="$ROOTDIR/Build" +SB2DIR="$BUILDDIR/scratchbox2" +QEMUDIR="$BUILDDIR/qemu" +DEBOOTDIR="$BUILDDIR/debootstrap" +LUTILDIR="$BUILDDIR/lutil" + +missing='' +pkg-config --version >/dev/null 2>&1 || { missing="$missing pkg-config"; warn "pkg-config missing - dependency checks won't be accurate"; } +pkg-config --exists libxml-2.0 >/dev/null 2>&1 || missing="$missing libxml2-dev" +pkg-config --exists uuid >/dev/null 2>&1 || missing="$missing uuid-dev" +cpp --version >/dev/null 2>&1 || { missing="$missing cpp"; warn "cpp missing - dependency checks won't be accurate"; } +echo | cpp -include archive.h >/dev/null 2>&1 || missing="$missing libarchive-dev" +echo | cpp -include lzo/lzo1x.h >/dev/null 2>&1 || missing="$missing liblzo2-dev" +gcc --version >/dev/null 2>&1 || { missing="$missing gcc"; warn "gcc missing - dependency checks won't be accurate"; } +[ `uname -m` != 'x86_64' ] || echo '#include <asm/errno.h>' | gcc -m32 -xc -c -o /dev/null - >/dev/null 2>&1 || missing="$missing gcc-multilib" + +if ! pkg-config --exists zlib >/dev/null 2>&1; then + # Either pkg-config or zlib itself wasn't found (Debian provide .pc file, Ubuntu doesn't) + # We have to check zlib existence manually. + echo | cpp -include zlib.h >/dev/null 2>&1 || missing="$missing zlib1g-dev" +fi + +# check for things needed to build scratchbox2 +for prog in automake autoconf make fakeroot realpath; do + $prog --version >/dev/null 2>&1 || missing="$missing $prog" +done + +# check for dpkg-dev +if ! dpkg-architecture --version >/dev/null 2>&1; then + missing="$missing dpkg-dev" +fi + +[ -z "$missing" ] || die "please install required packages: $missing" + +mkdir -p "$BUILDDIR" + +git rev-parse HEAD > "$BUILDDIR/versions" + +# download stuff +while read name +do + srcfile="$BUILDDIR/$name.tar" + srcdir="$BUILDDIR/$name" + echo -n "Downloading $name... " + echo "Downloading $name" >> "$LOG" + rm -rf "$srcdir" + wget --no-check-certificate -P $BUILDDIR http://112.106.1.254/sbs/$name.tar + mkdir "$srcdir" + tar xf "$srcfile" -C "$srcdir" --touch + rm -f "$srcfile" + echo "done" +done <<END +scratchbox2 +qemu +debootstrap +lutil +END + +# build scratchbox2 +echo -n "Building scratchbox2... " +(cd "$SB2DIR" && make clean > /dev/null 2>&1) +(cd "$SB2DIR" && ./autogen.sh && ./configure && make 2>&1 ) >> "$LOG" || die "scratchbox2 build failed" +echo "done" +echo -n "Installing scratchbox2... " +(cd "$SB2DIR" && make install prefix="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "scratchbox2 install failed" +echo "done" + +# build qemu +echo -n "Building qemu... " +(cd "$QEMUDIR" && make clean > /dev/null 2>&1) +(cd "$QEMUDIR" && ./configure --target-list=arm-linux-user,i386-linux-user --disable-blobs --disable-uuid && make 2>&1) >> "$LOG" || die "qemu build failed" +echo "done" +echo -n "Installing qemu... " +(cd "$QEMUDIR" && make install prefix="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "qemu install failed" +echo "done" + +# build lutil and related tools +echo -n "Building lutil... " +(cd "$LUTILDIR" && ./autogen.sh && make prefix=/) >> "$LOG" || die "failed to build lutil" +(cd "$LUTILDIR" && make install prefix=/ DESTDIR="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "lutil install failed" +echo "done" + +# install debootstrap +echo -n "Installing debootstrap... " +(cd "$DEBOOTDIR" && fakeroot make devices.tar.gz) >> "$LOG" || die "failed to build debootstrap" +mkdir -p "$INSTALLDIR"/share/debootstrap/scripts/ +cp -fd "$DEBOOTDIR"/scripts/* "$INSTALLDIR"/share/debootstrap/scripts/ +cp -f "$DEBOOTDIR"/functions "$INSTALLDIR"/share/debootstrap +cp -f "$DEBOOTDIR"/devices.tar.gz "$INSTALLDIR"/share/debootstrap +cp -f "$DEBOOTDIR"/debootstrap "$INSTALLDIR"/bin/debootstrap +echo "done" + +# update the sbs binary +echo -n "Installing sbs scripts... " +if [ -e "$INSTALLDIR"/sbs.list ]; then + notice "removing old sbs installation files" >>"$LOG" 2>&1 + sort -r "$INSTALLDIR"/sbs.list | + while read path; do + if [ -d "$INSTALLDIR/$path" ] + then + lx rmdir "$INSTALLDIR/$path" || true + else + lx rm "$INSTALLDIR/$path" || true + fi + done >>"$LOG" 2>&1 + mv -f "$INSTALLDIR"/sbs.list "$INSTALLDIR"/sbs.list.old +fi +mkdir -p "$INSTALLDIR" +make install DESTDIR="$INSTALLDIR" prefix=/ >"$INSTALLDIR/sbs.list" 2>>$LOG || die "failed to install SBS" +echo "done" + +# save the versions, to enable OSS license compliance +cp -f "$BUILDDIR"/versions "$INSTALLDIR" + +SBS_ROOTDIR=${SBS_ROOTDIR:-$HOME/sbs} +if ! test -d "$SBS_ROOTDIR" +then + echo + echo "$CX""Run $INSTALLDIR/bin/sbs -c to create your initial environment$CN" + echo +else + echo + echo "$CX""SBS update successful$CN" + echo +fi + |