forked from byassine52/Demo-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·176 lines (155 loc) · 4.55 KB
/
setup.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
#!/usr/bin/env sh
#===============================================================================
#
# FILE: setup.sh
#
# USAGE: ./setup.sh
#
# DESCRIPTION: Development Environment Setup Script
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Yassine ElBadaoui,
# ORGANIZATION: TORANOTC
# CREATED: 2021/04/26 17:54
# REVISION: ---
#===============================================================================
# shellcheck disable=SC3000-SC4000
set -o nounset # Treat unset variables as an error
export PATH="$PATH:/usr/local/bin"
# ENVIRONMENT="${1-dev}"
# BIN_FOLDER='/usr/local/bin'
# GEM_INSTALL="sudo gem install -n ${BIN_FOLDER}"
# Global Variables ##########################################
USER_INFO_SHELL=".userinfo.sh"
# General Functions ##########################################
_command_found() {
command -v "${1}" >/dev/null 2>&1
}
# Setup Development Environment ##########################################
_save_git_author_info() {
# shellcheck disable=SC1091
# shellcheck source=.
if [ -f "${USER_INFO_SHELL}" ]; then
source "${USER_INFO_SHELL}"
fi
echo "Set user Git author name to \"${GIT_AUTHOR_NAME}\"."
git config user.name "${GIT_AUTHOR_NAME}"
echo "Set user Git author email address to \"${GIT_AUTHOR_EMAIL}\"."
git config user.email "${GIT_AUTHOR_EMAIL}"
}
_read_user_info() {
# shellcheck disable=SC1091
# shellcheck source=.
if [ -f "${USER_INFO_SHELL}" ]; then
echo "Load ${USER_INFO_SHELL}"
source "${USER_INFO_SHELL}"
_fullname="${GIT_AUTHOR_NAME}"
_email="${GIT_AUTHOR_EMAIL}"
fi
if [ -z "${_fullname+x}" ]; then
printf "Enter your full name: "
read -r _fullname
_fullname="$(printf '%s' "${_fullname}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
if [ -z ${_email+x} ]; then
printf "Enter your work e-mail address: "
read -r _email
_email="$(printf '%s' "${_email}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
if [ ! -f "${USER_INFO_SHELL}" ]; then
cat <<-EOT >"${USER_INFO_SHELL}"
GIT_AUTHOR_NAME="${_fullname}"
GIT_AUTHOR_EMAIL=${_email}
GIT_COMMITTER_NAME="${_fullname}"
GIT_COMMITTER_EMAIL=${_email}
EOT
echo "Saved user info into \"${USER_INFO_SHELL}\""
fi
echo "This script will be using the following information in this session:"
echo "Full Name: \"${_fullname}\""
echo "Email: \"${_email}\""
echo
}
# Generate SSH keys if needed
_generate_ssh_keys() {
local RSA_KEY_PATH=~/.ssh/id_rsa
local ED25519_KEY_PATH=~/.ssh/id_ed25519
if [ ! -f ${RSA_KEY_PATH} ]; then
echo "Generating RSA Key ..."
ssh-keygen -t rsa -b 4096 -f ${RSA_KEY_PATH} -C "${GIT_AUTHOR_EMAIL}" -N ''
fi
if [ ! -f ${ED25519_KEY_PATH} ]; then
echo "Generating Ed25519 Key ..."
ssh-keygen -t ed25519 -f ${ED25519_KEY_PATH} -C "${GIT_AUTHOR_EMAIL}" -N ''
fi
}
# Install Homebrew and Homebrew formulas
_homebrew_formula_install() {
hash brew >/dev/null 2>&1 || ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap Homebrew/bundle
brew bundle --no-lock --verbose
}
# Install Xcode Command Line Tools
_xcode_commandline_tools_install() {
xcode-select --install
sleep 1
osascript <<-EOD
tell application "System Events"
tell process "Install Command Line Developer Tools"
keystroke return
click button "Agree" of window "License Agreement"
end tell
end tell
EOD
if ! xcode-select -p >/dev/null 2>&1; then
echo "Installing Xcode Command Line Tools ..."
xcode-select --install
fi
}
# Install Git LFS hooks
_git_lfs_install() {
git lfs install
}
# Install Bundler
_bundle_install_from_gemfile() {
local VENDOR_PATH='vendor/bundle'
echo
if ! _command_found bundle; then
echo "Installing Bundler ..."
echo "Please input the login password for the following user: \"${USER}\" (The user should have administrative privilege):"
# ${GEM_INSTALL} bundler
gem install bundler
fi
echo "Updating Bundler ..."
bundle update --bundler
echo "Installing needed commands ..."
bundle install --path="${VENDOR_PATH}" --verbose
}
# Install cocoapods pods
_pod_install() {
echo
echo "Installing pods ..."
bundle exec pod install --repo-update --verbose
}
# Main ##########################################
_additional_homebrew_formulas_install() {
brew bundle --file=/dev/stdin <<<EOT
brew "rbenv"
EOT
gem install bundler
}
_main() {
_read_user_info
_save_git_author_info
# _additional_homebrew_formulas_install
_generate_ssh_keys
# _xcode_commandline_tools_install
_homebrew_formula_install
_bundle_install_from_gemfile
_pod_install
_git_lfs_install
}
_main