]> git.sven.stormbind.net Git - sven/java-package.git/blobdiff - lib/common.sh
Add Java 10 Server JRE support now that it's released.
[sven/java-package.git] / lib / common.sh
index 60c28522fe669a957361fa0ca2fae948732de99a..ab07236aa54b5c82933d2c350a1506a14bb383ef 100644 (file)
@@ -1,38 +1,38 @@
 # read_yn <prompt>
 # read_yn <prompt>
-function read_yn() {
+read_yn() {
     local prompt="$1"
     while true; do
     local prompt="$1"
     while true; do
-       read -e -n 1 -p "$prompt" reply
-       case "$reply" in
-           "" | "y" | "Y")
-               return 0
-               ;;
-           "N" | "n")
-               return 1
-               ;;
-       esac
+    read -e -n 1 -p "$prompt" reply
+    case "$reply" in
+        "" | "y" | "Y")
+        return 0
+        ;;
+        "N" | "n")
+        return 1
+        ;;
+    esac
     done
 }
 
 
 # diskusage <path>: prints size in MB
     done
 }
 
 
 # diskusage <path>: prints size in MB
-function diskusage() {
+diskusage() {
     local path="$1"
     local path="$1"
-    read size dummy < <( du -sm "$path" )
+    read size dummy < <( du -sm --apparent-size "$path" )
     echo "$size"
 }
 
 
 # diskfree <minimum size in MB>
     echo "$size"
 }
 
 
 # diskfree <minimum size in MB>
-function diskfree() {
+diskfree() {
     local size="$1"
     echo -n "Checking free diskspace:"
     local size="$1"
     echo -n "Checking free diskspace:"
-       (( free = `stat -f -c '%a / 2048 * ( %s / 512 )' $tmp ` ))
+    (( free = `stat -f -c '%a / 2048 * ( %s / 512 )' $tmp ` ))
 
     if [ "$free" -ge "$size" ]; then
 
     if [ "$free" -ge "$size" ]; then
-       echo " done."
+    echo " done."
     else
     else
-       cat >&2 << EOF
+    cat >&2 << EOF
 
 
 WARNING: Possibly not enough free disk space in "$tmp".
 
 
 WARNING: Possibly not enough free disk space in "$tmp".
@@ -45,13 +45,13 @@ Press Ctrl+C to interrupt, or return to try to continue anyway.
 TMPDIR.
 
 EOF
 TMPDIR.
 
 EOF
-       read
+    read
     fi
 }
 
 
 # extract_bin <file> <expected_min_size> <dest>
     fi
 }
 
 
 # extract_bin <file> <expected_min_size> <dest>
-function extract_bin() {
+extract_bin() {
     local file="$1"
     local expected_min_size="$2"
     local dest="$3"
     local file="$1"
     local expected_min_size="$2"
     local dest="$3"
@@ -72,20 +72,20 @@ EOF
 
     local extract_cmd
     case "$archive_path" in
 
     local extract_cmd
     case "$archive_path" in
-       *.tar)
-           extract_cmd="tar xf";;
-       *.tar.bz2)
-           extract_cmd="tar --bzip2 -xf";;
-       *.tgz|*.tar.gz)
-           extract_cmd="tar xfz";;
-       *.zip)
-           extract_cmd="unzip -q";;
-       *)
-           extract_cmd=sh
+    *.tar)
+        extract_cmd="tar xf";;
+    *.tar.bz2)
+        extract_cmd="tar --bzip2 -xf";;
+    *.tgz|*.tar.gz)
+        extract_cmd="tar xfz";;
+    *.zip)
+        extract_cmd="unzip -q";;
+    *)
+        extract_cmd=sh
     esac
 
     if ! $extract_cmd "$archive_path"; then
     esac
 
     if ! $extract_cmd "$archive_path"; then
-       cat << EOF
+    cat << EOF
 
 WARNING: The package installation script exited with an error
 value. Usually, this means, that the installation failed for some
 
 WARNING: The package installation script exited with an error
 value. Usually, this means, that the installation failed for some
@@ -96,13 +96,13 @@ Please check if there are any error messages. Press [Return] to
 continue or Ctrl-C to abort.
 
 EOF
 continue or Ctrl-C to abort.
 
 EOF
-       read
+    read
     fi
     echo
     echo -n "Testing extracted archive..."
     local size="$( diskusage "$extract_dir" )"
     if [ "$size" -lt "$expected_min_size" ]; then
     fi
     echo
     echo -n "Testing extracted archive..."
     local size="$( diskusage "$extract_dir" )"
     if [ "$size" -lt "$expected_min_size" ]; then
-       cat << EOF
+    cat << EOF
 
 Invalid size ($size MB) of extracted archive. Probably you have not
 enough free disc space in the temporary directory. Note: You can
 
 Invalid size ($size MB) of extracted archive. Probably you have not
 enough free disc space in the temporary directory. Note: You can
@@ -110,85 +110,111 @@ specify an alternate directory by setting the environment variable
 TMPDIR.
 
 EOF
 TMPDIR.
 
 EOF
-       error_exit
+    error_exit
     else
     else
-       cd "$extract_dir"
-       files=(*)
-       if [ "${#files[*]}" -ne 1 ]; then
-           cat << EOF
+    cd "$extract_dir"
+    files=(*)
+    if [ "${#files[*]}" -ne 1 ]; then
+        cat << EOF
 
 Expected one file, but found the following ${#files[*]} files:
     ${files[*]}
 
 EOF
 
 Expected one file, but found the following ${#files[*]} files:
     ${files[*]}
 
 EOF
-           error_exit
-       fi
-       mv "$files" "$dest"
-       echo -e " okay.\n"
+        error_exit
+    fi
+    mv "$files" "$dest"
+    echo -e " okay.\n"
     fi
 }
 
     fi
 }
 
+extract_jce() {
+  local zip_file="$1"
+  local dest_dir="$2"
+
+  echo "Installing unlimited strength cryptography files using $zip_file"
+  for f in {US_export,local}_policy.jar; do
+    unzip -o -j -d "$dest_dir" "$zip_file" "*/$f"
+  done
+}
 
 
-function read_maintainer_info() {
+read_maintainer_info() {
     if [ -z "$maintainer_name" ]; then
     if [ -z "$maintainer_name" ]; then
-       if [ -n "$DEBFULLNAME" ]; then
-               maintainer_name="$DEBFULLNAME"
-       elif [ -n "$DEBNAME" ]; then
-               maintainer_name="$DEBNAME"
-       else
-               default_name="$(getent passwd $(id -run) | cut -d: -f5| cut -d, -f1)"
-       
-       cat << EOF
+    if [ -n "$DEBFULLNAME" ]; then
+        maintainer_name="$DEBFULLNAME"
+    elif [ -n "$DEBNAME" ]; then
+        maintainer_name="$DEBNAME"
+    else
+        default_name="$(getent passwd $(id -run) | cut -d: -f5| cut -d, -f1)"
+
+    cat << EOF
 
 Please enter your full name. This value will be used in the maintainer
 field of the created package.
 
 EOF
 
 
 Please enter your full name. This value will be used in the maintainer
 field of the created package.
 
 EOF
 
-       # gecos can be null
-       while [ -z "$maintainer_name" ]; do
-               read -e -p "Full name [$default_name]:" maintainer_name
-               if [ -z "$maintainer_name" ] && [ -n "$default_name" ]; then
-                       maintainer_name="$default_name"
-               fi
-       done
-       fi
+    # gecos can be null
+    while [ -z "$maintainer_name" ]; do
+        read -e -p "Full name [$default_name]:" maintainer_name
+        if [ -z "$maintainer_name" ] && [ -n "$default_name" ]; then
+            maintainer_name="$default_name"
+        fi
+    done
+    fi
     fi
     fi
+
     if [ -z "$maintainer_email" ]; then
     if [ -z "$maintainer_email" ]; then
-       local default_email=
-       if [ -n "$DEBEMAIL" ]; then
-           maintainer_email="$DEBEMAIL"
-       else 
-       if [ -r "/etc/mailname" ]; then
-           default_email="$( id -run )@$( cat /etc/mailname )"
-       else
-           default_email="$( id -run )@$( hostname --fqdn )"
-       fi
-       cat << EOF
+    local default_email=
+    if [ -n "$DEBEMAIL" ]; then
+        maintainer_email="$DEBEMAIL"
+    else
+    if [ -r "/etc/mailname" ]; then
+        default_email="$( id -run )@$( cat /etc/mailname )"
+    else
+        default_email="$( id -run )@$( hostname --fqdn )"
+    fi
+    cat << EOF
 
 Please enter a valid email address or press return to accept the
 default value. This address will be used in the maintainer field of
 the created package.
 
 EOF
 
 Please enter a valid email address or press return to accept the
 default value. This address will be used in the maintainer field of
 the created package.
 
 EOF
-       read -e -p "Email [$default_email]: " maintainer_email
-       if [ -z "$maintainer_email" ]; then
-           maintainer_email="$default_email"
-       fi
-       fi
+    read -e -p "Email [$default_email]: " maintainer_email
+    if [ -z "$maintainer_email" ]; then
+        maintainer_email="$default_email"
+    fi
+    fi
     fi
 }
 
 # provide the architecture for evaluation by plugins
     fi
 }
 
 # provide the architecture for evaluation by plugins
-function get_architecture() {
+get_architecture() {
     echo
 
     export DEB_BUILD_ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
 
     export DEB_BUILD_GNU_TYPE=$(dpkg-architecture -qDEB_BUILD_GNU_TYPE)
     echo
 
     export DEB_BUILD_ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
 
     export DEB_BUILD_GNU_TYPE=$(dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-    
+
     echo "Detected Debian build architecture: ${DEB_BUILD_ARCH:-N/A}"
     echo "Detected Debian build architecture: ${DEB_BUILD_ARCH:-N/A}"
-    
+
     echo "Detected Debian GNU type: ${DEB_BUILD_GNU_TYPE:-N/A}"
 }
     echo "Detected Debian GNU type: ${DEB_BUILD_GNU_TYPE:-N/A}"
 }
+
+# get browser plugin directories
+get_browser_plugin_dirs() {
+    if dpkg-vendor --derives-from Ubuntu; then
+        export browser_plugin_dirs="xulrunner-addons firefox iceape iceweasel mozilla midbrowser xulrunner"
+    else
+        export browser_plugin_dirs=mozilla
+    fi
+}
+
+get_distribution() {
+    if [ -n "$distribution" ]; then
+      target_distribution="$distribution"
+    else
+      target_distribution="unstable"
+    fi
+}