-
-
Save zellio/11f2c7660449e27cdbe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
### orjf --- Oracle Java RPM Fixer | |
## Copyright (c) 2014 Zachary Elliott | |
## | |
## Authors: Zachary Elliott <[email protected]> | |
## URL: | |
## Version: 0.1.0 | |
### Commentary: | |
## | |
### License: | |
## All Rights Reserved | |
## Permission is hereby granted, free of charge, to any person obtaining a | |
## copy of this software and associated documentation files (the "Software"), | |
## to deal in the Software without restriction, including without limitation | |
## the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
## and/or sell copies of the Software, and to permit persons to whom the | |
## Software is furnished to do so, subject to the following conditions: | |
## The above copyright notice and this permission notice shall be included in | |
## all copies or substantial portions of the Software, and that the name of | |
## NYU not be used in advertising or publicity pertaining to distribution of | |
## the software without specific written permission. | |
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
## DEALINGS IN THE SOFTWARE. | |
### Code: | |
set -f | |
_basename=$(\basename $0) | |
function usage { | |
\cat <<EOF | |
Usage: ${_basename} [OPTION]... | |
Specific options: | |
-p, --package Specify RPM Path. | |
-P, --java-package Specify JDK or JRE (jre). | |
-V, --java-version Specify Version of Java (7). | |
General options: | |
--debug Turn on xtrace | |
-h, --help Display this help message. | |
--version Display the version number | |
${_basename} home page: <https://github.com/zellio/zsh-config> | |
Report bugs to: <https://github.com/zellio/zsh-config/issues> | |
EOF | |
return 0 | |
} | |
function version { | |
\cat <<EOF | |
0.1.0 | |
EOF | |
} | |
function error { | |
echo -en "\e[1;31m>>> ERROR: " | |
echo -en $1 | |
echo -e "\e[0m " | |
} | |
ARGS=$(getopt \ | |
--longoptions 'java-version:,java-package:,package:,debug,help,version' \ | |
--name "$_basename" \ | |
--options 'V:P:ph' \ | |
-- "$@"); | |
if [ $? -ne 0 ]; then | |
\echo "" | |
usage | |
exit 1 | |
fi | |
eval set -- "$ARGS" | |
package='' | |
java_package='jre' | |
java_version='7' | |
while true; do | |
case "$1" in | |
-p|--package) | |
rpm_src="$2" | |
shift 2 | |
;; | |
-P|--java-package) | |
java_package="$2" | |
shift 2 | |
;; | |
-V|--java-version) | |
java_version="$2" | |
shift 2 | |
;; | |
--debug) | |
set -x | |
shift 1 | |
;; | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
--version) | |
version | |
exit 0 | |
;; | |
--) | |
shift; | |
break | |
;; | |
esac | |
done | |
pagkage_version='' | |
rpm_name='' | |
rpm_url_comp='' | |
# RPM_NAME='' | |
# PKG_VER='' | |
# RPM_URL_COMP='' | |
case "$java_version" in | |
6) | |
# http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64-rpm.bin | |
# rpm_name="${java_package}-6u45-linux-amd64.rpm" | |
package_version='1.6.0' | |
rpm_url_comp='6u45-b06' | |
[ -z "$rmp_src" ] && error "Version 6 requires you to provide the rpm" | |
;; | |
7) | |
package_version='1.7.0' | |
rpm_name="${java_package}-7u60-linux-x64.rpm" | |
rpm_url_comp='7u60-b19' | |
;; | |
8) | |
package_version='1.8.0' | |
rpm_name="${java_package}-8u5-linux-x64.rpm" | |
rpm_url_comp='8u5-b13' | |
;; | |
*) | |
error "version ${java_version} isn't supported" | |
;; | |
esac | |
if [ -z "$package" ] || [ ! -f "$package" ]; then | |
package="$(pwd)/orjb-${java-package}-${package_version}.rpm" | |
rpm_url="http://download.oracle.com/otn-pub/java/jdk/${rpm_url_comp}/${rpm_name}" | |
CURL=$(command -v curl) | |
[ -z "$CURL" ] && error 'program: curl not found.' | |
CURL_OPTS='--location' | |
CURL_HEADER='Cookie: oraclelicense=accept-securebackup-cookie' | |
"$CURL" ${CURL_OPTS} --header "$CURL_HEADER" "$rpm_url" --output "$package" | |
fi | |
RPMREBUILD=$(command -v rpmrebuild) | |
[ -z "$RPMREBUILD" ] && error 'program: rpmrebuild not found.' | |
rpmrebuild\ | |
--change-spec-preamble="sed -e 's/^Name:.*/Name: java-${package_version}-oracle${java_package}/'"\ | |
--change-spec-files="sed -e 's|.*/etc/init.d/jexec.*|# &|'"\ | |
--directory=.\ | |
--package "$package" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment