This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·202 lines (180 loc) · 5.01 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/data/data/com.termux/files/usr/bin/env bash
cd $(dirname `which $0`)
# Colors
if test -t 1; then
bold=$(tput bold)
normal=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 4)
yellow=$(tput setaf 11)
else
echo "(!) No colors will be available: not supported."
fi
error(){
echo "${bold}${red}=x ${normal}${1}"
}
success(){
echo "${bold}${green}=> ${normal}${1}"
}
warn(){
echo "${bold}${yellow}(!)${normal}${1}"
}
info(){
echo "${bold}${blue}=> ${normal}${1}"
}
exec(){
info "${1}"
eval "${1}"
code=$?
if [ ! $code -eq 0 ]; then
error "Exec: ${1} failed with non-zero exit code: ${code}"
exit -1
fi
}
require_directory(){ # Creates directory if not exist
if [ ! -d $1 ]; then
warn "Directory not found: ${1}. Will create it now."
exec "mkdir ${1}"
fi
}
check_directory(){ # Creates directory if not exist
if [ ! -d $1 ]; then
error "Directory not found: ${1}. Will create it now."
exit -1
fi
}
change_dir(){
if [ ! -d $1 ]; then
error "No such directory: ${1}"
exit -1
fi
info "Entering directory: ${1}"
cd $1
}
leave_dir(){
info "Leaving directory: $(pwd)"
cd $BASEDIR
}
check_equal(){
printf "${bold}${blue}=>${normal} Checking equality: ${1} and ${2}..."
if ! cmp $1 $2 >/dev/null 2>&1
then
printf "${bold}${red}FAILED${normal}\n"
return -1
fi
printf "${bold}${green}OK${normal}\n"
return 0
}
require_equal(){
check_equal $1 $2
local r=$?
if [ ! $r -eq 0 ]; then
error "Files ${1} and ${2} are not equal."
exit -1
fi
}
check_command(){
printf "${bold}${blue}=> ${normal}Checking that ${1} avail..."
if ! [ -x "$(command -v ${1})" ]; then
printf "${bold}${red}FAILED${normal}\n"
return -1
fi
printf "${bold}${green}OK${normal}\n"
return 0
}
require_command(){
check_command $1
local r=$?
if [ ! $r -eq 0 ]; then
error "Command ${1} is not avail."
exit -1
fi
}
if [ $# -eq 0 ]; then
error "Please specify target. Use -h option for help."
exit -1
fi
if [[ $1 == "-h" ]]; then
echo "Usage:"$0" <-h> [all]"
echo "-h Display this help message and exit."
echo "all Install everything"
echo "deps Installs required packages to run the app"
echo "gems Installs gems"
echo "install Copies files and registers program"
echo "uninstall Removes program"
echo "deauth Removes tokens and cache"
echo "update Updates to a latest development version from git"
echo "configure Opens vim to configure program"
exit 0
fi
TERMUX_ROOT="/data/data/com.termux/files"
target_deps(){
info "Updating apt repos..."
require_command "apt"
exec "apt update"
exec "apt upgrade"
exec "apt install ruby"
success "Installed ruby"
exec "apt install termux-api"
success "Installed Termux API"
}
target_gems(){
info "Installing gems..."
info "Checking prerequities"
require_command "bundle"
require_command "ruby"
require_command "termux-toast"
require_command "termux-notification"
exec "bundle install"
success "Installed gems"
}
target_install(){
info "Installing nextcloud-notificator"
require_directory "${TERMUX_ROOT}/usr/share/nextcloud-notificator"
exec "cp ./*.rb ${TERMUX_ROOT}/usr/share/nextcloud-notificator"
require_directory "${TERMUX_ROOT}/home/.termux/boot/"
exec "cp ./boot.sh ${TERMUX_ROOT}/home/.termux/boot/boot-notificator.sh"
exec "cp ./config.yml ${TERMUX_ROOT}/usr/etc/nextcloud-notificator.yml"
success "Installation complete"
}
target_deauth(){
info "Removing tokens"
exec "rm -rf /data/data/com.termux/files/usr/var/cache/notificator-cache"
exec "rm -rf /data/data/com.termux/files/usr/var/cache/notificator-auth"
success "Tokens cleaned"
}
target_uninstall(){
info "Installing nextcloud-notificator"
exec "rm -rf ${TERMUX_ROOT}/usr/share/nextcloud-notificator"
exec "rm -rf ${TERMUX_ROOT}/home/.termux/boot/boot-notificator.sh"
exec "rm -rf ${TERMUX_ROOT}/usr/etc/nextcloud-notificator.yml"
success "Uninstallation complete"
}
target_update(){
require_command "git"
exec "git pull"
exec "rm -rf ${TERMUX_ROOT}/usr/share/nextcloud-notificator"
exec "rm -rf ${TERMUX_ROOT}/home/.termux/boot/boot-notificator.sh"
target_gems
require_directory "${TERMUX_ROOT}/usr/share/nextcloud-notificator"
exec "cp ./*.rb ${TERMUX_ROOT}/usr/share/nextcloud-notificator"
require_directory "${TERMUX_ROOT}/home/.termux/boot/"
exec "cp ./boot.sh ${TERMUX_ROOT}/home/.termux/boot/boot-notificator.sh"
success "Update complete"
}
target_configure(){
require_command "vim"
exec "vim /data/data/com.termux/files/usr/etc/nextcloud-notificator.yml"
}
target_all(){
target_deps
target_gems
target_install
}
if [[ `type -t "target_${1}"` == "function" ]]; then
eval "target_${1}"
success "Done."
else
error "No such target:${1}."
fi