move_ps_files.sh (1959B)
1 #!/bin/bash 2 3 # USAGE ======================================================================= 4 # 5 # a number of shared libraries are kept in /usr/local/lib/. They are 6 # incompatible with the python pocketsphinx package. This script moves them 7 # between their installed location and the installation directory for the 8 # rest of the CMU Sphinx dependencies. 9 # 10 # bash move_ps_files.sh -into_lib 11 # bash move_ps_files.sh -out_of_lib 12 # 13 # This script is run at the beginning and at the end of the VMC program. 14 # 15 # VARIABLES =================================================================== 16 17 option="$1" 18 lib_backup_dir="/home/$USER/CMU_Sphinx/shared_library_backup" 19 20 # FUNCTIONS =================================================================== 21 22 move_files_out_of_lib() { 23 24 25 sudo mv /usr/local/lib/libpocketsphinx* $lib_backup_dir 26 sudo mv /usr/local/lib/libsphinx* $lib_backup_dir 27 sudo mv /usr/local/lib/sphinxtrain $lib_backup_dir 28 29 } 30 31 copy_files_into_lib() { 32 33 sudo cp $lib_backup_dir/libpocketsphinx* /usr/local/lib 34 sudo cp $lib_backup_dir/libsphinx* /usr/local/lib 35 sudo cp -r "$lib_backup_dir/sphinxtrain" /usr/local/lib 36 37 } 38 39 delete_files_from_lib() { 40 41 sudo rm -f /usr/local/lib/libpocketsphinx* 42 sudo rm -f /usr/local/lib/libsphinx* 43 sudo rm -fr /usr/local/lib/sphinxtrain 44 45 } 46 47 clean_lib_directory() { 48 49 if [ -d "$lib_backup_dir" ] 50 then 51 delete_files_from_lib 52 else 53 mkdir -p "$lib_backup_dir" 54 move_files_out_of_lib 55 fi 56 57 58 } 59 60 ensure_files_are_present() { 61 62 if [ ! -d "$lib_backup_dir" ] # if no backup made, assume files are present 63 then 64 : 65 else 66 copy_files_into_lib 67 fi 68 69 } 70 71 main() { 72 73 if [ $option == "-into_lib" ]; then ensure_files_are_present; 74 elif [ $option == "-out_of_lib" ]; then clean_lib_directory; 75 else echo "bad options given" 76 fi 77 78 } 79 80 # COMMANDS ==================================================================== 81 82 main