updated on Wed Jan 11 00:07:16 UTC 2012
[aur-mirror.git] / unball / install.sh
blob645cfc78dc0f1d24a4aa8be570af635d0821f557
1 #!/usr/bin/env bash
3 # The basic framework for adjusting the install location.
4 [ -z "$DESTDIR" ] && DESTDIR="/" && export DESTDIR
5 [ -z "$PREFIX" ] && PREFIX="/usr/local" && export PREFIX
6 NAUTILUS_SCRIPT_SUFFIX="" # Set this to use hierarchical categories for Nautilus scripts.
7 UNBALL_TARGET="$PREFIX/bin/unball"
8 MOVETOZIP_TARGET="$PREFIX/bin/moveToZip"
9 MANPAGES_TARGET="$PREFIX/man/man1"
10 THUNAR_HOOK_DIR="$PREFIX/libexec/thunar-archive-plugin"
12 function gen_manpages() {
13 # Usage: gen_manpages <command> ...
14 # Purpose: If help2man is installed, generate and install manpages from --help and --version
15 if which help2man > /dev/null; then
16 echo "help2man found. Generating manpages."
17 [ -d "$DESTDIR/$MANPAGES_TARGET" ] || mkdir -p "$DESTDIR/$MANPAGES_TARGET"
18 for CMD in "$@"; do
19 chmod +x "$CMD"
20 help2man -N "$CMD" | gzip > "$DESTDIR/$MANPAGES_TARGET/${CMD##*/}.1.gz"
21 done
22 else
23 echo "help2man not found. No manpages will be generated."
28 function install_nautilus() {
29 # Usage: install_nautilus <UID> <GID> <HOMEDIR>
30 # Purpose: Install unball and MoveToZip into the Nautilus (GNOME) scripts menu.
32 # Find the script dir if it exists. Return if it doesn't.
33 if [ -d "$3/.gnome2/nautilus-scripts" ]; then NSCRIPT_PATH="$3/.gnome2/nautilus-scripts"
34 elif [ -d "$3/.gnome/nautilus-scripts" ]; then NSCRIPT_PATH="$3/.gnome/nautilus-scripts"
35 elif [ -d "$3/Nautilus/scripts" ]; then NSCRIPT_PATH="$3/Nautilus/scripts"
36 else return 1
39 # Make the script category dir if it doesn't exist
40 NSCRIPT_FULL_PATH="$DESTDIR/$NSCRIPT_PATH/$NAUTILUS_SCRIPT_SUFFIX"
41 [ ! -d "$NSCRIPT_FULL_PATH" ] && mkdir -p "$NSCRIPT_FULL_PATH" &> /dev/null
43 # Install the symlinks
44 pushd "$NSCRIPT_FULL_PATH" > /dev/null
45 ln -s "$UNBALL_TARGET" ./Unball
46 chown "$1:$2" ./Unball
47 ln -s "$MOVETOZIP_TARGET" "./Move to ZIP"
48 chown "$1:$2" "./Move to ZIP"
49 popd > /dev/null
52 function user_enum() {
53 # Usage: user_enum <command>
54 # command will receive <UID> <GID> <HOMEDIR> as it's parameters
55 #FIXME: This will break if the homedir path contains spaces.
56 for LINE in `cut -sd: -f3,4,6 /etc/passwd`; do
57 LINE_SPLIT=`echo $LINE | tr ":" " "`
58 $1 $LINE_SPLIT # DON'T just quote the $LINE_SPLIT. It has to expand into 3 positional args.
59 done
62 # This will just fail silently if we don't have write permissions for DESTDIR.
63 # That way, we can just leave the checking to the last minute.
64 [ ! -d "$DESTDIR/$PREFIX" ] && mkdir -p "$DESTDIR/$PREFIX" &> /dev/null
66 # Support for installing the Konqueror (KDE) service menu
67 #if which konqueror &> /dev/null; then
68 # if [ -w "$DESTDIR" ]; then
69 [ -z "$KDEDIR" ] && KDEDIR=`cut -d: -f1 <<< "$KDEDIRS"`
70 [ -z "$KDEDIR" ] && KDEDIR="$PREFIX"
71 # else
72 # KDEDIR=~/.kde
73 # fi
74 SERVICEMENU_DIR="${DESTDIR}/${KDEDIR}/share/apps/konqueror/servicemenus"
75 # unset KDEDIR # Make sure nobody uses it afterwards since it's not prefixed with DESTDIR.
76 #fi
78 # Do the install.
79 if [ -w "$DESTDIR/$PREFIX" ] && [ "$1" != "--help" ] ; then
80 # Install unball and moveToZip
81 echo `sed 's@//*@/@g' <<< "Installing unball to $DESTDIR/$PREFIX/bin"`
82 [ -d "$DESTDIR/$PREFIX/bin" ] || mkdir -p "$DESTDIR/$PREFIX/bin"
83 install src/unball "$DESTDIR/$UNBALL_TARGET"
84 install src/moveToZip "$DESTDIR/$MOVETOZIP_TARGET"
86 # Install manpages
87 gen_manpages src/unball src/moveToZip
89 # Install the Konqueror (KDE) hooks
90 if [ -n "$SERVICEMENU_DIR" ]; then
91 # echo "Konqueror present. Installing service menus."
92 [ -d "$SERVICEMENU_DIR" ] || mkdir -p "$SERVICEMENU_DIR"
93 install --mode 0644 src/servicemenus/*.desktop "$SERVICEMENU_DIR"
96 # Install the Nautilus (GNOME) hook, but only if it doesn't already exist.
97 # This ensures that users won't have unball re-added if they removed it after a previous install.
98 NAUTILUS_SKEL_TARGET="/etc/skel/.gnome2/nautilus-scripts"
99 # if [ ! -L "$DESTDIR/$NAUTILUS_SKEL_TARGET/Unball" ]; then
100 # echo "Installing Nautilus script links."
101 # mkdir -p "$DESTDIR/$NAUTILUS_SKEL_TARGET"
102 # ln -s "$UNBALL_TARGET" "$DESTDIR/$NAUTILUS_SKEL_TARGET/Unball"
103 # ln -s "$MOVETOZIP_TARGET" "$DESTDIR/$NAUTILUS_SKEL_TARGET/Move to ZIP"
104 # user_enum install_nautilus
105 # fi
107 # Install the Thunar (Xfce) hook if the Thunar archive plugin is installed.
108 if [ -d "$THUNAR_HOOK_DIR" ]; then
109 echo "Installing Thunar (Xfce) archive hooks"
110 install src/unball.tap "$DESTDIR/$THUNAR_HOOK_DIR/unball.tap"
113 echo
114 # echo "unball installed. You can now type \"./run_test.py\" to run the unit tests. If tests fail, you probably are missing some extraction tools."
115 else
116 [ "$1" != "--help" ] && echo "Sorry, it appears that you do not have write permissions for the chosen install location."
117 echo "The install location can be adjusted using the DESTDIR and PREFIX environment variables."
118 echo "There are three main ways to do this:"
119 echo ' 1. For making debs, rpms, or ebuilds: DESTDIR=$D PREFIX=/usr ./install.sh'
120 echo ' 2. As root (to put unball in /usr/bin): PREFIX=/usr ./install.sh'
121 echo ' 3. As a non-root user to install to your home directory: PREFIX=~ ./install.sh'
122 echo "The default install location is /usr/local/bin"
123 echo
124 echo "Also, if you prefer to sort your Nautilus scripts into categories, you can set the NAUTILUS_SCRIPT_SUFFIX variable."