change URL at comments
[tools/sbs.git] / sbs-make-devkit
1 #!/bin/sh
2 #
3 # Mike McCormack
4 # 2011/2/24
5 #
6 # Build a self-extracting devkit to be used on 2nd party machines
7 #
8
9 # die: print message to stderr and exit with error code
10 #
11 # PARAMETERS
12 #   $1 $2 ... - message to be printed
13 die()
14 {
15         echo "$CE$N: fatal error: $*$CN" >&2
16         exit 1
17 }
18
19 # make sure we're not root
20 if test `id -u` = "0"
21 then
22         die "Please install SBS in a user account, not as root"
23 fi
24
25 # enable colors only on terminal devices
26 TPUT="`which tput`"
27 if test -t 0 -a -t 1 -a -n "$TPUT"
28 then
29     CI="`$TPUT setf 6 || true`"
30     CE="`$TPUT setf 4 || true`"
31     CX="`$TPUT setf 2 || true`"
32     CN="`$TPUT sgr0 || true`"
33 else
34     CI=''
35     CE=''
36     CX=''
37     CN=''
38 fi
39
40 N="`basename \"$0\"`"
41
42 set +e
43
44 ms=`which makeself`
45 if [ ! "$ms" ]
46 then
47         die "makeself is not installed. (try: sudo aptitude install makeself)"
48 fi
49
50 if [ ! -x ./install-sbs ]
51 then
52         die "must be run from sbs git repository"
53 fi
54
55 # remove everything
56 cleanup()
57 {
58         rm -rf "$tmpdir"
59 }
60
61 trap cleanup 0 INT TERM
62
63 # setup a temporary home directory
64 datestr=`date '+%Y%m%d'`
65 tmpdir=`mktemp -d`
66
67 # mirroring may take a long time, so cache the mirror
68 echo
69 echo "$CI""Mirroring debian repositories""$CN"
70 echo
71 ./make-offline-mirror.sh ./repo || die "Mirroring failed"
72
73 # make sure SBS is installed
74 SBS_INSTALL_DIR="$tmpdir/sbs-install" ./install-sbs || die "SBS install failed"
75
76 mirror_dir="$tmpdir"/sbs-install/share/sbs/apt_mirror
77 mkdir -p "$mirror_dir"
78 cp -R ./repo/* "$mirror_dir/"
79
80 echo
81 echo "$CI""Creating installer""$CN"
82 echo
83 makeself "$tmpdir" "sbs-offline-$datestr.sh" "sbs-offline-$datestr" ./sbs-install/share/sbs/scripts/sbs-offline-install || die "failed to build self-extracting archive"
84
85 exit 0