1#!/bin/sh
2
3cd "$(dirname "$0")"
4
5DESTVOL=/haiku
6LOOPVOL=/loopimg
7
8warn () {
9	alert --warning "$*" "Ok"
10}
11
12error () {
13	alert --stop "$*" "Ok"
14	exit 1
15}
16
17log () {
18	echo "$*"
19}
20
21
22if [ ! -d "$DESTVOL" ]; then
23	error "$DESTVOL not mounted"
24	exit 1
25fi
26
27
28find_current_revision () {
29	log "Getting url of latest revision..."
30	tf=/tmp/haiku-files.org_raw_$$
31	wget -O $tf http://haiku-files.org/raw/ >/dev/null 2>&1 || error "wget error"
32	url="$(grep -m1 'http:.*nightly-.*gcc2hybrid-raw.zip' "$tf" | sed 's/.*href="//;s/".*//')"
33	test -n "$url" || error "cannot find latest build"
34	file="${url##*/}"
35	rm "$tf"
36}
37
38
39download_current_revision () {
40	#if [ ! -e "$file" ]; then
41	log "Downloading latest revision: $file"
42	wget -c "$url" || error "cannot download latest revision"
43	#fi
44}
45
46
47unzip_current_revision () {
48	if [ ! -e "haiku-nightly.image" ]; then
49		log "Unziping..."
50		unzip "$file"
51	fi
52}
53
54
55install_current_revision () {
56	mkdir -p "$LOOPVOL"
57	sync
58	mount -ro "$PWD/haiku-nightly.image" "$LOOPVOL" || error "mount"
59	sync
60	
61	copyattr -r -d "$LOOPVOL"/* "$DESTVOL/"
62	sync
63	unmount "$LOOPVOL"
64}
65
66
67makebootable_install () {
68	log "Making the partition bootable..."
69	makebootable "$DESTVOL/"
70}
71
72
73customize_install () {
74	log "Copying files..."
75	copyattr -r -d files/* "$DESTVOL/"
76}
77
78
79
80find_current_revision
81download_current_revision
82#file=haiku-nightly-r37641-x86gcc2hybrid-raw.zip
83unzip_current_revision
84install_current_revision
85makebootable_install
86customize_install
87