diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index 8760f7fcaf..8736539720 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -83,20 +83,21 @@ END_OF_JCLOUDS_SCRIPT echo "aborting: $@" 1>&2 exit 1 } +alias apt-get-update="apt-get update -qq" alias apt-get-install="apt-get install -f -y -qq --force-yes" -alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)" +alias yum-install="yum --quiet --nogpgcheck -y install" function ensure_cmd_or_install_package_apt(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg ) } function ensure_cmd_or_install_package_yum(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || yum --nogpgcheck -y install $pkg + hash $cmd 2>/dev/null || yum-install $pkg } function ensure_netutils_apt() { @@ -133,44 +134,56 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +# adds JAVA_HOME and into PATH in global and user-specific profiles function setupJavaHomeInProfile() { - test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + PROFILES=(/etc/bashrc $HOME/.bashrc /etc/skel/.bashrc) + test -n "$SUDO_USER" && + PROFILES=(${PROFILES[*]} `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc) + for PROFILE in ${PROFILES[*]}; do + cat >> $PROFILE <<-'END_OF_JCLOUDS_FILE' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH END_OF_JCLOUDS_FILE + done } +# resets JAVA_HOME to what an openjdk installer created +function findOpenJDK() { + local oldJavaHome=$JAVA_HOME + unset JAVA_HOME + for CANDIDATE in $oldJavaHome `ls -d /usr/lib/jvm/java-1.6.0-openjdk-* /usr/lib/jvm/java-6-openjdk-* /usr/lib/jvm/java-6-openjdk 2>&-`; do + if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then + export JAVA_HOME=$CANDIDATE + break + fi + done +} + +# assures JDK installed and JAVA_HOME to a link at /usr/local/jdk function installOpenJDK() { - if hash apt-get 2>/dev/null; then - pkg=openjdk-7-jdk - (apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg )) && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk*|grep -v common` - # ex. lucid where jdk 7 is not present - export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-6-openjdk} - test -d $JAVA_HOME || apt-get-install openjdk-6-jdk - elif hash yum 2>/dev/null; then - #TODO: find a jdk7 yum repo - export pkg=java-1.6.0-openjdk-devel - yum --nogpgcheck -y install $pkg && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-1.6.0-openjdk-*` - else - abort "we only support apt-get and yum right now... please contribute!" - return 1 + if [ "$JAVA_HOME" == "/usr/local/jdk" ]; then + echo skipping as JAVA_HOME is already set to /usr/local/jdk + return 0 fi - test -n "$JAVA_HOME" || abort "JDK installation failed!" - ln -Fs $JAVA_HOME /usr/local/jdk + if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + echo reusing JAVA_HOME $JAVA_HOME + else + if hash apt-get 2>/dev/null; then + apt-get-update && apt-get-install openjdk-6-jdk + elif hash yum 2>/dev/null; then + yum-install java-1.6.0-openjdk-devel + else + abort "we only support apt-get and yum right now... please contribute" + fi + findOpenJDK + if [ -n "$JAVA_HOME" ]; then + echo installed JAVA_HOME $JAVA_HOME + else + abort "JDK installation failed" + fi + fi + rm -rf /usr/local/jdk + ln -Fs $JAVA_HOME /usr/local/jdk /usr/local/jdk/bin/java -version || abort "cannot run java" setupJavaHomeInProfile } @@ -199,7 +212,7 @@ END_OF_JCLOUDS_SCRIPT exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no PermitRootLogin no " 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3 - hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload + hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow setupPublicCurl || return 1 diff --git a/compute/src/test/resources/initscript_with_jboss.sh b/compute/src/test/resources/initscript_with_jboss.sh index 48ce5994fa..cf88c7512c 100644 --- a/compute/src/test/resources/initscript_with_jboss.sh +++ b/compute/src/test/resources/initscript_with_jboss.sh @@ -83,20 +83,21 @@ END_OF_JCLOUDS_SCRIPT echo "aborting: $@" 1>&2 exit 1 } +alias apt-get-update="apt-get update -qq" alias apt-get-install="apt-get install -f -y -qq --force-yes" -alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)" +alias yum-install="yum --quiet --nogpgcheck -y install" function ensure_cmd_or_install_package_apt(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg ) } function ensure_cmd_or_install_package_yum(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || yum --nogpgcheck -y install $pkg + hash $cmd 2>/dev/null || yum-install $pkg } function ensure_netutils_apt() { @@ -133,44 +134,56 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +# adds JAVA_HOME and into PATH in global and user-specific profiles function setupJavaHomeInProfile() { - test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + PROFILES=(/etc/bashrc $HOME/.bashrc /etc/skel/.bashrc) + test -n "$SUDO_USER" && + PROFILES=(${PROFILES[*]} `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc) + for PROFILE in ${PROFILES[*]}; do + cat >> $PROFILE <<-'END_OF_JCLOUDS_FILE' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH END_OF_JCLOUDS_FILE + done } +# resets JAVA_HOME to what an openjdk installer created +function findOpenJDK() { + local oldJavaHome=$JAVA_HOME + unset JAVA_HOME + for CANDIDATE in $oldJavaHome `ls -d /usr/lib/jvm/java-1.6.0-openjdk-* /usr/lib/jvm/java-6-openjdk-* /usr/lib/jvm/java-6-openjdk 2>&-`; do + if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then + export JAVA_HOME=$CANDIDATE + break + fi + done +} + +# assures JDK installed and JAVA_HOME to a link at /usr/local/jdk function installOpenJDK() { - if hash apt-get 2>/dev/null; then - pkg=openjdk-7-jdk - (apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg )) && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk*|grep -v common` - # ex. lucid where jdk 7 is not present - export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-6-openjdk} - test -d $JAVA_HOME || apt-get-install openjdk-6-jdk - elif hash yum 2>/dev/null; then - #TODO: find a jdk7 yum repo - export pkg=java-1.6.0-openjdk-devel - yum --nogpgcheck -y install $pkg && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-1.6.0-openjdk-*` - else - abort "we only support apt-get and yum right now... please contribute!" - return 1 + if [ "$JAVA_HOME" == "/usr/local/jdk" ]; then + echo skipping as JAVA_HOME is already set to /usr/local/jdk + return 0 fi - test -n "$JAVA_HOME" || abort "JDK installation failed!" - ln -Fs $JAVA_HOME /usr/local/jdk + if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + echo reusing JAVA_HOME $JAVA_HOME + else + if hash apt-get 2>/dev/null; then + apt-get-update && apt-get-install openjdk-6-jdk + elif hash yum 2>/dev/null; then + yum-install java-1.6.0-openjdk-devel + else + abort "we only support apt-get and yum right now... please contribute" + fi + findOpenJDK + if [ -n "$JAVA_HOME" ]; then + echo installed JAVA_HOME $JAVA_HOME + else + abort "JDK installation failed" + fi + fi + rm -rf /usr/local/jdk + ln -Fs $JAVA_HOME /usr/local/jdk /usr/local/jdk/bin/java -version || abort "cannot run java" setupJavaHomeInProfile } @@ -199,7 +212,7 @@ END_OF_JCLOUDS_SCRIPT exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no PermitRootLogin no " 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3 - hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload + hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow setupPublicCurl || return 1 diff --git a/compute/src/test/resources/runscript.sh b/compute/src/test/resources/runscript.sh index 7e2d5c7d48..646964a5b5 100644 --- a/compute/src/test/resources/runscript.sh +++ b/compute/src/test/resources/runscript.sh @@ -83,20 +83,21 @@ END_OF_JCLOUDS_SCRIPT echo "aborting: $@" 1>&2 exit 1 } +alias apt-get-update="apt-get update -qq" alias apt-get-install="apt-get install -f -y -qq --force-yes" -alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)" +alias yum-install="yum --quiet --nogpgcheck -y install" function ensure_cmd_or_install_package_apt(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg ) } function ensure_cmd_or_install_package_yum(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || yum --nogpgcheck -y install $pkg + hash $cmd 2>/dev/null || yum-install $pkg } function ensure_netutils_apt() { @@ -133,44 +134,56 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +# adds JAVA_HOME and into PATH in global and user-specific profiles function setupJavaHomeInProfile() { - test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + PROFILES=(/etc/bashrc $HOME/.bashrc /etc/skel/.bashrc) + test -n "$SUDO_USER" && + PROFILES=(${PROFILES[*]} `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc) + for PROFILE in ${PROFILES[*]}; do + cat >> $PROFILE <<-'END_OF_JCLOUDS_FILE' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH END_OF_JCLOUDS_FILE + done } +# resets JAVA_HOME to what an openjdk installer created +function findOpenJDK() { + local oldJavaHome=$JAVA_HOME + unset JAVA_HOME + for CANDIDATE in $oldJavaHome `ls -d /usr/lib/jvm/java-1.6.0-openjdk-* /usr/lib/jvm/java-6-openjdk-* /usr/lib/jvm/java-6-openjdk 2>&-`; do + if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then + export JAVA_HOME=$CANDIDATE + break + fi + done +} + +# assures JDK installed and JAVA_HOME to a link at /usr/local/jdk function installOpenJDK() { - if hash apt-get 2>/dev/null; then - pkg=openjdk-7-jdk - (apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg )) && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk*|grep -v common` - # ex. lucid where jdk 7 is not present - export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-6-openjdk} - test -d $JAVA_HOME || apt-get-install openjdk-6-jdk - elif hash yum 2>/dev/null; then - #TODO: find a jdk7 yum repo - export pkg=java-1.6.0-openjdk-devel - yum --nogpgcheck -y install $pkg && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-1.6.0-openjdk-*` - else - abort "we only support apt-get and yum right now... please contribute!" - return 1 + if [ "$JAVA_HOME" == "/usr/local/jdk" ]; then + echo skipping as JAVA_HOME is already set to /usr/local/jdk + return 0 fi - test -n "$JAVA_HOME" || abort "JDK installation failed!" - ln -Fs $JAVA_HOME /usr/local/jdk + if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + echo reusing JAVA_HOME $JAVA_HOME + else + if hash apt-get 2>/dev/null; then + apt-get-update && apt-get-install openjdk-6-jdk + elif hash yum 2>/dev/null; then + yum-install java-1.6.0-openjdk-devel + else + abort "we only support apt-get and yum right now... please contribute" + fi + findOpenJDK + if [ -n "$JAVA_HOME" ]; then + echo installed JAVA_HOME $JAVA_HOME + else + abort "JDK installation failed" + fi + fi + rm -rf /usr/local/jdk + ln -Fs $JAVA_HOME /usr/local/jdk /usr/local/jdk/bin/java -version || abort "cannot run java" setupJavaHomeInProfile } diff --git a/compute/src/test/resources/runscript_adminUpdate.sh b/compute/src/test/resources/runscript_adminUpdate.sh index 761e641b35..af1387e905 100644 --- a/compute/src/test/resources/runscript_adminUpdate.sh +++ b/compute/src/test/resources/runscript_adminUpdate.sh @@ -101,7 +101,7 @@ END_OF_JCLOUDS_SCRIPT exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no PermitRootLogin no " 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3 - hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload + hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/SshdConfig.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/SshdConfig.java index 2264f89f91..ec89d8fd4a 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/SshdConfig.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/SshdConfig.java @@ -49,7 +49,7 @@ public class SshdConfig implements Statement { Statement prependSshdConfig = exec(String.format( "exec 3<> %1$s && awk -v TEXT=\"%2$s\n\" 'BEGIN {print TEXT}{print}' %1$s >&3", sshdConfig, linesToPrepend)); - Statement reloadSshdConfig = exec("hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload"); + Statement reloadSshdConfig = exec("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload"); return newStatementList(prependSshdConfig, reloadSshdConfig).render(family); } diff --git a/scriptbuilder/src/main/resources/functions/installOpenJDK.sh b/scriptbuilder/src/main/resources/functions/installOpenJDK.sh index 8f24fec87c..fd32aca227 100644 --- a/scriptbuilder/src/main/resources/functions/installOpenJDK.sh +++ b/scriptbuilder/src/main/resources/functions/installOpenJDK.sh @@ -1,41 +1,53 @@ +# adds JAVA_HOME and into PATH in global and user-specific profiles function setupJavaHomeInProfile() { - test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + PROFILES=(/etc/bashrc $HOME/.bashrc /etc/skel/.bashrc) + test -n "$SUDO_USER" && + PROFILES=(${PROFILES[*]} `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc) + for PROFILE in ${PROFILES[*]}; do + cat >> $PROFILE <<-'END_OF_JCLOUDS_FILE' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH END_OF_JCLOUDS_FILE + done } +# resets JAVA_HOME to what an openjdk installer created +function findOpenJDK() { + local oldJavaHome=$JAVA_HOME + unset JAVA_HOME + for CANDIDATE in $oldJavaHome `ls -d /usr/lib/jvm/java-1.6.0-openjdk-* /usr/lib/jvm/java-6-openjdk-* /usr/lib/jvm/java-6-openjdk 2>&-`; do + if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then + export JAVA_HOME=$CANDIDATE + break + fi + done +} + +# assures JDK installed and JAVA_HOME to a link at /usr/local/jdk function installOpenJDK() { - if hash apt-get 2>/dev/null; then - pkg=openjdk-7-jdk - (apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg )) && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk*|grep -v common` - # ex. lucid where jdk 7 is not present - export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-6-openjdk} - test -d $JAVA_HOME || apt-get-install openjdk-6-jdk - elif hash yum 2>/dev/null; then - #TODO: find a jdk7 yum repo - export pkg=java-1.6.0-openjdk-devel - yum --nogpgcheck -y install $pkg && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-1.6.0-openjdk-*` - else - abort "we only support apt-get and yum right now... please contribute!" - return 1 + if [ "$JAVA_HOME" == "/usr/local/jdk" ]; then + echo skipping as JAVA_HOME is already set to /usr/local/jdk + return 0 fi - test -n "$JAVA_HOME" || abort "JDK installation failed!" - ln -Fs $JAVA_HOME /usr/local/jdk + if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + echo reusing JAVA_HOME $JAVA_HOME + else + if hash apt-get 2>/dev/null; then + apt-get-update && apt-get-install openjdk-6-jdk + elif hash yum 2>/dev/null; then + yum-install java-1.6.0-openjdk-devel + else + abort "we only support apt-get and yum right now... please contribute" + fi + findOpenJDK + if [ -n "$JAVA_HOME" ]; then + echo installed JAVA_HOME $JAVA_HOME + else + abort "JDK installation failed" + fi + fi + rm -rf /usr/local/jdk + ln -Fs $JAVA_HOME /usr/local/jdk /usr/local/jdk/bin/java -version || abort "cannot run java" setupJavaHomeInProfile } \ No newline at end of file diff --git a/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh b/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh index ad72ddb838..60b1b54b16 100644 --- a/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh +++ b/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh @@ -1,17 +1,18 @@ +alias apt-get-update="apt-get update -qq" alias apt-get-install="apt-get install -f -y -qq --force-yes" -alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)" +alias yum-install="yum --quiet --nogpgcheck -y install" function ensure_cmd_or_install_package_apt(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg ) } function ensure_cmd_or_install_package_yum(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || yum --nogpgcheck -y install $pkg + hash $cmd 2>/dev/null || yum-install $pkg } function ensure_netutils_apt() { diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/AdminAccessTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/AdminAccessTest.java index 0d389fec19..5c17e5a14d 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/AdminAccessTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/AdminAccessTest.java @@ -33,7 +33,7 @@ import com.google.common.io.Resources; /** * @author Adrian Cole */ -@Test(groups = "unit", singleThreaded = true) +@Test(groups = "unit", singleThreaded = true, testName = "AdminAccessTest") public class AdminAccessTest { public void testStandardUNIX() throws IOException { diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ssh/SshStatementsTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ssh/SshStatementsTest.java index bf9a628518..a66691a519 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ssh/SshStatementsTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ssh/SshStatementsTest.java @@ -38,7 +38,7 @@ public class SshStatementsTest { .append("PasswordAuthentication no").append("\n")// .append("PermitRootLogin no").append("\n")// .append("\" 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3").append("\n")// - .append("hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload").append("\n").toString()); + .append("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload").append("\n").toString()); } public void testSshdConfigUNIX() { @@ -46,7 +46,7 @@ public class SshStatementsTest { new StringBuilder().append("exec 3<> /etc/ssh/sshd_config && awk -v TEXT=\"")// .append("AddressFamily inet6").append("\n")// .append("\" 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3").append("\n")// - .append("hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload").append("\n").toString()); + .append("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload").append("\n").toString()); } } diff --git a/scriptbuilder/src/test/resources/test_adminaccess_params.sh b/scriptbuilder/src/test/resources/test_adminaccess_params.sh index 6f1e1d0589..d4f8f4acd6 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_params.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_params.sh @@ -15,6 +15,6 @@ chown -R foo /home/users/foo exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no PermitRootLogin no " 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3 -hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload +hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(0)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow diff --git a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh index 28d184988a..b567afcd42 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh @@ -15,6 +15,6 @@ chown -R defaultAdminUsername /home/users/defaultAdminUsername exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no PermitRootLogin no " 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3 -hash service 2>/dev/null && service ssh reload || /etc/init.d/ssh* reload +hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(1)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow diff --git a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh index 22d9c49096..e3d1872d3c 100644 --- a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh @@ -83,20 +83,21 @@ END_OF_JCLOUDS_SCRIPT echo "aborting: $@" 1>&2 exit 1 } +alias apt-get-update="apt-get update -qq" alias apt-get-install="apt-get install -f -y -qq --force-yes" -alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)" +alias yum-install="yum --quiet --nogpgcheck -y install" function ensure_cmd_or_install_package_apt(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg ) } function ensure_cmd_or_install_package_yum(){ local cmd=$1 local pkg=$2 - hash $cmd 2>/dev/null || yum --nogpgcheck -y install $pkg + hash $cmd 2>/dev/null || yum-install $pkg } function ensure_netutils_apt() { @@ -133,44 +134,56 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +# adds JAVA_HOME and into PATH in global and user-specific profiles function setupJavaHomeInProfile() { - test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + PROFILES=(/etc/bashrc $HOME/.bashrc /etc/skel/.bashrc) + test -n "$SUDO_USER" && + PROFILES=(${PROFILES[*]} `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc) + for PROFILE in ${PROFILES[*]}; do + cat >> $PROFILE <<-'END_OF_JCLOUDS_FILE' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH END_OF_JCLOUDS_FILE + done } +# resets JAVA_HOME to what an openjdk installer created +function findOpenJDK() { + local oldJavaHome=$JAVA_HOME + unset JAVA_HOME + for CANDIDATE in $oldJavaHome `ls -d /usr/lib/jvm/java-1.6.0-openjdk-* /usr/lib/jvm/java-6-openjdk-* /usr/lib/jvm/java-6-openjdk 2>&-`; do + if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then + export JAVA_HOME=$CANDIDATE + break + fi + done +} + +# assures JDK installed and JAVA_HOME to a link at /usr/local/jdk function installOpenJDK() { - if hash apt-get 2>/dev/null; then - pkg=openjdk-7-jdk - (apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg )) && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk*|grep -v common` - # ex. lucid where jdk 7 is not present - export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-6-openjdk} - test -d $JAVA_HOME || apt-get-install openjdk-6-jdk - elif hash yum 2>/dev/null; then - #TODO: find a jdk7 yum repo - export pkg=java-1.6.0-openjdk-devel - yum --nogpgcheck -y install $pkg && - export JAVA_HOME=`ls -d /usr/lib/jvm/java-1.6.0-openjdk-*` - else - abort "we only support apt-get and yum right now... please contribute!" - return 1 + if [ "$JAVA_HOME" == "/usr/local/jdk" ]; then + echo skipping as JAVA_HOME is already set to /usr/local/jdk + return 0 fi - test -n "$JAVA_HOME" || abort "JDK installation failed!" - ln -Fs $JAVA_HOME /usr/local/jdk + if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + echo reusing JAVA_HOME $JAVA_HOME + else + if hash apt-get 2>/dev/null; then + apt-get-update && apt-get-install openjdk-6-jdk + elif hash yum 2>/dev/null; then + yum-install java-1.6.0-openjdk-devel + else + abort "we only support apt-get and yum right now... please contribute" + fi + findOpenJDK + if [ -n "$JAVA_HOME" ]; then + echo installed JAVA_HOME $JAVA_HOME + else + abort "JDK installation failed" + fi + fi + rm -rf /usr/local/jdk + ln -Fs $JAVA_HOME /usr/local/jdk /usr/local/jdk/bin/java -version || abort "cannot run java" setupJavaHomeInProfile }