-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·151 lines (108 loc) · 3.99 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
#!/bin/sh
PWD=$(pwd)
# generic
APPNAME="OX Coi Xcode Templates Installer"
VERSION="1.0.0"
# Destination Templates
FILE_TEMPLATES_DIR="File Templates"
PROJECT_TEMPLATES_DIR="Project Templates"
TEMPLATE_PATH="${HOME}/Library/Developer/Xcode/Templates"
FILE_TEMPLATES_PATH="${TEMPLATE_PATH}/${FILE_TEMPLATES_DIR}"
PROJECT_TEMPLATES_PATH="${TEMPLATE_PATH}/${PROJECT_TEMPLATES_DIR}"
OX_COI_TEMPLATES="OX Coi"
REPO_NAME="ox-coi-xcode-templates"
REPO_URL="https://github.com/open-xchange/${REPO_NAME}.git"
# Colors
ESC_SEQ="\x1b["
COL_RESET='\033[39m'
COL_RED='\033[31m'
COL_GREEN='\033[32m'
COL_YELLOW='\033[33m'
# If the FILE_TEMPLATES_DIR doesn't exists, it is possible that all
# templates are direct under TEMPLATE_PATH.
#
# This isn't ideal, because there might be a "Project Templates" folder, too.
# Both "File Templates" and "Project Templates" must be placed in TEMPLATE_PATH
# side by side!
#
# If this is the case we create a new FILE_TEMPLATES_DIR and move all existent
# templates into it.
# /////////////////////////////////////////////////////////////////////////////
# Generic Functions
# /////////////////////////////////////////////////////////////////////////////
function show_header() {
_HEADER=`cat <<EOT
$COL_GREEN
>> \$1 $COL_RESET
EOT
`
echo "$COL_GREEN $_HEADER $COL_RESET"
}
function show_version() {
_VERSION=`cat <<EOF
\$APPNAME, v\$VERSION
EOF
`
echo "$COL_YELLOW$_VERSION $COL_RESET"
}
# /////////////////////////////////////////////////////////////////////////////
# Installation Related Functions
# /////////////////////////////////////////////////////////////////////////////
function handle_file_templates() {
show_header "Manage 'File Templates' Directory"
if [ ! -d "${FILE_TEMPLATES_PATH}" ]; then
echo "** Directory '${FILE_TEMPLATES_DIR}' doesn't exists! Creating."
cd "${TEMPLATE_PATH}/"
TMP_DIR=".${FILE_TEMPLATES_DIR}"
mkdir "${TMP_DIR}" &>/dev/null
echo "** Directory creation done."
NUMBER_OF_FILES_IN_TEMPLATE_PATH=$(ls "${TEMPLATE_PATH}" | wc -l)
if [ $NUMBER_OF_FILES_IN_TEMPLATE_PATH -gt 0 ]; then
echo "** Moving existent templates into: '${FILE_TEMPLATES_DIR}'"
for DIR in *; do
mv "${DIR}" "${TMP_DIR}" &>/dev/null
done
echo "** Moving done."
fi
mv "${TMP_DIR}" "${FILE_TEMPLATES_DIR}" &>/dev/null
fi
echo "** Managing 'File Templates' directory done."
}
function handle_project_templates() {
show_header "Manage 'Project Templates' Directory"
if [ ! -d "${PROJECT_TEMPLATES_PATH}" ]; then
echo "** Directory '${PROJECT_TEMPLATES_DIR}' doesn't exists! Creating."
mkdir "${PROJECT_TEMPLATES_PATH}" &>/dev/null
echo "** Directory creation done."
fi
echo "** Managing 'Project Templates' directory done."
}
function install_xcode_templates() {
show_header "Install OX Coi Templates"
TMP_SYS_DIR="/tmp"
TMP_INSTALL_DIR="xctpl"
TMP_INSTALL_PATH="${TMP_SYS_DIR}/${TMP_INSTALL_DIR}"
cd "${TMP_SYS_DIR}" &>/dev/null
mkdir "${TMP_INSTALL_DIR}" &>/dev/null
cd "${TMP_INSTALL_DIR}" &>/dev/null
git clone ${REPO_URL} &>/dev/null
cd ${REPO_NAME} &>/dev/null
cp -a "./File Templates/${OX_COI_TEMPLATES}" "${FILE_TEMPLATES_PATH}/" &>/dev/null
cd "${TMP_SYS_DIR}" &>/dev/null
rm -rf "${TMP_INSTALL_DIR}" &>/dev/null
echo "** File Templates installation done."
}
# /////////////////////////////////////////////////////////////////////////////
# Start Installation
# /////////////////////////////////////////////////////////////////////////////
show_version;
handle_file_templates;
handle_project_templates;
install_xcode_templates;
# /////////////////////////////////////////////////////////////////////////////
# We're done!
# /////////////////////////////////////////////////////////////////////////////
show_header "🎉🚀🤘🏻 Hooray... Xcode templates installation successfully finished! 👏"
echo
cd "$PWD"
exit 0