forked from yugabyte/brew-build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost_install.template
73 lines (62 loc) · 2.6 KB
/
post_install.template
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
#!/usr/bin/env bash
# Copyright (c) YugaByte, Inc.
#
# 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.
#
# This script replaces patches files and links in Homebrew/Linuxbrew installation. It replaces path
# where Homebrew/Linuxbrew was originally built with new path of the same length. In order to keep
# the path length the same we are creating symlink of required length to current Homebrew/Linuxbrew
# directory.
set -euo pipefail
. "${0%/*}/brew-common.sh"
readonly script_dir=$( cd "$( dirname "$0" )" && pwd )
if [[ ! -x $script_dir/bin/brew ]]; then
fatal "This script should be located inside Homebrew/Linuxbrew directory."
fi
# This is inserted at Homebrew/Linuxbrew build time.
readonly orig_brew_home="{{ orig_brew_home }}"
declare -i -r ORIG_LEN=${#orig_brew_home}
brew_home=$script_dir
cd "$brew_home"
LEN=${#brew_home}
if [[ $LEN -gt $ORIG_LEN ]]; then
fatal "Homebrew/Linuxbrew absolute path should be no more than $ORIG_LEN bytes, but actual" \
"length is $LEN bytes: $brew_home"
fi
get_fixed_length_path "$brew_home" "$ORIG_LEN"
readonly brew_final_path=$fixed_length_path
declare -i -r final_path_len=${#brew_final_path}
if [[ $final_path_len != $ORIG_LEN ]]; then
fatal "Homebrew/Linuxbrew should be linked to a directory having absolute path length of" \
"$ORIG_LEN bytes, but actual length is $final_path_len bytes: $brew_final_path"
fi
if [[ $brew_home != $brew_final_path ]]; then
if [[ -e $brew_final_path ]]; then
fatal "Fixed-length path '$brew_final_path' already exists"
fi
# Make the real directory be the fixed-length path, and the old name would be a link to it.
cd /
mv "$brew_home" "$brew_final_path"
create_symlink "$brew_final_path" "$brew_home"
cd "$brew_final_path"
fi
orig_brew_home_escaped=$(get_escaped_sed_re "$orig_brew_home")
brew_final_path_escaped=$(get_escaped_sed_replacement_str "$brew_final_path")
cat FILES_TO_PATCH | while read f
do
sed -i --binary "s/$orig_brew_home_escaped/$brew_final_path_escaped/g" "$f"
done
cat LINKS_TO_PATCH | while read f
do
target=$(readlink "$f")
target="${target/$orig_brew_home/$brew_final_path}"
create_symlink "$target" "$f"
done