annotate setup @ 18:868a339b19f8 draft

log exceptions, exit when logging fails Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author Changaco <changaco ατ changaco δοτ net>
date Fri, 27 Apr 2012 00:01:59 +0200
parents 70bf588021fa
children 75563016f269
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
1 #!/bin/sh
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
2
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
3 usage () {
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
4 echo "usage: [DESTDIR=/] [PREFIX=/usr] $(basename "$0") install|uninstall|update" && exit 1
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
5 }
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
6
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
7 remove () {
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
8 [ -e "$1" ] && rm -vrf --preserve-root "$1"
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
9 }
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
10
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
11 install_dir () {
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
12 mkdir -p "$2"
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
13 cp -rv "$1" "$2"
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
14 }
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
15
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
16 [ $# -eq 1 ] && action=$1 || usage
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
17
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
18 [ -z "$DESTDIR" ] && DESTDIR=/
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
19 [ -z "$PREFIX" ] && PREFIX=/usr
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
20 _PREFIX=${DESTDIR%%/}/${PREFIX##/}
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
21
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
22 [ ! -w "$DESTDIR" ] && echo "You don't have write access on $DESTDIR" && exit 1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
23
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
24 progname=feed-push
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
25 confdir="${DESTDIR}etc/$progname"
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
26
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
27 if [ "$action" == install ]; then
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
28 install -v -m 755 -D $progname "$_PREFIX/bin/$progname"
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
29 install_dir examples "$_PREFIX/share/$progname"
4
70bf588021fa fix setup script
Changaco <changaco ατ changaco δοτ net>
parents: 3
diff changeset
30 [ -d /etc/rc.d ] && install_dir rc.d "${DESTDIR}etc" && install -vd "$confdir"
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
31 elif [ "$action" == uninstall ]; then
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
32 remove "$_PREFIX/bin/$progname"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
33 remove "$_PREFIX/share/$progname/examples"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
34 remove "${DESTDIR}etc/rc.d/$progname"
4
70bf588021fa fix setup script
Changaco <changaco ατ changaco δοτ net>
parents: 3
diff changeset
35 if [ $(ls -a "$confdir" | wc -l) -eq 2 ]; then rmdir "$confdir"
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
36 else echo "not removing config dir $confdir (not empty)"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
37 fi
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
38 elif [ "$action" == update ]; then
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
39 $0 uninstall &>/dev/null
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
40 $0 install
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
41 else
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
42 usage
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
43 fi
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
44
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
45 exit 0