JDK環境パラメータを自動的に設置する
ファイル名:jdk.sh
中身:
#!/bin/bash
find “$PWD" -type f \( -iname '*.bin’ \) -print0 | xargs -0 chmod +x
find -type f \( -iname '*.bin’ \) -print |
while read filename
do
case “$filename" in
*.bin)
xterm -e “$filename" && rm -if “$filename"
;;
esac
done
OLDIFS=$IFS
IFS=$’\n’
for line in `cat ~/.bashrc`
do
if [[ “$line" =~ .*export.* ]]; then
if [[ “$line" =~ .*JAVA_HOME=.* ]]; then
if [[ “$line" =~ =(\/([0-9a-zA-Z._]+))+ ]]; then
javahome=$line
fi
fi
fi
if [[ “$line" =~ export\ PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin$ ]];then
javapath=$line
fi
if [[ “$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]];then
classpath=$line
fi
done
if [ ! -n “$javahome" ]; then
sed -i '$a export JAVA_HOME=’$(pwd)’/jdk1.6.0_32’ ~/.bashrc
else
sed -i 's:’${javahome//\\/\\\\}’:export JAVA_HOME=’$(pwd)’/jdk1.6.0_25:g’ ~/.bashrc
fi
if [ ! -n “$javapath" ]; then
sed -i '$a export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin’ ~/.bashrc
fi
if [ ! -n “$classpath" ]; then
sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib’ ~/.bashrc
fi
IFS=$OLDIFS