This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·76 lines (66 loc) · 1.68 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
#!/bin/sh
DESKTOP_FILE=netindic.desktop
AUTOSTART_DIR="$HOME/.config/autostart/"
INSTALL=/usr/bin/install
SED=/bin/sed
BUNDLER=/usr/bin/bundler
CURRENT_DIR=$(pwd)
NETINDIC_EXEC="$CURRENT_DIR/netindic.rb"
NETINDIC_ICON="$CURRENT_DIR/wrench-8x.png"
# $1 file to copy
# $2 destination dir
copy_file() {
[ ! -d "$2" ] && "$INSTALL" -d "$2"
"$INSTALL" -m 644 "$1" "$2"
}
# $1 path to netindic.rb
# $2 desktop file to change
set_exec_correct_path() {
"$SED" -i "s#^Exec=.*#Exec=$1#" "$2"
}
# $1 path to icon
# $2 desktop file to change
set_icon_correct_path() {
"$SED" -i "s#^Icon=.*#Icon=$1#" "$2"
}
ask_confirmation() {
echo "Confirm autostart of netindic on session start? (y/n) "
read -r r
case $r in
y|Y) return 0;;
*) return 1;;
esac
}
help_install_bundler() {
cat <<EOF >&2
bundler not found
netindic relies on ruby gems to be installed
install bundler, then restart this script
it can be installed with:
Debian and derivative: sudo apt install bundler
EOF
}
run_bundler() {
$BUNDLER update
}
#######################################
# install prerequisites
echo "Installing prerequisites"
[ -f "$BUNDLER" ] && run_bundler || help_install_bundler
if ask_confirmation; then
if ! copy_file "$DESKTOP_FILE" "$AUTOSTART_DIR"; then
echo "cannot install desktop file to $AUTOSTART_DIR" >&2
exit 1
fi
if ! set_exec_correct_path "$NETINDIC_EXEC" "$AUTOSTART_DIR/$DESKTOP_FILE"; then
echo "cannot set correct 'Exec=' parameter into desktop file" >&2
exit 1
fi
if ! set_icon_correct_path "$NETINDIC_ICON" "$AUTOSTART_DIR/$DESKTOP_FILE"; then
echo "cannot set correct 'Icon=' parameter into desktop file" >&2
exit 1
fi
echo "Done!"
else
echo "Cancelled!"
fi