-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.bash
165 lines (137 loc) · 4.66 KB
/
install.bash
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
: "${BIN_PATH:=$HOME/.local/bin}"
: "${INSTALL_PATH:=$BIN_PATH/needlessly-pomo}"
prompt_yes_no(){
# Yes-No dialog, with default fallback
prompt="${*=Choose}"
# 0=yes; 1=no
default="${DEFAULT:=1}"
while
printf "\nQUESTION: %s\n(y[es]/n[o] - case insensitive): " "$prompt"
read -r REPLY
case "$(echo "${REPLY}" | tr '[:upper:]' '[:lower:]')" in
(y|yes)
return 0
;;
(n|no)
return 1
;;
("")
printf "...I'll take that as a '%s'.\n" \
"$([ "$default" -eq 0 ] && echo Yes || echo No)"
return "$default"
;;
(*)
printf "Option '%s' not recognized, please try again.\n" "${REPLY}"
continue
;;
esac
# do we even need to add a break condition here?
do :
done
}
echo "== OVER ENGINEERED POMODORO SCRIPT INSTALLATION =="
echo "HINT: both the path to local binary folder as well as"\
"the installation destination can be configured by setting"\
"the 'BIN_PATH' and 'INSTALL_PATH' variable on your bash"\
"environment before running this script"
if prompt_yes_no "Do you want to move the script"\
"alongside it's resources to '${INSTALL_PATH}'?"; then
_install_in_dir=true
else
_install_in_dir=false
fi
if prompt_yes_no "Do you want to have a shortcut"\
"to the script in '${BIN_PATH}'?"; then
_ln_to_bin=true
else
_ln_to_bin=false
fi
if prompt_yes_no "Do you want to add a desktop shortcut?"; then
_dot_desktop=true
else
_dot_desktop=false
fi
if ! ($_install_in_dir || $_ln_to_bin || $_dot_desktop);
then
count=3
while [ "$count" -gt 0 ]; do
echo -n "."
: $((--count))
sleep 0.8
done
echo "what are you doing here then?"
sleep 0.8
exit 0;
fi
echo -e "\nINFO: Installation started."
if $_install_in_dir; then
WORK_DIR="${INSTALL_PATH}"
mkdir -p --verbose "${WORK_DIR}"
for item in "resources" "pomodoro.bash" "uninstall.bash" "install.bash";
do
cp --interactive --verbose --recursive \
./"${item}" "${WORK_DIR}/${item}"
done
fi
# set WORK_DIR if it hasn't been set
: "${WORK_DIR:=$(dirname "$0")}"
echo "INFO: Creating '${WORK_DIR}/.env', which is the configuration file."
cat > "${WORK_DIR}/.env" <<ENV
#!/bin/bash
# This is basically a configuration file
# (should we put it in ~/.config instead?)
#
# If you wanna have set values you can later overwrite, use
# this Shell syntax (yes the ":" is mandatory):
# : "\${VARIABLE_NAME=the value you want to set}"
#
# For example, to set a cycle of 45/10/5 minutes as the default:
# : "\${POMO_INTERVAL_1=45}"
# : "\${POMO_INTERVAL_2=10}"
# : "\${POMO_INTERVAL_3=5}"
#
# this way, you can override the intervals per run like so:
# # in your terminal
# # POMO_INTERVAL_1 is still 45 min, but 2 are 15min and no interval 3
# POMO_INTERVAL_2=15 POMO_INTERVAL_3="" bash pomodoro.sh
#
# For more overridable parameters, see the scripts itself!
# Look for the above shell syntax (this one: ': \${...}').
ENV
if $_ln_to_bin; then
: "${LN_NAME:=pomodoro}"
ln --interactive --relative --symbolic \
"${WORK_DIR}/pomodoro.bash" "${BIN_PATH}/${LN_NAME}"
chmod u+x "${BIN_PATH}/${LN_NAME}"
echo "LINK='${BIN_PATH}/${LN_NAME}'" >> "$WORK_DIR/.env"
fi
if $_dot_desktop; then
: "${DESKTOP_FILE:=needlessly-pomo.desktop}"
: "${APPLICATION_DIR:=$HOME/.local/share/applications}"
echo "INFO: Generating a .desktop file in '${APPLICATION_DIR}...'"
cat > "$APPLICATION_DIR/$DESKTOP_FILE.temp" <<DOT_DESKTOP
[Desktop Entry]
Type=Application
# The name of the application
Name=Needlessly Complex Pomodoro
# A comment which can/will be used as a tooltip
Comment=Pomodoro that is kinda over engineered :3
# The path to the folder in which the executable is run
Path=$WORK_DIR
# The executable of the application, possibly with arguments.
Exec=bash "$WORK_DIR/pomodoro.bash"
# The name of the icon that will be used to display this entry
Icon=$WORK_DIR/resources/icon.svg
# Describes whether this application needs to be run in a terminal or not
Terminal=true
# Describes the categories in which this entry should be shown
Categories=ConsoleOnly;Time;Utility;Education;
DOT_DESKTOP
# doing it this way prevents accidentally overwriting an existing file
mv --interactive --verbose \
"$APPLICATION_DIR/$DESKTOP_FILE.temp" "$APPLICATION_DIR/$DESKTOP_FILE"
echo "DESKTOP='$APPLICATION_DIR/$DESKTOP_FILE'" >> "$WORK_DIR/.env"
fi
echo -e "\nINFO: Installation complete."\
"For further configurations, please edit '$WORK_DIR/.env'"