annotate setup @ 27:75563016f269 draft

add systemd .service unit Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author Changaco <changaco ατ changaco δοτ net>
date Sat, 04 Aug 2012 18:33:17 +0200
parents 70bf588021fa
children
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"
27
75563016f269 add systemd .service unit
Changaco <changaco ατ changaco δοτ net>
parents: 4
diff changeset
30 install -vd "$confdir"
75563016f269 add systemd .service unit
Changaco <changaco ατ changaco δοτ net>
parents: 4
diff changeset
31 install -v -m 755 -D init/$progname.bash "${DESTDIR}etc/rc.d/$progname"
75563016f269 add systemd .service unit
Changaco <changaco ατ changaco δοτ net>
parents: 4
diff changeset
32 install -v -m 644 -D init/$progname.service "${DESTDIR}usr/lib/systemd/system/$progname.service"
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
33 elif [ "$action" == uninstall ]; then
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
34 remove "$_PREFIX/bin/$progname"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
35 remove "$_PREFIX/share/$progname/examples"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
36 remove "${DESTDIR}etc/rc.d/$progname"
4
70bf588021fa fix setup script
Changaco <changaco ατ changaco δοτ net>
parents: 3
diff changeset
37 if [ $(ls -a "$confdir" | wc -l) -eq 2 ]; then rmdir "$confdir"
3
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
38 else echo "not removing config dir $confdir (not empty)"
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
39 fi
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
40 elif [ "$action" == update ]; then
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
41 $0 uninstall &>/dev/null
0d4378996672 improve setup script
Changaco <changaco ατ changaco δοτ net>
parents: 1
diff changeset
42 $0 install
1
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
43 else
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
44 usage
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
45 fi
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
46
a68d7feeba88 initial commit
Changaco <changaco ατ changaco δοτ net>
parents:
diff changeset
47 exit 0