This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·147 lines (116 loc) · 3.44 KB
/
install
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
#!/usr/bin/env bash
# cadsoft_eagle_git_attributes
#
# Copyright 2016 Andrew Countryman <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the specific language governing
# permissions and limitations under the License.
# File: install
# Description: Install script for the CadSoft EAGLE git attributes.
function display_help {
echo "NAME"
echo " install - install the CadSoft EAGLE git attributes"
echo
echo "SYNOPSIS"
echo " install --help"
echo " install --version"
echo " install (--global|--local <path>)"
echo
echo "OPTIONS"
echo " --help"
echo " Display this help."
echo " --version"
echo " Display version."
echo " --global"
echo " Write the attributes to the global (user) git configuration file."
echo " --local <path>"
echo " Write the attributes to a local (repository) git configuration file."
echo
echo "EXAMPLES"
echo " install --help"
echo " install --version"
echo " install --global"
echo " install --local ~/projects/foo"
}
# script version
VERSION="1.0.1"
# project clean filter
FILTER_PROJECT_CLEAN=\
'sed'\
' -e '"'"'/^\[Eagle\]\|^\[Globals\]/,/^\s*$/!d'"'"\
' -e '"'"'/^\[Eagle\]/,/^\s*$/{/^\[Eagle\]\|^Version=\|^Globals=\|^\s*$/!d;}'"'"\
' -e '"'"'/^\[Globals\]/,/^\s*$/{/^\s*$/d;}'"'"
# verify there are arguments
if [[ $# -eq 0 ]]; then
( >&2 echo "install: no arguments, aborting" )
( >&2 echo "install: try 'install --help' for more information" )
exit 1
fi
# read in arguments
while [[ $# -gt 0 ]]; do
option="$1"
case $option in
--help)
display_help
exit 0
;;
--version)
echo "install: version $VERSION"
exit 0
;;
--global)
GLOBAL=true
;;
--local)
LOCAL=true
REPOSITORY_DIR=$( readlink -f "$2" )
INITIAL_DIR=$( pwd )
shift
;;
--*|-)
( >&2 echo "install: unrecognized option '$option', aborting" )
exit 1
;;
esac
shift
done
# verify the attributes scope was specified
if [[ -z $GLOBAL && -z $LOCAL ]]; then
( >&2 echo "install: attributes scope not specified, aborting" )
exit 1
fi
# configure for global installation
if [[ "$GLOBAL" == true ]]; then
SCOPE="--global"
fi
# configure for local installation
if [[ "$LOCAL" == true ]]; then
SCOPE="--local"
cd "$REPOSITORY_DIR"
if [[ $? != 0 ]]; then
( >&2 echo "install: $REPOSITORY_DIR does not exist, aborting" )
exit 1
fi
fi
# install the project filter
git config "$SCOPE" filter.cadsoft_eagle_project.clean "$FILTER_PROJECT_CLEAN"
if [[ $? != 0 ]]; then
( >&2 echo "install: git configuration failed, aborting" )
exit 1
fi
# cleanup
if [[ "$LOCAL" == true ]]; then
cd "$INITIAL_DIR"
if [[ $? != 0 ]]; then
( >&2 echo "install: unable to return to initial directory, aborting" )
exit 1
fi
fi
exit 0