#1
|
|||
|
|||
![]()
Hello.
I haven't used JDownloader for a while now, and when I considered setting it up again earlier I was surprised to see an installer for linux. However, I downloaded it, took a look into it, and then my surprise turned into being shocked ^^ So I decided to go for it and write a script including basic sanity checks, avoiding changing a directory inside a bash script ( - you shouldnt - ), the possibility to specify an alternative installation directory.... Just look at it ![]() This script will also create a launcher so JDownloader can be started simply by calling jdown from anywhere (anywhere inside a terminal, or by creating a launcher with jdown as its command) Instructions: Code:
wget -O /tmp/jd-installer.sh **External links are only visible to Support Staff** sh /tmp/jd-installer.sh sh /tmp/jd-installer.sh -d /your/prefered/directory *edit* I just noticed that jdownloader will install itself into ~/jdownloader anyway, so no need to specify a directory. However, I'll change the script so that it will link to the specified directory... By default it will install to ~/jdownloader. If you specify -d this will be stored in the launcher, so feel free to. I don't think I have to mention that, if -d, you should have write permissions to that directory (tho the script will check this too) Please let me know if you run into some undesirable behavior, experience some bugs, wanna thank me cause you like it, or in any other case you think you'd have to contact me ![]() Enjoy everybody PS: I dont have a mac to test, so please let me know if you run into trouble. *edit* here's the code in case you want to take a look at it first, or if it gets removed from ompload. Code:
#!/bin/bash #set -x # ------------------------------------------------------------------- # # Shell program to Install JDownloader. # # written by Norbert Varzariu <loomsen@googlemail.com> # Copyright 2009 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Description: # # # # Usage: # # ./jd-installer.sh [ -h | --help ] [-d dir] # # Options: # # -h, --help Display this help message and exit. # -d dir alternative installation directory # # # Revision History: # # 08/28/2009 File created by new_script ver. 2.1.0 # # ------------------------------------------------------------------- # ------------------------------------------------------------------- # Constants # ------------------------------------------------------------------- PROGNAME=$(basename $0) VERSION="0.0.2" JDINSTALLER=http://update0.jdownloader.org/jdupdate.jar BINDIR=$HOME/bin JAVABIN=$(which java) > /dev/null 2>&1 ## DONT EDIT HERE! installdir= # ------------------------------------------------------------------- # Functions # ------------------------------------------------------------------- function clean_up { rm -f ${TEMP_FILE1} } function error_exit { echo "${PROGNAME}: ${1:-Unknown Error}" >&2 clean_up exit 1 } function graceful_exit { clean_up exit } function signal_exit { # Function to handle termination signals case $1 in INT ) echo "$PROGNAME: Program terminated by user" >&2 ;; TERM ) echo "$PROGNAME: Program terminated" >&2 clean_up exit ;; *) error_exit "$PROGNAME: Terminating on unknown signal" ;; esac } function int_exit { echo "${PROGNAME}: Aborted by user" clean_up exit 1 } function wget_exit { echo "${PROGNAME}: Can't download installer" clean_up exit 1 } function make_temp_files { if [ -d ~/tmp ]; then TEMP_DIR=~/tmp else TEMP_DIR=/tmp fi TEMP_FILE1=$(mktemp -q "${TEMP_DIR}/${PROGNAME}.$$.XXXXXX") if [ "$TEMP_FILE1" = "" ]; then error_exit "cannot create temp file!" fi } function usage { echo "Usage: ${PROGNAME} [-h | --help] [-d dir]" } function helptext { local tab=$(echo -en "\t\t") cat <<- -EOF- ${PROGNAME} ver. ${VERSION} This is a program to Install JDownloader. $(usage) Options: -h, --help Display this help message and exit. -d dir alternative installation directory -EOF- } function ask_yes_no { local yn= while [ "$yn" = "" ]; do echo -en "$1" read yn case $yn in y|Y) yn=0 ;; n|N) yn=1 ;; *) yn= echo "Invalid response - please answer y or n" ;; esac done return $yn } function getit { pushd $installdir echo "Starting JD-installer, downloading to $installdir" wget -q $JDINSTALLER echo "Download finished" popd return } function adjust_path { echo 'PATH=$PATH:$HOME/bin' >> $HOME/.bashrc } # ------------------------------------------------------------------- # Program starts here # ------------------------------------------------------------------- ##### Initialization And Setup ##### # Set file creation mask so that all files are created with 644 permissions. # umask 022 # Trap TERM, HUP, and INT signals and properly exit trap "signal_exit TERM" TERM HUP trap "signal_exit INT" INT # Create temporary file(s) make_temp_files dir_flag=0 ##### Command Line Processing ##### if [ "$1" = "--help" ]; then helptext graceful_exit fi while getopts ":hd:" opt; do case $opt in d ) dir_flag=1 installdir=$OPTARG ;; h ) helptext graceful_exit ;; * ) usage clean_up exit 1 ;; esac done ##### Main Logic ##### # perform some basic checks if [ "`basename $JAVABIN`" != "java" ]; then error_exit "no valid java installation found!" fi if [ ! -x /usr/bin/wget ]; then error_exit "wget not found, no reason to continue" fi ## basic sanity checks done, lets get the installer ## if alternative installation directory is given if [ $dir_flag = 1 ];then ## an alternative directory has been set, perform some basic tests ## test if directory exists if [ -e "${installdir}" ];then # test if it's a regular directory if [ -d "${installdir}" ];then # Is it writable? if [ -w "${installdir}" ]; then # Confirm overwrite if ! ask_yes_no "Output directory exists - Overwrite? [y/n] "; then int_exit fi else error_exit "Output directory is not writable" fi else error_exit "Output directory is not a regular directory" fi else # Try and write it mkdir -p $installdir #|| error_exit "cant write to output dir, make sure you have sufficient permissions" getit || error_exit "Cant access the internet, make sure you're connected" fi else ## installation to default directory installdir=$HOME/jdownloader ## test if directory exists if [ -e "${installdir}" ];then # test if it's a regular directory if [ -d "${installdir}" ];then # Is it writable? if [ -w "${installdir}" ]; then # Confirm overwrite if ! ask_yes_no "Output directory exists - Overwrite? [y/n] "; then int_exit fi else error_exit "Output directory is not writable" fi else error_exit "Output directory is not a regular directory" fi else # Try and write it mkdir -p $installdir getit || error_exit "Cant access the internet, make sure you're connected" fi fi ## Check if $HOME/bin is existent, create it if not [[ ! -d $BINDIR ]] && mkdir -p $BINDIR || : ## Check if PATH includes $BINDIR so we can launch jdown from anywhere if [ "$(echo $PATH | grep $BINDIR)" == "" ];then adjust_path fi function create_binary { cat > $BINDIR/jdown << "FOE" #!/bin/bash # ------------------------------------------------------------------- # # Shell program to launch JDownloader. # # Copyright 2009, docter <docter@localhost.localdomain>. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Description: # # # # Usage: # # jdown [ -h | --help ] [-u] # # Options: # # -h, --help Display this help message and exit. # -u Update # # # Revision History: # # 08/29/2009 File created by new_script ver. 2.1.0 # # ------------------------------------------------------------------- # ------------------------------------------------------------------- # Constants # ------------------------------------------------------------------- PROGNAME=$(basename $0) VERSION="0.0.1" # ------------------------------------------------------------------- # Functions # ------------------------------------------------------------------- function error_exit { # ----------------------------------------------------------------------- # Function for exit due to fatal program error # Accepts 1 argument: # string containing descriptive error message # ----------------------------------------------------------------------- echo "${PROGNAME}: Unknown Error" >&2 # clean_up exit 1 } function graceful_exit { # ----------------------------------------------------------------------- # Function called for a graceful exit # No arguments # ----------------------------------------------------------------------- # clean_up exit } function signal_exit { # ----------------------------------------------------------------------- # Function to handle termination signals # Accepts 1 argument: # signal_spec # ----------------------------------------------------------------------- exit 1 } function usage { # ----------------------------------------------------------------------- # Function to display usage message (does not exit) # No arguments # ----------------------------------------------------------------------- echo "Usage: ${PROGNAME} [-h | --help] [-u]" } function helptext { # ----------------------------------------------------------------------- # Function to display help message for program # No arguments # ----------------------------------------------------------------------- local tab=$(echo -en "\t\t") cat <<- -FOEEOF- jdown ver. 0.0.1 This is a program to launch JDownloader. Usage: ${PROGNAME} [-h | --help] [-d dir] Options: -h, --help Display this help message and exit. -u Update -FOEEOF- } function getup { if [ ! -d $HOME/jdownloader/update/ ]; then java -Xmx512m -jar $HOME/jdownloader/jdupdate.jar else java -Xmx512m -jar $HOME/jdownloader/update/jdupdate.jar fi } function launch { java -Xmx512m -jar $HOME/jdownloader/update/JDownloader.jar } # ------------------------------------------------------------------- # Program starts here # ------------------------------------------------------------------- ##### Initialization And Setup ##### # Set file creation mask so that all files are created with 600 permissions. umask 066 ##### Command Line Processing ##### if [ "$1" = "--help" ]; then helptext graceful_exit fi while getopts ":hu" opt; do case $opt in u ) getup graceful_exit ;; h ) helptext graceful_exit ;; * ) usage #clean_up exit 1 esac done ##### Main Logic ##### launch graceful_exit FOE chmod +x $BINDIR/jdown } ## Create a launcher and install it to $HOME/bin/jdown create_binary || error_exit "could not create binary in $BINDIR! This is critical (meaning you don't have write permissions on that folder." echo "Done downloading installer!" echo "Now type \"jdown -u\" to launch" graceful_exit ### # Please add your changes here and bump the version above #*CHANGELOG* # #* Sat Aug 29 2009 Norbert Varzariu <loomsen@googlemail.com> - 0.0.2 #- cleanup # #* Sat Aug 29 2009 Norbert Varzariu <loomsen@googlemail.com> - 0.0.1 #- initial version Last edited by Jiaz; 29.08.2009 at 14:37. |
#2
|
||||
|
||||
![]()
and then my surprise turned into being shocked ^^
just for me: why? btw. the changedir is neccessary, because jd will install itself into the current workingdir
__________________
JD-Dev & Server-Admin |
#3
|
|||
|
|||
![]()
There are more appropriate built in functions for these purposes.pushd and popd namely.
To refer to the jar's it's better to make the full PATH be generated by the installer, and so on... Or would you really want to state the current script to be good in any manner? |
#4
|
||||
|
||||
![]()
its written by me and works fine so far for many many users...it was my first bash script...so i think..yes..it does what its meant for ...install and start jd
__________________
JD-Dev & Server-Admin |
#5
|
|||
|
|||
![]()
I just use the java version, no install reqd.
|
Thread Tools | |
Display Modes | |
|
|