-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall-gcc-without-xcode
executable file
·119 lines (104 loc) · 2.68 KB
/
install-gcc-without-xcode
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
#!/bin/zsh
# ------------------------------------------------------------------------------
# FILE: install-gcc-without-xcode
# DESCRIPTION: Installs GCC Without Xcode.
# AUTHOR: Sorin Ionescu <[email protected]>
# ------------------------------------------------------------------------------
script_name="${0:t}"
script_version='1.0.2'
cached_argv="${argv}"
# Writes to standard error.
function print-error() {
print "${script_name}: ${@}" >&2
}
# Writes to standard output.
function print-info() {
print "${@}" >&1
}
# Writes version information to standard errror.
function version() {
print "${script_name} ${script_version}
Copyright (c) 2011 Sorin Ionescu
This program is free software. You may modify or distribute it
under the terms of the MIT License." >&2
}
# Writes help to standard error.
function help() {
print "Usage: ${script_name} [‐option ...] archive [directory]
Options:
-v, --version Display version and copyright
-h, --help Display this help
Report bugs to <[email protected]>." >&2
}
# Parse switches.
while [[ "${1}" == -* ]]; do
case "${1}" in
( -v | --version )
version
exit 0
;;
( -h | --help )
help
exit 0
;;
( -- )
shift
break
;;
( -* )
print-error "invalid option: ${1}"
help
exit 0
;;
esac
done
# Get archive.
if (( ${#} < 1 )); then
print-error "No archive given."
help
exit 1
else
if [[ ! -e "${1}" ]]; then
print-error "Archive '${1}' does not exist."
help
exit 1
else
archive="$(cd "${1:h}" && pwd)/${1:t}"
if [[ "${archive}" == *.xz ]]; then
if (( ! ${+commands[xzcat]} )); then
print-error "Cannot extract '${archive}' because XZ Utils are not installed."
exit 1
else
decompressor='xzcat'
fi
else
decompressor='gzcat'
fi
shift
fi
fi
# Get directory.
if (( ${#} < 1 )); then
print-error "No directory given, assuming /."
directory='/'
else
if [[ ! -e "${1}" ]]; then
print-error "Directory '${1}' does not exist."
help
exit 1
else
directory="${1}"
shift
fi
fi
# Root is required to install.
if [[ ! -w "${directory}" ]]; then
print-info "Root privileges are required; running sudo..."
exec sudo "${0}" "${cached_argv[@]}"
exit ${?}
fi
print-info "Installing:"
print-info " ${archive}"
cd "${directory}" \
&& "${decompressor}" < "${archive}" \
| cpio -idm 2> /dev/null