This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathkr
executable file
·283 lines (246 loc) · 8.81 KB
/
kr
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
VERSION=2.4.13
install_darwin() {
command -v brew &>/dev/null && test "$1" = "brew"
if [ "$?" != "0" ]; then
say Installing Krypton...
install_darwin_manual
else
# Check if already installed with brew
ls -l `command -v kr` | grep Cellar &>/dev/null
if [ "$?" = "0" ]; then
say Upgrading Krypton with Homebrew...
ensure brew update -v
ensure brew upgrade kryptco/tap/kr && brew link --overwrite kryptco/tap/kr
else
say "Installing Krypton with Homebrew. If Homebrew is too slow or fails, try \"curl https://krypt.co/kr | sh\""
ensure brew update -v
ensure brew install kryptco/tap/kr && brew link --overwrite kryptco/tap/kr
if [ "$?" != "0" ]; then
echo
read -p "Krypton Homebrew install failed. Try manual installation?" -n 1 -r < /dev/tty
if [ $REPLY != ^[Yy]$ ]
then
install_darwin_manual
fi
fi
fi
fi
}
verify_bottle_hash() {
say OpenSSL command line found, verifying downloaded binary hash...
DOWNLOADED_HASH=`openssl dgst -sha256 -hex /tmp/$BOTTLE_FILE | awk '{print $2}'`
test "$DOWNLOADED_HASH" = "$BOTTLE_HASH" || (say "Downloaded binary hash incorrect. Aborting."; rm /tmp/$BOTTLE_FILE; exit 1) || exit 1
say "Binary verified."
}
install_darwin_manual() {
need_cmd mv
need_cmd cp
need_cmd curl
need_cmd rm
need_cmd tar
need_cmd launchctl
need_cmd perl
need_cmd mkdir
need_cmd touch
need_cmd printf
MAJOR_MAC_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}')
case $MAJOR_MAC_VERSION in
#10.10 NO LONGER SUPPORTED
10.11) BOTTLE_FILE=kr-2.4.13.el_capitan.bottle.2.tar.gz; BOTTLE_HASH=c7ff5433486daa1654ec79806b0fcb9aafcc7dc052e166c5c68fa707ed49e2b4;;
10.12) BOTTLE_FILE=kr-2.4.13.sierra.bottle.2.tar.gz; BOTTLE_HASH=2285ce4eebb3ee75ab9678676c15bf133d5a3d24d2b7a4dc4da31179de699462; USE_KRBTLE=1;;
10.13) BOTTLE_FILE=kr-2.4.13.high_sierra.bottle.2.tar.gz; BOTTLE_HASH=b5278156184a7f50ed04790ecc7081be5c3f3d82c07da64d9683bf5db19472cb; USE_KRBTLE=1;;
10.14) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
10.15) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
10.16) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
11.0) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
11.*) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
12.*) BOTTLE_FILE=kr-2.4.13.mojave.bottle.2.tar.gz; BOTTLE_HASH=8901218264de65fdbf2dc258f00557e456416f9f32fb9511956d546fea0a804a; USE_KRBTLE=1;;
*) say "Unsupported OS X version $MAJOR_MAC_VERSION. Krypton requires 10.11+" && exit 1 ;;
esac
say Downloading Krypton.
ensure curl -# -o /tmp/$BOTTLE_FILE -L https://github.com/KryptCo/bottles/raw/master/$BOTTLE_FILE
command -v openssl &>/dev/null && verify_bottle_hash
PREFIX=${PREFIX:-$HOMEBREW_PREFIX}
PREFIX=${PREFIX:-/usr/local}
ensure mk_owned_dir_if_not_exists $PREFIX/lib
ensure mk_owned_dir_if_not_exists $PREFIX/bin
if [ "$USE_KRBTLE" = '1' ]; then
ensure mk_owned_dir_if_not_exists $PREFIX/Frameworks
fi
ignore rm -rf /tmp/kr
ensure tar xf /tmp/$BOTTLE_FILE -C /tmp/
ensure mv_maybe_sudo "/tmp/kr/$VERSION/bin/*" $PREFIX/bin/
ensure mv_maybe_sudo "/tmp/kr/$VERSION/lib/*" $PREFIX/lib/
if [ "$USE_KRBTLE" = '1' ]; then
ensure rmrf_maybe_sudo "$PREFIX/Frameworks/krbtle.framework"
ensure mv_maybe_sudo "/tmp/kr/$VERSION/Frameworks/krbtle.framework" $PREFIX/Frameworks/
fi
ensure mkdir -p ~/.ssh
ensure touch ~/.ssh/config
say Krypton installed successfully. Type \"kr pair\" to pair with the Krypton mobile app.
kr restart &>/dev/null
}
set_os() {
#!/bin/bash
# Check for FreeBSD in the uname output
# If it's not FreeBSD, then we move on!
if [ "$(uname -s)" = 'FreeBSD' ]; then
OS='freebsd'
# Check for a redhat-release file and see if we can
# tell which Red Hat variant it is
elif [ -f "/etc/redhat-release" ]; then
RHV=$(egrep -o 'Fedora|CentOS|Red\ Hat|Red.Hat' /etc/redhat-release)
case $RHV in
Fedora) OS='fedora';;
CentOS) OS='centos';;
Red\ Hat) OS='redhat';;
Red.Hat) OS='redhat';;
esac
# Check for debian_version
elif [ -f "/etc/debian_version" ]; then
OS='debian'
# Check for arch-release
elif [ -f "/etc/arch-release" ]; then
OS='arch'
# Check for SuSE-release
elif [ -f "/etc/SuSE-release" ]; then
OS='suse'
fi
}
install_linux() {
set_os
case $OS in
fedora) install_yum "yum config-manager";;
centos) need_cmd yum-config-manager && install_yum "yum-config-manager";;
redhat) need_cmd yum-config-manager && install_yum "yum-config-manager";;
*) install_debian
esac
}
install_yum() {
export YUM_CONFIG_MANAGER=$1
need_cmd yum
need_cmd rpm
need_cmd gpg
ensure gpg --keyserver=hkp://keyserver.ubuntu.com:80 --recv-keys "C4A05888A1C4FA02E1566F859F2A29A569653940"
ensure gpg --export --armor C4A05888A1C4FA02E1566F859F2A29A569653940 > /tmp/kryptco.key
echo Importing KryptCo GPG key...
ensure sudo rpm --import /tmp/kryptco.key
ignore rm /tmp/kryptco.key
ignore sudo yum clean expire-cache 1>/dev/null 2>/dev/null
ensure sudo $YUM_CONFIG_MANAGER --add-repo https://kryptco.github.io/yum
ensure sudo yum install kr -y
}
is_kali() {
cat /etc/*-release | head -1 | grep "Kali" && KALI="yes"
}
install_debian() {
need_cmd apt-get
ensure sudo apt-get install software-properties-common dirmngr apt-transport-https -y
need_cmd apt-add-repository
need_cmd apt-key
need_cmd sleep
say Adding KryptCo signing key...
ensure sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C4A05888A1C4FA02E1566F859F2A29A569653940
which kr && say Removing old version of kr...
ignore sudo apt-get remove kr -y &>/dev/null
say Adding KryptCo repository...
ignore sudo add-apt-repository --remove "deb http://kryptco.github.io/deb beta beta" &>/dev/null
sleep 1
is_kali
if [ "$KALI" = 'yes' ]; then
# Kali linux add-apt-repository checks for kali-rolling template
grep "deb http://kryptco.github.io/deb kryptco main" "/etc/apt/sources.list" || ensure sudo printf "deb http://kryptco.github.io/deb kryptco main" >> /etc/apt/sources.list
else
ensure sudo add-apt-repository "deb http://kryptco.github.io/deb kryptco main"
fi
sleep 1
ignore sudo apt-get update
say Installing kr...
ensure sudo apt-get install kr -y
}
install() {
unamestr=`uname`
if [ "$unamestr" = 'Linux' ]; then
install_linux "$@"
elif [ "$unamestr" = 'Darwin' ]; then
install_darwin "$@"
else
say "OS $unamestr Unsupported"
exit 1
fi
}
is_my_dir() {
test "`ls -ld $1 | awk 'NR==1 {print $3}'`" = "$USER"
}
# mv $1 to $2, using sudo if necessary
# $2 must be a directory, not the new file name
mv_maybe_sudo() {
(is_my_dir $2 && ensure mv -f $1 $2) || ensure warn_sudo mv -f $1 $2
}
# rm $1 using sudo if necessary, failing gracefully if not present
rmrf_maybe_sudo() {
(is_my_dir `dirname $1` && ensure rm -rf $1) || ensure warn_sudo rm -rf $1
}
warn_sudo() {
sudo -n true 2>/dev/null || say "sudo required for command $@"
sudo "$@"
}
mk_owned_dir_if_not_exists() {
if [ ! -d "$1" ]; then
mkdir -p $1 &> /dev/null || (ensure warn_sudo mkdir -p $1 && ensure warn_sudo chown $USER $1)
fi
}
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
say() {
echo "kr: $@"
}
say_err() {
say "$@" >&2
}
err() {
say "$@" >&2
exit 1
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
then err "need '$1' (command not found)"
fi
}
need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
assert_nz() {
if [ -z "$1" ]; then err "assert_nz $2"; fi
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
"$@"
need_ok "command failed: $*"
}
# This is just for indicating that commands' results are being
# intentionally ignored. Usually, because it's being executed
# as part of error handling.
ignore() {
run "$@"
}
# Runs a command and prints it to stderr if it fails.
run() {
"$@"
local _retval=$?
if [ $_retval != 0 ]; then
say_err "command failed: $*"
fi
return $_retval
}
install "$@"