forked from Netflix/photon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·121 lines (87 loc) · 4.7 KB
/
bootstrap.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
#!/usr/bin/env bash
# This script:
# - Is intended to quickly get people up and running using Photon
# - Builds and installs Photon on Mac & Linux
# - Generates an IMP validator script in /usr/local/bin/photon_imp_validator.sh
# - Can be run using \curl -sSL https://raw.githubusercontent.com/Netflix/photon/master/bootstrap.sh | bash
[email protected]:Netflix/photon.git
photon_git_repo_parent_dir=~/Projects/stash
photon_git_repo_dir=${photon_git_repo_parent_dir}/photon
photon_install_dir=~/dev/photon_builds/$(date +"%Y-%m-%d")
photon_validator_script_to_generate=${photon_install_dir}/photon_imp_validator.sh
photon_validator_script_install_dir=/usr/local/bin
photon_validator_script_installed_path=${photon_validator_script_install_dir}/photon_imp_validator.sh
die() { echo "$@" 1>&2 ; exit 1; }
echo "Checking whether git is installed.."
git --version 2>&1 >/dev/null
GIT_IS_AVAILABLE=$?
if [ ! $GIT_IS_AVAILABLE -eq 0 ]; then
die "Git is not installed, please install it. On Mac you can type 'brew install git', on Ubuntu: 'sudo apt-get install git', on CentOS/Redhat: sudo yum install git"
else
echo "Git found"
fi
echo "Checking for JDK / Java compiler.."
if type -p javac; then
echo "Found Java compiler in $(which javac)"
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/javac" ]]; then
echo "Found Java compiler in ${JAVA_HOME}/bin/javac"
else
die "Error: JDK not found, please install the latest version and make sure the JAVA_HOME environment variable is set correctly."
fi
if [ ! -e ${photon_git_repo_dir} ] ; then
echo "Git repo does not exist here, creating it: ${photon_git_repo_dir}"
mkdir -p $photon_git_repo_dir || die "Couldn't create git repo dir"
cd $photon_git_repo_parent_dir
echo "Cloning git repo: git clone ${photon_git_repo_url}"
git clone ${photon_git_repo_url} || die "Error cloning git repo"
fi
echo "Building Photon.."
echo "Changing to build dir: cd ${photon_git_repo_dir}"
cd ${photon_git_repo_dir} || die "Error: can't cd to ${photon_git_repo_dir}"
echo "Fetching latest code.."
git fetch || die "Error running git fetch"
echo "Determining the latest release.."
latest_release=$(curl -s https://api.github.com/repos/netflix/photon/releases/latest | grep 'tag_name' | grep -o 'v.*"' | tr -d '"')
echo "Latest release found: ${latest_release}"
check_this_out=master
if [[ ! -z "${latest_release}" ]] ; then
check_this_out=${latest_release}
fi
echo "Checking out ${check_this_out}"
git checkout ${check_this_out} || die "Error: can't checkout ${check_this_out} in ${photon_git_repo_dir}"
echo "Cleaning the build dir"
./gradlew clean || die "Failure while running ./gradlew clean"
echo "Building Photon"
./gradlew build || die "Failure while running ./gradlew build"
echo "Getting dependencies"
./gradlew getDependencies || die "Failure while running ./gradlew getDependencies"
if [ -e ${photon_install_dir} ] ; then
echo "Photon install dir already exists, removing: rm -rf ${photon_install_dir}"
rm -rf ${photon_install_dir}
fi
echo "Creating a dir to install the java classes: ${photon_install_dir}"
mkdir -p ${photon_install_dir} || die "Error running mkdir -p ${photon_install_dir}"
echo "Installing java classes"
cp -r ./build/libs ${photon_install_dir}/ || die "Error running cp -r ./build/libs ${photon_install_dir}/"
echo "Creating IMP validation script: ${photon_validator_script_to_generate}"
cat <<EOT > ${photon_validator_script_to_generate}
#!/usr/bin/env bash
set -x
java -cp ${photon_install_dir}/libs/*:* com.netflix.imflibrary.app.IMPAnalyzer \${1}
EOT
echo "Installing photon validator script to ${photon_validator_script_install_dir}/"
if [ -w ${photon_validator_script_install_dir} ] ; then
cp ${photon_validator_script_to_generate} ${photon_validator_script_install_dir}/ || echo "Unable to install validation script here: ${photon_validator_script_install_dir}"
echo "Setting permissions: chmod ugo+x ${photon_validator_script_installed_path}"
chmod ugo+x ${photon_validator_script_installed_path} || die "Error setting permissions on IMP validator script: chmod ugo+x ${photon_validator_script_installed_path} "
else
sudo cp ${photon_validator_script_to_generate} ${photon_validator_script_install_dir}/ || echo "Unable to install validation script here: ${photon_validator_script_install_dir}"
echo "Setting permissions: sudo chmod ugo+x ${photon_validator_script_installed_path}"
sudo chmod ugo+x ${photon_validator_script_installed_path} || die "Error setting permissions on IMP validator script: chmod ugo+x ${photon_validator_script_installed_path} "
fi
echo "Done"
cat <<EOT
To run IMP validation:
photon_imp_validator.sh </dir/containing/imp|/path/to/assetmap.xml>
A validation report will be created named: </path/to/imp>_IMP_validation_output.txt
EOT