forked from transmute-industries/launchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·162 lines (132 loc) · 3.92 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
h#!/usr/bin/env bash
trap 'ret=$?; test $ret -ne 0 && printf "\n \e[31m?\033[0m Formation failed \e[31m?\033[0m\n" >&2; exit $ret' EXIT
set -e
ask() {
# https://djm.me/ask
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n " [?] $1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read -r reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y* | y*) return 0 ;;
N* | n*) return 1 ;;
esac
done
}
cli_is_installed() {
# set to 1 initially
local return_status=1
# set to 0 if not found
type "$1" >/dev/null 2>&1 || { local return_status=0; }
# return value
echo "$return_status"
}
copy_key_github() {
echo "Public key copied, Paste into Github"
[[ -f "$pub" ]] && cat "$pub" | pbcopy
open 'https://github.com/account/ssh'
read -r -p " ✦ Press enter to continue"
echo "SSH key"
return
}
github_key_check() {
if ask "SSH key found. Enter it in Github?" Y; then
copy_key_github
else
echo "SSH key"
fi
}
create_ssh_key() {
if ask "No SSH key found. Create one?" Y; then
ssh-keygen -t rsa
github_key_check
else
return 0
fi
}
ssh_key_setup() {
local pub=$HOME/.ssh/id_rsa.pub
if ! [[ -f $pub ]]; then
create_ssh_key
else
github_key_check
fi
}
ask_for_sudo() {
# Ask for the administrator password upfront.
sudo -v &>/dev/null
# Update existing `sudo` time stamp
# until this script has finished.
#
# https://gist.github.com/cowboy/3118588
# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
echo "Password cached"
}
###############################################################################
# PROMPT: Password
###############################################################################
echo "Caching password?"
ask_for_sudo
###############################################################################
# PROMPT: SSH Key
###############################################################################
echo 'Checking for SSH key?'
ssh_key_setup
# -----------------------------------------------------------------------------
# Homebrew
# -----------------------------------------------------------------------------
if ! [ -x "$(command -v brew)" ]; then
echo "Installing Homebrew?"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/usr/local/bin:$PATH"
export PATH="/opt/homebrew/bin:$PATH"
echo "Homebrew installed!"
else
echo "Homebrew already installed. Skipping."
fi
if brew list | grep -Fq brew-cask; then
echo "Uninstalling old Homebrew-Cask?"
brew uninstall --force brew-cask
echo "Homebrew-Cask uninstalled!"
fi
# -----------------------------------------------------------------------------
# XCode
# -----------------------------------------------------------------------------
if xpath=$(xcode-select --print-path) && test -d "${xpath}" && test -x "${xpath}"; then
echo "Xcode already installed. Skipping."
else
echo "Installing Xcode?"
xcode-select --install
echo "Xcode installed!"
fi
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
if [ ! -d "$HOME/launchpad" ]; then
echo "Downloading Launchpad Tool"
(cd $HOME; git clone [email protected]:Ashraf-Ali-aa/launchpad.git)
fi
echo "Running Launchpad Tool"
sh "$HOME/launchpad/launchpad.sh"