3 # die: print message to stderr and exit with error code
6 # $1 $2 ... - message to be printed
9 echo "$CE$N: fatal error: $*$CN" >&2
10 echo "For detailed log, see: $LOG"
16 echo "$CE$N: warning: $*$CN" >&2
21 echo "$CX$N: $*$CN" >&2
30 # make sure we're not root
33 die "Please install SBS in a user account, not as root"
36 # enable colors only on terminal devices
38 if test -t 0 -a -t 1 -a -n "$TPUT"
40 CI="`$TPUT setf 6 || true`"
41 CE="`$TPUT setf 4 || true`"
42 CX="`$TPUT setf 2 || true`"
43 CN="`$TPUT sgr0 || true`"
53 # default logging is none
54 LOG="$(mktemp /tmp/.sbs-install-XXXXXX)"
55 [ $? -eq 0 ] || { echo "$CE$N: error: unable to open log file$CN" >&2; exit 1; }
56 echo "SBS install begin" > "$LOG"
58 git rev-parse --short HEAD >> "$LOG"
62 echo "$CI""SBS install script$CN"
63 echo "$CI""git version: `git rev-parse --short HEAD`$CN"
64 echo "$CI""last commit: `git log HEAD^1.. | grep ^Date:`$CN"
65 echo "$CI""For help see: https://source.tizen.org$CN"
68 check_email_and_complain()
72 # figure out the user's single ID
75 email="`git config --global --get user.email`"
82 echo "git username and email address are not set correctly."
83 echo "SBS will configure these for you now."
84 echo "Example name: David Kim"
85 echo "Example email: david.kim@your_company.com"
89 echo -n "Your email: "
91 git config --global user.name "$name"
92 git config --global user.email "$email"
97 copy_key_from_scratchbox()
99 if ! test -f "$HOME/.ssh/id_rsa"
101 if test -f "/scratchbox/users/$USER/home/$USER/.ssh/id_rsa"
103 echo "Copying public key from old scratchbox install"
104 mkdir -p "$HOME/.ssh"
105 cp -f "/scratchbox/users/$USER/home/$USER/.ssh"/id_rsa* "$HOME/.ssh"
115 echo -n "Updating sbs... "
117 # using origin/master because this is the default setup by git
118 (git fetch "$REMOTE""tools/sbs" master:origin/master -q >> "$LOG") || die "failed to fetch sbs repository"
119 if ! git diff-index --quiet HEAD
123 echo "$CE""Files have been changed. Please checkin changes or remove them with:""$CN"
124 echo "$CE""git reset --hard origin""$CN"
126 die "Repository not clean"
129 # check the current branch contains the latest we fetched from above
130 branch=`git branch --contains origin/master 2> /dev/null | grep "^\\* "`
133 warn "Please update to origin. e.g. git reset --hard origin"
134 die "Repository not up-to-date"
140 # location of server with all our source
141 REMOTE=${SBS_INSTALL_REMOTE:-"download.tizen.org:"}
146 # no user compile options, thanks
147 unset CC CFLAGS LDFLAGS MAKE MAKEFLAGS PANTS
149 if [ ! "$SBS_INSTALL_LAX" ]
151 check_email_and_complain
152 copy_key_from_scratchbox
156 # which distribution are we installing on?
157 cat /etc/lsb-release >> "$LOG" 2> /dev/null
159 INSTALLDIR=${SBS_INSTALL_DIR:-"$HOME/sbs-install"}
160 BUILDDIR="$ROOTDIR/Build"
161 SB2DIR="$BUILDDIR/scratchbox2"
162 QEMUDIR="$BUILDDIR/qemu"
163 DEBOOTDIR="$BUILDDIR/debootstrap"
164 LUTILDIR="$BUILDDIR/lutil"
167 pkg-config --version >/dev/null 2>&1 || { missing="$missing pkg-config"; warn "pkg-config missing - dependency checks won't be accurate"; }
168 pkg-config --exists libxml-2.0 >/dev/null 2>&1 || missing="$missing libxml2-dev"
169 pkg-config --exists uuid >/dev/null 2>&1 || missing="$missing uuid-dev"
170 cpp --version >/dev/null 2>&1 || { missing="$missing cpp"; warn "cpp missing - dependency checks won't be accurate"; }
171 echo | cpp -include archive.h >/dev/null 2>&1 || missing="$missing libarchive-dev"
172 echo | cpp -include lzo/lzo1x.h >/dev/null 2>&1 || missing="$missing liblzo2-dev"
173 gcc --version >/dev/null 2>&1 || { missing="$missing gcc"; warn "gcc missing - dependency checks won't be accurate"; }
174 [ `uname -m` != 'x86_64' ] || echo '#include <asm/errno.h>' | gcc -m32 -xc -c -o /dev/null - >/dev/null 2>&1 || missing="$missing gcc-multilib"
176 if ! pkg-config --exists zlib >/dev/null 2>&1; then
177 # Either pkg-config or zlib itself wasn't found (Debian provide .pc file, Ubuntu doesn't)
178 # We have to check zlib existence manually.
179 echo | cpp -include zlib.h >/dev/null 2>&1 || missing="$missing zlib1g-dev"
182 # check for things needed to build scratchbox2
183 for prog in automake autoconf make fakeroot realpath; do
184 $prog --version >/dev/null 2>&1 || missing="$missing $prog"
188 if ! dpkg-architecture --version >/dev/null 2>&1; then
189 missing="$missing dpkg-dev"
192 [ -z "$missing" ] || die "please install required packages: $missing"
196 git rev-parse HEAD > "$BUILDDIR/versions"
201 srcfile="$BUILDDIR/$name.tar.gz"
202 srcdir="$BUILDDIR/$name"
203 echo -n "Downloading $name... "
204 echo "Downloading $name" >> "$LOG"
206 wget --no-check-certificate -P $BUILDDIR http://download.tizen.org/releases/1.0/sbs/$name.tar.gz
208 tar xzf "$srcfile" -C "$srcdir" --touch
219 echo -n "Building scratchbox2... "
220 (cd "$SB2DIR" && make clean > /dev/null 2>&1)
221 (cd "$SB2DIR" && ./autogen.sh && ./configure && make 2>&1 ) >> "$LOG" || die "scratchbox2 build failed"
223 echo -n "Installing scratchbox2... "
224 (cd "$SB2DIR" && make install prefix="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "scratchbox2 install failed"
228 echo -n "Building qemu... "
229 (cd "$QEMUDIR" && make clean > /dev/null 2>&1)
230 (cd "$QEMUDIR" && ./configure --target-list=arm-linux-user,i386-linux-user --disable-blobs --disable-uuid && make 2>&1) >> "$LOG" || die "qemu build failed"
232 echo -n "Installing qemu... "
233 (cd "$QEMUDIR" && make install prefix="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "qemu install failed"
236 # build lutil and related tools
237 echo -n "Building lutil... "
238 (cd "$LUTILDIR" && ./autogen.sh && make prefix=/) >> "$LOG" || die "failed to build lutil"
239 (cd "$LUTILDIR" && make install prefix=/ DESTDIR="$INSTALLDIR" 2>&1 ) >> "$LOG" || die "lutil install failed"
242 # install debootstrap
243 echo -n "Installing debootstrap... "
244 (cd "$DEBOOTDIR" && fakeroot make devices.tar.gz) >> "$LOG" || die "failed to build debootstrap"
245 mkdir -p "$INSTALLDIR"/share/debootstrap/scripts/
246 cp -fd "$DEBOOTDIR"/scripts/* "$INSTALLDIR"/share/debootstrap/scripts/
247 cp -f "$DEBOOTDIR"/functions "$INSTALLDIR"/share/debootstrap
248 cp -f "$DEBOOTDIR"/devices.tar.gz "$INSTALLDIR"/share/debootstrap
249 cp -f "$DEBOOTDIR"/debootstrap "$INSTALLDIR"/bin/debootstrap
252 # update the sbs binary
253 echo -n "Installing sbs scripts... "
254 if [ -e "$INSTALLDIR"/sbs.list ]; then
255 notice "removing old sbs installation files" >>"$LOG" 2>&1
256 sort -r "$INSTALLDIR"/sbs.list |
258 if [ -d "$INSTALLDIR/$path" ]
260 lx rmdir "$INSTALLDIR/$path" || true
262 lx rm "$INSTALLDIR/$path" || true
265 mv -f "$INSTALLDIR"/sbs.list "$INSTALLDIR"/sbs.list.old
267 mkdir -p "$INSTALLDIR"
268 make install DESTDIR="$INSTALLDIR" prefix=/ >"$INSTALLDIR/sbs.list" 2>>$LOG || die "failed to install SBS"
271 # save the versions, to enable OSS license compliance
272 cp -f "$BUILDDIR"/versions "$INSTALLDIR"
274 SBS_ROOTDIR=${SBS_ROOTDIR:-$HOME/sbs}
275 if ! test -d "$SBS_ROOTDIR"
278 echo "$CX""Run $INSTALLDIR/bin/sbs -c to create your initial environment$CN"
282 echo "$CX""SBS update successful$CN"