diff --git a/installer.sh b/installer.sh index 925b743..f888a4d 100755 --- a/installer.sh +++ b/installer.sh @@ -1,63 +1,73 @@ #!/bin/bash # A Bash script to install Linux Libraries used on EV3Dev-lang-java. # Author: Juan Antonio Breña Moral, bren@juanantonio.info +# Author: Jakub Vaněk, linuxtardis@gmail.com + +MODULE="unknown" +MODULE_FOLDER="module2" +ROOT_URL="https://raw.githubusercontent.com/ev3dev-lang-java/installer/develop/modules" + +# $1 => module name +function download_module() { + pushd "./$MODULE_FOLDER" >/dev/null + wget -qN "$ROOT_URL/$1.sh" + popd >/dev/null +} + +# $1 => module name +function run_module() { + MODULE="$1" + createHeader "$1" + download_module "$1" + source "$MODULE_FOLDER/$1.sh" +} + +# $1 => module name +function inc_module() { + download_module "$1" + source "$MODULE_FOLDER/$1.sh" +} + +function init_installer() { + echo "Init installer" + rm -rf "$MODULE_FOLDER" + mkdir -p "$MODULE_FOLDER" +} echo echo "##############################" echo "# EV3Dev-lang-java Installer #" echo "##############################" -echo "# Last update: 2018/03/30 #" +echo "# Last update: 2018/04/14 #" echo "##############################" echo -OFF=0 -MODULE="EMPTY" -MODULE_FOLDER="module2" -function runModule(){ - if ! [ "$2" == "$OFF" ]; then - createHeader $1 - fi - local domain="https://raw.githubusercontent.com/ev3dev-lang-java/installer/develop/modules" - wget -N "$domain/$1.sh" - MODULE=$1 - mv ./$1.sh ./$MODULE_FOLDER/$1.sh - source "$MODULE_FOLDER/$1.sh" -} -function initInstaller(){ - echo "Init installer" - mkdir -p $MODULE_FOLDER - rm ./$MODULE_FOLDER/* -} +#Init +init_installer +inc_module vars +inc_module utilities -MODE_HELP="help" -MODE_JDK="jdk" -MODE_BATTERY_MONITOR="batteryMonitor" -MODE_COPY_INSTALLER="copy-installer" -MODE_EXTENDED="extended" +run_module platform -#Init -initInstaller -runModule utilities 0 -if [ "$1" == "$MODE_HELP" ]; then - runModule help -fi +if [ "$1" == "help" ]; then + run_module help -if [ "$1" == "$MODE_COPY_INSTALLER" ]; then - CREDENTIAL=$2 - runModule copy-installer -fi +elif [ "$1" == "copy-installer" ]; then + CREDENTIAL="$2" + run_module copy-installer -runModule platform -runModule java +elif [ "$1" == "batteryMonitor" ]; then + run_module java + run_module battery-monitor -if [ "$1" == "$MODE_BATTERY_MONITOR" ]; then - runModule battery-monitor -fi +elif [ "$1" == "extended" ]; then + run_module java + run_module native-libraries -if [ "$1" == "$MODE_EXTENDED" ]; then - runModule native-libraries +else + run_module java fi exit 0 diff --git a/modules/battery-monitor.sh b/modules/battery-monitor.sh index f0cf246..869b857 100644 --- a/modules/battery-monitor.sh +++ b/modules/battery-monitor.sh @@ -1,51 +1,36 @@ #!/bin/bash -function installBatteryMonitor() { - cd /home/robot - wget https://github.com/ev3dev-lang-java/batteryMonitor/raw/release/v0.2.0-RELEASE/releases/batteryMonitor-0.2.0-RELEASE.zip - - #TODO Move block to function - isInstalled unzip - if [ "$INSTALLED" == "$INSTALLED_NO" ]; then - if [ "$PLATFORM" == "$EV3" ]; then - - mkdir -p packages - cd packages - wget http://ftp.us.debian.org/debian/pool/main/u/unzip/unzip_6.0-16+deb8u3_armel.deb - sudo dpkg -i unzip_6.0-16+deb8u3_armel.deb - cd .. - else - apt-get install unzip - fi - - fi - - #TODO Move to a function - unzip batteryMonitor-0.2.0-RELEASE.zip - mv batteryMonitor-0.2.0-RELEASE batteryMonitor - cd batteryMonitor - chmod +x ./start.sh - chmod +x ./stop.sh - cp batteryMonitor-service.sh /etc/init.d - cd /etc/init.d - chmod +x batteryMonitor-service.sh +function battmon_install() { + wget "$BATTMON_URL" -O "$BATTMON_FILE" + + apt-get install unzip + + unzip "$BATTMON_FILE" + mv "$BATTMON_ZIPBASE" "$BATTMON_BASE" + chmod +x "$BATTMON_BASE/start.sh" + chmod +x "$BATTMON_BASE/stop.sh" + chmod +x "$BATTMON_BASE/batteryMonitor-service.sh" + ln -s "$BATTMON_BASE/batteryMonitor-service.sh" "/etc/init.d" + update-rc.d batteryMonitor-service.sh defaults - cd /home/robot/batteryMonitor - ./start.sh & + "$BATTMON_BASE/start.sh" & } -if [ "$PLATFORM" == "$UNKNOWN" ]; then - echo "This platform: $PLATFORM is not suitable for Battery Monitor." - echo -else +if [ "$PLATFORM" == "ev3" ] || + [ "$PLATFORM" == "brickpi" ] || + [ "$PLATFORM" == "brickpi3" ] || + [ "$PLATFORM" == "pistorms" ]; then - if [ -d "/home/robot/batteryMonitor" ]; then + if [ -d "$BATTMON_BASE" ]; then echo "We have detected a previous installation." echo "We will skip this step." else - installBatteryMonitor + battmon_install fi +else + echo "This platform: $PLATFORM is not suitable for Battery Monitor." + echo fi -createHeader "END $MODULE" \ No newline at end of file +createHeader "END $MODULE" diff --git a/modules/copy-installer.sh b/modules/copy-installer.sh index 4842e3e..ad416f9 100644 --- a/modules/copy-installer.sh +++ b/modules/copy-installer.sh @@ -1,11 +1,11 @@ #!/bin/bash -if [ -e "/home/robot/installer/installer.sh" ]; then - echo $CREDENTIAL - ssh $CREDENTIAL 'uptime' - ssh $CREDENTIAL 'sudo mkdir /home/robot/installer/' - scp "/home/robot/installer/installer.sh" "$CREDENTIAL:/home/robot/installer" - ssh $CREDENTIAL 'sudo chmod +x /home/robot/installer.sh' +if [ -e "$INSTALLER_EXE" ]; then + chmod +x "$INSTALLER_EXE" + + echo "SSHing to: $CREDENTIAL" + ssh "$CREDENTIAL" "uptime; sudo mkdir -p $INSTALLER_DIR" + scp "$INSTALLER_EXE" "$CREDENTIAL:$INSTALLER_DIR" exit else echo "Sorry, the installer didn´t detect the installer" @@ -13,4 +13,4 @@ else echo "try to review your installation on your EV3 Brick." echo exit 1 -fi \ No newline at end of file +fi diff --git a/modules/experimental/bluetooth.sh b/modules/experimental/bluetooth.sh index c935589..46f28f8 100644 --- a/modules/experimental/bluetooth.sh +++ b/modules/experimental/bluetooth.sh @@ -7,14 +7,14 @@ echo "##############################" echo "" #2. Install Bluetooth -if [ "$PLATFORM" == "$EV3" ]; +if [ "$PLATFORM" == "ev3" ]; then - echo $EV3 + echo "EV3" #isInstalled libbluetooth-dev #wget http://ftp.us.debian.org/debian/pool/main/b/bluez/libbluetooth-dev_5.23-2+b1_armel.deb #dpkg --force-depends-version -i libbluetooth-dev_5.23-2+b1_armel.deb else - echo $BRICKPI - isInstalled libbluetooth-dev + echo "BrickPi" + isInstalled "$BT_BRICKPI_PKG" #apt-get install libbluetooth-dev -fi \ No newline at end of file +fi diff --git a/modules/java.sh b/modules/java.sh index 5172b2f..663c7be 100644 --- a/modules/java.sh +++ b/modules/java.sh @@ -1,49 +1,84 @@ #!/bin/bash -function installJavaForEV3() { - if [ ! -d /opt/jri-10-build-050 ]; then - wget https://github.com/ev3dev-lang-java/openjdk-ev3/releases/download/v0.5.0/jri10-ev3.tar.gz - tar -zxvf "/home/robot/installer/jri10-ev3.tar.gz" -C /opt - mv /opt/jri-ev3/ /opt/jri-10-build-050 - update-alternatives --install /usr/bin/java java /opt/jri-10-build-050/bin/java 10 - java -version - java -Xshare:dump - else + +function java_install_bundle() { + if [ -d "$JAVA_PATH_NEW" ]; then echo "Sorry, we detected a previous installation in path: /opt/jri-10-build-050" + echo + exit 1 + fi + + if [ ! -f "$JAVA_ZIP" ]; then + echo "Downloading new Java..." + wget "$JAVA_URL" -O "$JAVA_ZIP" + else + echo "Java archive found, using cached." fi + + # extract it, rename it and point the symlink to it + echo "Java package acquired, installing..." + tar -xf "$JAVA_ZIP" -C "$JAVA_OPT" + mv "$JAVA_PATH_ZIP" "$JAVA_PATH_NEW" + update-alternatives --install /usr/bin/java java "$JAVA_EXE" 1 + + JAVA_REAL_EXE="$JAVA_EXE" } -#TODO Upgrade this function with the support of OpenJDK 10 -function installJavaForBrickPi() { - apt-key adv --recv-key --keyserver keyserver.ubuntu.com EEA14886 - echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list - echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list +function java_install_ppa() { + ### + # Add Debian Buster repo to Stretch + + # prevent distro upgrade + cat >/etc/apt/preferences.d/jdk <