-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·91 lines (72 loc) · 1.66 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
PROGRAM_NAME="server-scripts"
DEFAULT_PREFIX="/usr/share"
BIN_PATH="/usr/local/bin"
SOURCE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
CONFIG_PATH="/etc/$PROGRAM_NAME.conf"
SCRIPT_ASSUME_YES=""
PREFIX="$DEFAULT_PREFIX"
INSTALL_DIR="$PREFIX/$PROGRAM_NAME"
usage() {
echo "
Usage: $0
Options:
-y Assume yes for all questions"
}
if [ "$1" = "--help" ]; then
usage
exit 1
fi
while getopts ":y" opt; do
case "$opt" in
y) SCRIPT_ASSUME_YES="1"
shift
;;
esac
done
#PREFIX="$1"
#if [ ! -d "$PREFIX" ]; then
# PREFIX="$DEFAULT_PREFIX"
#fi
if [ ! -w "$PREFIX" ]; then
echo "You cannot write to $INSTALL_DIR, aborting."
exit 1
fi
if [ -z "$SCRIPT_ASSUME_YES" ]; then
read -p "Install $PROGRAM_NAME to $INSTALL_DIR (y/n)? " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting installation."
exit 1
fi
fi
if [ -d "$INSTALL_DIR" ]; then
echo "Previous installation detected."
if [ -z "$SCRIPT_ASSUME_YES" ]; then
read -p "Replace $INSTALL_DIR (y/n)? " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting installation."
exit 1
fi
fi
fi
python -c "import sh" 2>/dev/null || {
pip install sh
}
rsync -a "$SOURCE_DIR/" "$INSTALL_DIR" || {
echo "Sync files to $INSTALL_DIR failed."
exit 1
}
chmod +x "$INSTALL_DIR"/bin/*
chmod +x "$INSTALL_DIR"/lib/*
if [ -w "$BIN_PATH" ]; then
# TODO: ln -s -f too danger, it rewrites files!
find "$INSTALL_DIR"/bin -type f -exec ln -s {} "$BIN_PATH" \; 2>/dev/null
fi
if [ ! -e "$CONFIG_PATH" ]; then
cp "$SOURCE_DIR/$PROGRAM_NAME.conf.example" "$CONFIG_PATH"
else
echo "$CONFIG_PATH exists, don't rewrite it."
fi
echo "Installed $PROGRAM_NAME to $INSTALL_DIR."