-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_credenceid
339 lines (302 loc) · 15.6 KB
/
.bash_credenceid
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Michael Sattler <[email protected]>
#
# Improvements spurred on by Yash Shah, Tanmay Narang; thanks!.
#
# # ---------------------------------------------------------------------------
# # For *NIX (including macOS) and Windows (via Bash for Windows):
# #
# # https://msdn.microsoft.com/en-us/commandline/wsl/about
# # ---------------------------------------------------------------------------
#
# Work-related workflow shortcuts. To install
#
# (1) download this file (.bash_credenceid) to your home directory
# (2) add the following line into your .bash_profile:
#
# source ~/.bash_credenceid
#
# Syntax-checked with shellcheck (http://www.shellcheck.net/).
#
# -----------------------------------------------------------------------------
# To get the latest version of this file:
#
# curl -#O https://github.com/mickeys/dotfiles/blob/master/.bash_credenceid
#
# to see this file as I've written it, visit this link:
#
# https://github.com/mickeys/dotfiles/blob/master/.bash_credenceid?ts=4
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Android Debug Bridge (adb)
# ==========================
#
# As we do a lot of work with Android devices, much of our command-line time is
# spent with 'adb' and 'fastboot'. Essential to know about these is:
#
# > adb communicates with your device when it's in it's usual operating mode.
# > fastboot communicates with your device when it's in a low-level special mode.
# > the bootloader is the lowest-level mode (which you'll almost never need).
#
# Windows users can get and install adb & fastboot most quickly from:
#
# https://forum.xda-developers.com/showthread.php?p=48915118#post48915118
#
# *NIX and Windows standard installation reference information is at:
#
# https://developer.android.com/studio/command-line/adb.html
#
# To start with adb, populate your ~/.android/adb_usb.ini find instructions at:
#
# https://github.com/apkudo/adbusbini
#
# Add CID-saavy udev rules for USB debugging Android devices. Use this file:
#
# https://github.com/CredenceID/devops/blob/master/other/52-android.rules
#
# with these great instructions:
#
# http://rootzwiki.com/topic/258-udev-rules-for-any-device-no-more-starting-adb-with-sudo/
#
# optionally, here's an explanation of udev rules:
#
# https://wiki.debian.org/udev
#
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# One gets Android logs (or traces) with "adb logcat". Tracing the execution of
# adb itself is another thing entirely.
#
# adb can run in two modes: a front-end client, or a background daemon talking
# with devices or emulators. Toggling the ADB_TRACE environment variable will
# cause traces from the adb front-end to be shown on the screen, and traces
# from the server will be saved in /tmp/adb.log.
# -----------------------------------------------------------------------------
# shellcheck disable=SC2128
export ADB_TRACE='' # '' or 'all' - show connection traffic
# -----------------------------------------------------------------------------
# List and reboot devices
# -----------------------------------------------------------------------------
alias ad='adb devices' # list devices in adb mode
alias ads='adb devices | grep -v -e "List of devices attached" -e "^[[:space:]]*$" | wc -l'
alias fd='fastboot devices' # list devices in fastboot mode
alias fds='fastboot devices | wc -l' # how many fastboot devices?
alias aw='adb wait-for-device ; ad' # wait until device(s) appear; list them
alias ar='adb reboot' # reboot into normal adb operating mode
alias arr='adb reboot recovery' # reboot into recovery mode
alias arb='adb reboot bootloader' # reboot into bootloader mode
alias fc='fastboot continue' # continue with boot process
alias fr='fastboot reboot' # reboot (sometimes needs continue after)
alias adn='adb shell reboot -p' # another way to reboot into normal mode
# -----------------------------------------------------------------------------
# Managing APK (Android Package Kit) files
#
# Android apps are delivered as APKs.
# -----------------------------------------------------------------------------
#
alias all='adb shell pm list packages -f | sort' # sorted list of packages
alias al='adb shell pm list packages -f | grep credenceid' # our installed APKs
alias alp='adb shell pm list packages -f | sort'
alias ai='adb install -r' # install an APK
alias au='adb uninstall' # uninstall an APK
alias aau='adb shell pm uninstall' # when `au` just doesn't seem to work
function aii() { # aii == "adb install items"
for apk in "$@" # usage: aii x.apk {y.apk, ...}
do
n=$(basename "$apk") # full just the apk name from path
echo "Installing $n..." # be nice and announce our actions
adb install "$apk" # install the apk
done
}
# -----------------------------------------------------------------------------
# Set the Android phone 'keep awake while plugged in' setting.
#
# svc power stayon [true|false|usb|ac|wireless]
# true will set all flags ("on") (usb, ac, wireless)
# false will clear all flags ("off")
# usb/ac/wireless will set that specific flag while clearing the others
# -----------------------------------------------------------------------------
alias aawake='adb shell svc power stayon true'
alias aasleep='adb shell svc power stayon false'
# -----------------------------------------------------------------------------
# Moving files to/from Android devices
# -----------------------------------------------------------------------------
alias ap='adb push' # ap source_file destination_location
FB="$HOME/android-backup.ab" # backup filename
# shellcheck disable=SC2139
alias abackup="adb backup -obb -apk -shared -all -f $FB" # create backup
# shellcheck disable=SC2139
alias arestore="adb restore $FB" # restore from backup
# -----------------------------------------------------------------------------
# Get a screenshot (screencap) from the attached Android device
#
# (1) make a common directory to store screencaps
# (2) cause a screencap to happen on the device
# (3) pull the screencap PNG file to your current working directory
# (4) remove the screencap from the device
# (5) rename the screencap to YYMMDD_HHMMSS.png
# -----------------------------------------------------------------------------
# shellcheck disable=SC2034
_PD="/sdcard" # where screencaps are to be stored
# shellcheck disable=SC2034
_PF="screen.png" # default name of screencap
alias getpix="adb shell mkdir -p \$_PD ; adb shell screencap \$_PD/\$_PF ; \
adb pull \$_PD/\$_PF ; adb shell rm \$_PD/\$_PF ; \
mv \$_PF \`date +%Y%m%d_%H%M%S\`.png" # _\$2
# -----------------------------------------------------------------------------
# Miscellaneous
# -----------------------------------------------------------------------------
alias am='adb shell mount system' # mount UNROOTED device's file system
alias as='adb shell' # start a shell session on the device
alias ak='adb kill-server; ADB_LIBUSB=1 adb start-server; adb host-features' # stop and start the ADB server
alias ac='adb logcat | grep com.credenceid' # show only log entries by CID apps
alias adate="adb shell date -s \`date \"+%Y%m%d.%H%M%S\"\`" # set time on device
alias adw='adb wait-for-device' # don't start until any device appears
alias cpu='adb shell cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"'
alias sel='adb shell getenforce' # SELinux enforced?
alias awipe='adb shell am broadcast -a android.intent.action.MASTER_CLEAR'
alias tabbatt='adb shell cat /sys/class/power_supply/bq27520-battery/device/df_version'
alias abackup='adb backup -apk -all -f ~/Desktop/backup.ab'
alias arestore='adb restore ~/Desktop/backup.ab'
alias upj='sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist'
alias dnj='sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist'
# -----------------------------------------------------------------------------
# Install CID and test apps
#
# Change _D if you have a non-standard Box.com location on your hard drive.
# Change _V to point at the SDK (and apps) version you want to be installing.
# -----------------------------------------------------------------------------
#export _D="$HOME/Box Sync/release_candidates__PRIVATE/sdk-and-apps" # no '\'
export _D="$HOME/Box Sync/official__releases__PUBLIC/sdk-and-apps" # no '\'
export _V="20170329-sdk-1.17.00"
alias alli='for a in C-Service.apk C-SdkApp.apk ; do ai "$_D/$_V/apk/$a" ; done ; for a in C-StressApi.apk C-Demo.apk ; do ai "$_D/$_V-cid-internal-apps/$a" ; done'
# uninstall the entire CID suite
#for a in $( adb shell 'pm list packages -f' | grep -e '/data/app' | grep 'com.credenceid'| sed -e 's/.*=//' -e 's/\r//g' | tr -d '\r' ) ; do echo -n Uninstalling $a... ; au $a ; done
alias allu='for a in stressapi sdkapp service demo ; do printf "Uninstalling $a..." ; au com.credenceid.$a ; done'
# -----------------------------------------------------------------------------
# git
# ===
#
# “Do not meddle in the affairs of wizards, for they are subtle and quick to
# anger.” -― J.R.R. Tolkien, The Fellowship of the Ring
#
# git, our chosen version control system, is powerful, subtle, and (thankfully)
# not quick to anger. You may never need git in your time here, but when the day
# comes that you want to contribute to our code or our documentation, git is the
# way.
#
# git basics: git (https://git-scm.com/)
#
# see also: http://nuclearsquid.com/writings/git-tricks-tips-workflows/
# and also: http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
# -----------------------------------------------------------------------------
alias g='git' # save 66% of typing
complete -o default -o nospace -F _git g # autocomplete for 'g' as well
function ga() { git add "$1"\ ; } # add files to be tracked
function gc() { git commit -m "$@" ; } # commit changes locally
function keysx() { tr '[:upper:]' '[:lower:]' < "$1" | sort | uniq | wc -l ; }
alias gd='git diff' # see what happened
alias gh='git log --follow ' # git history for a file
alias gi='git check-ignore -v *' # see what's being ignored
#alias gl='git log --pretty=format:" ~ %s (%cr)" --no-merges'
alias gl='git log --no-merges --date=short --pretty=format:"| %cd | %s [%an]"'
alias go='git remote show origin'
alias gp='git push -u origin master' # send changes upstream
alias gs='git status --short' # see what's going on
alias gsl='git stash list' # git-stash(1)
alias gsp='git stash pop' # git-stash(1)
alias gss='git stash save' # git-stash(1)
# -----------------------------------------------------------------------------
# device-type files
#
# Populate device-type files by supplying the exact text string.
#
# Usage: dt <type> (where type can be seen in the following section.
# -----------------------------------------------------------------------------
function dt { adb shell "mkdir -p /sdcard/credenceid/ ; echo $1 > /sdcard/credenceid/device-type" ; }
# -----------------------------------------------------------------------------
# Populate device-type files without needing to memorize the exact text string.
# -----------------------------------------------------------------------------
alias dtc1="dt credenceone-v1" # c1 ~ fingerprint
alias dtc2="dt credenceone-v2" # c1 ~ fingerprint, nfc card
alias dtc3="dt credenceone-v3" # c1 ~ fingerprint, nfc card, mrz
alias dtce="dt credenceone-ektp" # c1 ~ SAM card
alias dtsl="dt starlight" # tab (obsolete) prototype
alias dttb="dt credencetab" # tab (obsolete) production
alias dtt1="dt credencetab-v1-f" # tab ~ fingerprint
alias dtt2="dt credencetab-v2-fc" # tab ~ fingerprint, nfc card
alias dtt3="dt credencetab-v3-fm" # tab ~ fingerprint, mrz
alias dtt4="dt credencetab-v4-fcm" # tab ~ fingerprint, nfc card, mrz
alias dtt1="dt trident-1" # trident ~ model 1
alias dtt2="dt trident-2" # trident ~ model 2
alias dtt2r="dt Trident-2R" # trident ~ model 2R
alias dtt3="dt trident-3" # (obsolete) legacy code (per Mark Evans)
alias dttw="dt twizzler" # aka BCAT
# -----------------------------------------------------------------------------
# 'find' is a powerful command that selects files and/or folders based upon a
# wide variety of criteria, and can apply other *NIX tools to those selected.
#
# ff ('fast find') filters out 'Permission denied' error messages, a common woe.
#
# Usage: ff ~ -name \*battery\*.sh (starting at my home directory search for that
# bash script (.sh) which had "battery" in the filename.
# -----------------------------------------------------------------------------
ff () { find "$@" 3>&2 2>&1 1>&3 | grep -v 'Permission denied' >&3; } 3>&2 2>&1
# -----------------------------------------------------------------------------
# 'lookinside' examines the *contents* of every file in the current directory
# for the text string you specify.
#
# Usage: lookinside grail
# -----------------------------------------------------------------------------
lookinside () { find . -exec grep -i "$@" {} -s \; -exec echo {} \; ; }
# -----------------------------------------------------------------------------
# Change the last character of the terminal prompt to be
#
# % - for unrooted users
# # - for rooted users (appears in red)
#
# Feel free to customize the prompt in __PS1 to your liking. An exhaustive list
# of Bash prompt special characters may be found at:
#
# https://linuxconfig.org/bash-prompt-basics
# -----------------------------------------------------------------------------
export BLACK ; export RED ; export GREEN ; export YELLOW ; export BLUE
export MAGENTA ; export CYAN ; export WHITE ; export BOLD ; export RESET
BLACK="\[$(tput setaf 0)\]" # the palette of tput color choices
RED="\[$(tput setaf 1)\]"
GREEN="\[$(tput setaf 2)\]"
YELLOW="\[$(tput setaf 3)\]"
BLUE="\[$(tput setaf 4)\]"
MAGENTA="\[$(tput setaf 5)\]"
CYAN="\[$(tput setaf 6)\]"
WHITE="\[$(tput setaf 7)\]"
BOLD="\[$(tput bold)\]" # bold the following
RESET="\[$(tput sgr0)\]" # reset colors & characteristics
__ROOT="${RED}#${RESET}" # root prompt (#) is red
__PS1="${YELLOW}\A ${CYAN}\! ${BOLD}${BLUE}\h ${YELLOW}\w${RESET}" # prompt part
if [ "$(id -u)" -eq 0 ]; # if we're the superuser (root)
then
PS1="$__PS1 $__ROOT " # use this prompt variation
else
PS1="$__PS1 % " # non-root users get this prompt
fi
# -----------------------------------------------------------------------------
# *nix command history
# -----------------------------------------------------------------------------
alias h='history' # see what happened before
HISTCONTROL=ignoredups:erasedups:ignorespace # no dups;
HISTFILE=~/.bash_eternal_history # "eternal" ~ don't get truncated
# was eternal (empty); now set at 999 (three digits easier to grok)
HISTFILESIZE=999 # "eternal" ~ no max size
HISTSIZE=999 # "eternal" ~ no max size
HISTTIMEFORMAT="[%m-%d %H:%M] " # add 24-hour timestamp to history
shopt -s checkwinsize # after each command check window size...
shopt -q -s histappend >/dev/null 2>&1 # append, don't overwrite, history file
export PROMPT_COMMAND='history -a' >/dev/null 2>&1
# -----------------------------------------------------------------------------
# Michael's transitory work stuff
# -----------------------------------------------------------------------------
alias loadtab='arb ; sleep 10 ; fastboot flash "recovery" "recovery.img" ; fastboot flash "boot" "boot.img" ; fastboot flash "system" "system.img" ; fr'
alias allimg='for i in *.img ; do echo ${i%.img} ; fastboot flash ${i%.img} $i ; done'
# --- end of .bash_credenceid ---