Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Introduce shellcheck to lint .sh scripts #263

Merged
merged 19 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*_shasums_latest.sh
manifest_commands.sh
hadolint/
shellcheck/
push_commands.sh
144 changes: 71 additions & 73 deletions 10/jdk/alpine/slim-java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@ set -o pipefail
# Parse arguments
argc=$#
if [ ${argc} != 1 ]; then
echo " Usage: `basename $0` Full-JDK-path"
message=$(basename "$0")
echo " Usage: ${message} Full-JDK-path"
exit 1
fi

# Validate prerequisites(tools) necessary for making a slim build
tools="jar jarsigner pack200 strip"
for tool in ${tools};
do
if [ "`which ${tool}`" == "" ]; then
echo "${tool} not found, please add ${tool} into PATH"
exit 1
fi
command -v "${tool}" >/dev/null 2>&1 || { echo >&2 "${tool} not found, please add ${tool} into PATH"; exit 1; }
done

# Set input of this script
src=$1
src="$1"
# Store necessary directories paths
basedir=$(dirname ${src})
scriptdir=`dirname $0`
target=${basedir}/slim
basedir=$(dirname "${src}")
scriptdir=$(dirname "$0")
target="${basedir}"/slim

# Files for Keep and Del list of classes in rt.jar
keep_list="${scriptdir}/slim-java_rtjar_keep.list"
Expand Down Expand Up @@ -78,7 +76,7 @@ function parse_platform_specific() {
# Which vm implementation are we running on at the moment.
function get_vm_impl() {
impl="$(java -version 2>&1 | grep "OpenJ9")";
if [ ! -z "${impl}" ]; then
if [ -n "${impl}" ]; then
echo "OpenJ9";
else
echo "Hotspot";
Expand All @@ -88,46 +86,46 @@ function get_vm_impl() {
# Strip debug symbols from the given jar file.
function strip_debug_from_jar() {
jar=$1
isSigned=`jarsigner -verify ${jar} | grep 'jar verified'`
isSigned=$(jarsigner -verify "${jar}" | grep 'jar verified')
if [ "${isSigned}" == "" ]; then
echo " Stripping debug info in ${jar}"
pack200 --repack --strip-debug -J-Xmx1024m ${jar}.new ${jar}
mv ${jar}.new ${jar}
pack200 --repack --strip-debug -J-Xmx1024m "${jar}".new "${jar}"
mv "${jar}".new "${jar}"
fi
}

# Trim the files in jre/lib dir
function jre_lib_files() {
echo -n "INFO: Trimming jre/lib dir..."
pushd ${target}/jre/lib >/dev/null
pushd "${target}"/jre/lib >/dev/null || return
rm -rf applet/ boot/ ddr/ deploy desktop/ endorsed/
rm -rf images/icons/ locale/ oblique-fonts/ security/javaws.policy aggressive.jar deploy.jar javaws.jar jexec jlm.src.jar plugin.jar
pushd ext/ >/dev/null
pushd ext/ >/dev/null || return
rm -f dnsns.jar dtfj*.jar nashorn.jar traceformat.jar
popd >/dev/null
popd >/dev/null || return
# Derive arch from current platorm.
lib_arch_dir=$(parse_platform_specific)
if [ -d ${lib_arch_dir} ]; then
pushd ${lib_arch_dir} >/dev/null
if [ -d "${lib_arch_dir}" ]; then
pushd "${lib_arch_dir}" >/dev/null || return
rm -rf classic/ libdeploy.so libjavaplugin_* libjsoundalsa.so libnpjp2.so libsplashscreen.so
# Only remove the default dir for 64bit versions
if [ "${proc_type}" == "64bit" ]; then
rm -rf default/
fi
popd >/dev/null
popd >/dev/null || return
fi
popd >/dev/null
popd >/dev/null || return
echo "done"
}

# Trim the files in the jre dir
function jre_files() {
echo -n "INFO: Trimming jre dir..."
pushd ${target}/jre >/dev/null
pushd "${target}"/jre >/dev/null || return
rm -f ASSEMBLY_EXCEPTION LICENSE THIRD_PARTY_README
rm -rf bin
ln -s ../bin bin
popd >/dev/null
popd >/dev/null || return
echo "done"
}

Expand All @@ -136,56 +134,56 @@ function charset_files() {

# 2.3 Special treat for removing ZOS specific charsets
echo -n "INFO: Trimming charsets..."
mkdir -p ${root}/charsets_class
pushd ${root}/charsets_class >/dev/null
jar -xf ${root}/jre/lib/charsets.jar
mkdir -p "${root}"/charsets_class
pushd "${root}"/charsets_class >/dev/null || return
jar -xf "${root}"/jre/lib/charsets.jar
ibmEbcdic="290 300 833 834 838 918 930 933 935 937 939 1025 1026 1046 1047 1097 1112 1122 1123 1364"

# Generate sfj-excludes-charsets list as well. (OpenJ9 expects the file to be named sfj-excludes-charsets).
[ ! -e ${root}/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets ] || rm -rf ${root}/jre/lib/sfj/sun/nio/cs/ext/sfj-excludes-charsets
[ ! -e "${root}"/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets ] || rm -rf "${root}"/jre/lib/sfj/sun/nio/cs/ext/sfj-excludes-charsets
exclude_charsets=""

for charset in ${ibmEbcdic};
do
rm -f sun/nio/cs/ext/IBM${charset}.class
rm -f sun/nio/cs/ext/IBM${charset}\$*.class
rm -f sun/nio/cs/ext/IBM"${charset}".class
rm -f sun/nio/cs/ext/IBM"${charset}"\$*.class

exclude_charsets="${exclude_charsets} IBM${charset}"
done
mkdir -p $root/jre/lib/slim/sun/nio/cs/ext
echo ${exclude_charsets} > ${root}/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets
cp ${root}/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets sun/nio/cs/ext/
mkdir -p "${root}"/jre/lib/slim/sun/nio/cs/ext
echo "${exclude_charsets}" > "${root}"/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets
cp "${root}"/jre/lib/slim/sun/nio/cs/ext/sfj-excludes-charsets sun/nio/cs/ext/

jar -cfm ${root}/jre/lib/charsets.jar META-INF/MANIFEST.MF *
popd >/dev/null
rm -rf ${root}/charsets_class
jar -cfm "${root}"/jre/lib/charsets.jar META-INF/MANIFEST.MF ./*
popd >/dev/null || return
rm -rf "${root}"/charsets_class
echo "done"
}

# Trim the rt.jar classes. The classes deleted are as per slim-java_rtjar_del.list
function rt_jar_classes() {
# 2.4 Remove classes in rt.jar
echo -n "INFO: Trimming classes in rt.jar..."
mkdir -p ${root}/rt_class
pushd ${root}/rt_class >/dev/null
jar -xf ${root}/jre/lib/rt.jar
mkdir -p ${root}/rt_keep_class
for class in $(cat ${keep_list} | grep -v "^#");
mkdir -p "${root}"/rt_class
pushd "${root}"/rt_class >/dev/null || return
jar -xf "${root}"/jre/lib/rt.jar
mkdir -p "${root}"/rt_keep_class
grep -v '^#' < "${keep_list}" | while IFS= read -r class
do
cp --parents ${class}.class ${root}/rt_keep_class/ >null 2>&1
cp --parents ${class}\$*.class ${root}/rt_keep_class/ >null 2>&1
cp --parents "${class}".class "${root}"/rt_keep_class/ >null 2>&1
cp --parents "${class}"\$*.class "${root}"/rt_keep_class/ >null 2>&1
done

for class in $(cat ${del_list} | grep -v "^#");
grep -v '^#' < "${del_list}" | while IFS= read -r class
do
rm -rf ${class}
rm -rf "${class}"
done
cp -rf ${root}/rt_keep_class/* ./
rm -rf ${root}/rt_keep_class
cp -rf "${root}"/rt_keep_class/* ./
rm -rf "${root}"/rt_keep_class

# 2.5. Restruct rt.jar
jar -cfm ${root}/jre/lib/rt.jar META-INF/MANIFEST.MF *
popd >/dev/null
jar -cfm "${root}"/jre/lib/rt.jar META-INF/MANIFEST.MF ./*
popd >/dev/null || return
rm -rf rt_class
echo "done"
}
Expand All @@ -194,18 +192,18 @@ function rt_jar_classes() {
function strip_jar() {
# Using pack200 to strip debug info in jars
echo "INFO: Strip debug info from jar files"
list="`find . -name *.jar`"
list=$(find . -name "*.jar")
for jar in ${list};
do
strip_debug_from_jar ${jar}
strip_debug_from_jar "${jar}"
done
}

# Strip debug information from share libraries
function strip_bin() {
echo -n "INFO: Stripping debug info in object files..."
find bin -type f ! -path */java-rmi.cgi -exec strip -s {} \;
find . -name *.so* -exec strip -s {} \;
find bin -type f ! -path "./*"/java-rmi.cgi -exec strip -s {} \;
find . -name "*.so*" -exec strip -s {} \;
find . -name jexec -exec strip -s {} \;
echo "done"
}
Expand All @@ -226,54 +224,54 @@ function srczip_files() {

# Remove unnecessary jmod files
function jmod_files() {
if [ ! -d ${target}/jmods ]; then
if [ ! -d "${target}"/jmods ]; then
return;
fi
pushd ${target}/jmods >/dev/null
for jfile in $(cat ${del_jmod_list} | grep -v "^#");
pushd "${target}"/jmods >/dev/null || return
grep -v '^#' < "${del_jmod_list}" | while IFS= read -r jfile
do
rm -rf ${jfile}
rm -rf "${jfile}"
done
popd >/dev/null
popd >/dev/null || return
}

# Remove unnecessary tools
function bin_files() {
echo -n "INFO: Trimming bin dir..."
pushd ${target}/bin >/dev/null
for binfile in $(cat ${del_bin_list} | grep -v "^#");
pushd "${target}"/bin >/dev/null || return
grep -v '^#' < "${del_bin_list}" | while IFS= read -r binfile
do
rm -rf ${binfile}
rm -rf "${binfile}"
done
popd >/dev/null
popd >/dev/null || return
}

# Remove unnecessary tools and jars from lib dir
function lib_files() {
echo -n "INFO: Trimming bin dir..."
pushd ${target}/lib >/dev/null
for binfile in $(cat ${del_lib_list} | grep -v "^#");
pushd "${target}"/lib >/dev/null || return
grep -v '^#' < "${del_lib_list}" | while IFS= read -r libfile
do
rm -rf ${binfile}
rm -rf "${libfile}"
done
popd >/dev/null
popd >/dev/null || return
}

# Create a new target directory and copy over the source contents.
cd ${basedir}
mkdir -p ${target}
cd "${basedir}" || exit
mkdir -p "${target}"
echo "Copying ${src} to ${target}..."
cp -rf ${src}/* ${target}/
cp -rf "${src}"/* "${target}"/

pushd ${target} >/dev/null
root=`pwd`
pushd "${target}" >/dev/null || exit
root=$(pwd)
echo "Trimming files..."

# Remove examples documentation and sources.
rm -rf demo/ sample/ man/

# jre dir may not be present on all builds.
if [ -d ${target}/jre ]; then
if [ -d "${target}"/jre ]; then
# Trim file in jre dir.
jre_files

Expand Down Expand Up @@ -312,8 +310,8 @@ pushd ${target} >/dev/null
bin_files

# Remove temp folders
rm -rf ${root}/jre/lib/slim ${src}
popd >/dev/null
rm -rf "${root}"/jre/lib/slim "${src}"
popd >/dev/null || exit

mv ${target} ${src}
mv "${target}" "${src}"
echo "Done"
Loading