#!/bin/bash # This script aims to make everything a little easier by: # --> Cloning the GIT. # --> Downloading, and extracting, dictionary files. # --> Copying the zdict.zks from the old 0.731 install. # --> Option to overwrite icons with ones suited for Dark Theme users. <-- You may create your own set of icons, as long as type and names matches with those in Resources. # --> Compiling using 'qmake'. (Some distros may need to change this.) # --> Wrapping up using 'make'. # --> Performing initial run including database generation. # --> Giving user the command to run zkanji at any time. # # How to run this script? # --> Make executable: chmod +x PATH/FILE # --> Run it: ./PATH/FILE # --> Optional: bash -c "PATH/FILE" # # Requirements, up to date: (May require additional optional dependencies!) # --> bash # --> git # --> make # --> qmake # --> rsync # --> gzip # ...use 'pkgfile' to check if you got what you need - 'man pkgfile' for usage info. # ...use your package manager to install what you are missing. (E.g. pacman, apt-get, yum... etc.) # # Other requirements: # --> Access to an OLD INSTALL (v 0.731) or the 'zdict.zks" from it. # --> Internet connection. # --> User permissions at working directory. ## WARNING: Do NOT end directory paths with "/", this may cause errors as I'm too lazy to incorprate handling for this. echo " [WARNING] Do NOT end directory paths with \"/\", this may cause errors as I'm too lazy to incorprate handling for this." printf " [INFO] You may set some presets within this file at:\n%18s %3s-%3s \"%s\"\n%10s%s\n" "Line" "37" "45" "# Defaults for user comfort when updating:" "" "NOTE: Be sure to READ INSTRUCTIONS!!" # Defaults for user comfort when updating: ## Path to target install directory: dInstallDir="$HOME/zKanji" ## Path to DarkTheme Resources, e.g. icons: (NOTE: May NOT be located in target install directory!) dDarkTheme="$HOME/zKanji-extras/Resources-for-DarkTheme" ## Path to existing zdict.zks: (NOTE: May NOT be located in target install directory!) dzdict="$HOME/zKanji-extras/zdict.zks" ## Path to existing dictionary files: (NOTE: May NOT be located in target install directory!) dDict="$HOME/zKanji-extras/dict" # Backing up CurrentWorkingDirectory. oCD="$PWD" # Quering if user really wants to run script. printf "%s\n\n" " [INFO] This script will automatically perform most of the process for installing alpha of zKanji." read -n1 -p "Do you wish to continue? (Y/N) " tmp case ${tmp,,} in y) echo "" ;; *) printf "\nQuitting" && exit 1 ;; esac Quering where to install. while : ; do read -p "Enter path to install zkanji at: (Leave EMPTY to use \"$dInstallDir\") " WorkDir [[ ${#WorkDir} -le 1 || -d "$WorkDir" ]] && WorkDir="$dInstallDir" ; [[ ! -d "$WorkDir" ]] && mkdir "$WorkDir" && break echo " [ERROR] Directory exists. Please rename or remove it before trying again!" done printf "Installing at: %s\n" "$WorkDir" ; cd "$WorkDir" # Quering user if to clone from GIT or use existing download. while : ; do read -n1 -p "Clone from GIT or use existing SOURCE? (G/S) " tmp case ${tmp,,} in g) echo "" ; git clone https://github.com/z1dev/zkanji.git && break ;; s) echo "" ; read -p "Enter path to existing SOURCE DIR: " Source ; [[ -d "$Source" ]] && cp -fR "$Source" "$WorkDir/zkanji-source" && break ;; *) continue ;; esac done # Getting directory name. tmp=($(ls -d * | grep -i zkanji)) ; [[ ${#tmp[@]} -ge 1 ]] && wDir=${tmp[0]} ; [[ ! -d "$WorkDir/$wDir" ]] && echo "Failed to find folder: $WorkDir/zkanji*" # Quering for DarkTheme. read -n1 -p "Do you wish to use Dark Themed icons? (Y/N) " tmp case ${tmp,,} in y) echo "" ; while : ; do read -p "Enter PATH to icons for DarkTheme: (Leave EMPTY to use \"$dDarkTheme\") " DarkThemePath ; [[ ${#DarkThemePath} -le 1 && -d "$dDarkTheme" ]] && { cp -fR "$dDarkTheme/." "$WorkDir/$wDir/Resources/" ; break ; } || { [[ -d "$DarkThemePath" ]] && { cp -fR "$DarkThemePath/." "$WorkDir/$wDir/Resources/" ; break ; } || echo "Path is not a directory." ; } ; done ;; *) echo "" ;; esac # Copying files from 'dataimports'. cp -fR "$WorkDir/$wDir/dataimports/." "$WorkDir/dict/" # Downloading, and extracting, dictionary files. [[ ! -d "$WorkDir/dict" ]] && mkdir "dict" cd dict ; List=("JMdict" "kanjidic" "radkfile.gz" "examples.utf") ; c=1 ; l=${#List[@]} ; find=".gz" while : ; do read -n1 -p "Download latest dictionary files from server or use Local files? (D/L) " tmp echo "" case ${tmp,,} in d) for f in "${List[@]}" ; do printf "\r(%s/%s) Getting file '%s' from server...%s" "$c" "$l" "$f" " " ; rsync ftp.edrdg.org::nihongo/$f $f ; [[ "$f" =~ .*"$find" ]] && { printf "\r(%s/%s) Extracting content of: '%s'" "$c" "$l" "$f" " " ; gzip -fd "$f" ; } ; (( c++ )) ; done ; echo "" && break ;; l) tUseLocal=1 && break ;; *) continue ;; esac done if [[ $tUseLocal -eq 1 ]] then while : ; do read -p "Enter path to dictionary files: (Leave EMPTY to use \"$dDict\")" tmp echo "" [[ ${#tmp} -eq 0 && -d "$dDict" ]] && tmp="$dDict" [[ -d "$tmp" ]] && { printf "\rCopying files..." ; cp -fR "$tmp/." "./" ; printf "Done\n\rExtracting files..." ; for f in * ; do [[ "$f" =~ .*"$find" ]] && gzip -d "$f" ; done ; echo "" ; break ; } || { echo " [ERROR] Path is not a directory." ; continue ; } done fi # Quering for the 'zdict.zks', or PATH to OLD INSTALL which has it. while : ; do read -p "Enter INSTALL PATH to the OLD zKanji v. 0.731, OR directly to 'zdict.zks': (Leave EMPTY to use \"$dzdict\") " OldExec ; [[ ${#OldExec} -le 1 && -f "$dzdict" ]] && { cp -f "$dzdict" "zdict.zks" && break ; } || { [[ -f "$OldExec" ]] && cp -f "$OldExec" "zdict.zks" || { [[ -f "$OldExec/data/zdict.zks" ]] && cp -f "$OldExec/data/zdict.zks" "zdict.zks" || [[ -f "$OldExec/zdict.zks" ]] && cp -f "$OldExec/zdict.zks" "zdict.zks" ; } && break ; } ; done cd .. # Creating build directory. wDirBuild="$wDir""-build" [[ ! -d "$WorkDir/$wDirBuild" ]] && cp -fR "$WorkDir/$wDir" "$WorkDir/$wDirBuild" ; cd "$WorkDir/$wDirBuild" # Pausing inbefore build. echo "All set to start building." echo "If you wish to edit source, resources or make personal additions before building - please do it BEFORE building." while : ; do read -n1 -p "Do you wish to compile in terminal? (Y/N) " tmp case "${tmp,,}" in y) tInTerm=1 && break && printf "\n" ;; n) tInTerm=0 && break && printf "\n" ;; *) continue ;; esac done if [[ $tInTerm -eq 1 ]] then read -n1 -p "Press any key to start building." ; # Building and wrapping up. echo "Compiling application using 'qmake', please be patient!" ; qmake "zkanji.pro" -spec linux-g++ -Wall CONFIG+=debug CONFIG+=qml_debug ; [[ ! $? -eq 0 ]] && { echo " [ERROR] Error during build using 'qmake'! Exiting!" ; exit $? ; } echo "Wrapping up using 'make', please be patient!" ; make ; [[ ! $? -eq 0 ]] && { echo " [ERROR] Error during build using 'make'! Exiting!" ; exit $? ; } echo "Making binary executable." ; chmod +x zkanji ; cd "$WorkDir/$wDirBuild" else read -n1 -p "Press any key when you're done building with your favorite compiler." while : ; do read -p "Enter path to finished build. " tPathToBuild ; [[ -d "$tPathToBuild" ]] && { cd "$tPathToBuild" ; break ; } ; done ; PWD="$tPathToBuild" echo "Making binary executable." ; chmod +x zkanji fi # Creating directory for dictionary data. echo "Creating directory: data" ; [[ ! -d "$PWD/data" ]] && mkdir "$PWD/data" # Informing user how to run zkanji in the future, and creating a starter. printf "#!/bin/bash\n%s" "bash -c \"$PWD/zkanji\"" > "$PWD/../zKanji.sh" ; chmod +x "$PWD/../zKanji.sh" printf "You can start the application using command:\n %s\n\n This has been saved as %s\n" "bash -c \"$PWD/zkanji\"" "'$PWD/../zKanji.sh'" printf "If initializing exits with ERROR, run: bash -c \"%s\"" "$PWD/zkanji -ie \\\"$PWD/../dict\\\"" # Informing user in regards to first run. For some reason, initial call needs to be done TWICE or won't start. Error in zKanji? No debug data available atm. printf "\nFirst run for initialization of dictionary files.\nWhen prompted if you like to use 'Portable' or 'Normal' mode, you should select 'Portable'." read -n1 -p "Press any key to continue." ; while : ; do bash -c "$PWD/zkanji -ie \"$PWD/../dict\"" read -n1 -p "Did you finish setting it up? (Y/N) " tmp case ${tmp,,} in y) echo "" ; break ;; *) continue ;; esac done [[ ! $? -eq 0 ]] && echo " [ERROR] Error during initial execution! Exiting!" || echo "Setup finished successfully!" # Restoring PWD and exits. cd "$oCD" ; exit $?