Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 20.21 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##############################################################################
  4. ##
  5. ##  ScanGear MP for Linux
  6. ##  Copyright CANON INC. 2007-2013
  7. ##  All Rights Reserved.
  8. ##
  9. ##  This program is free software; you can redistribute it and/or modify
  10. ##  it under the terms of the GNU General Public License as published by
  11. ##  the Free Software Foundation; version 2 of the License.
  12. ##
  13. ##  This program is distributed in the hope that it will be useful,
  14. ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ##  GNU General Public License for more details.
  17. ##
  18. ##  You should have received a copy of the GNU General Public License
  19. ##  along with this program; if not, write to the Free Software
  20. ##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
  21. ##
  22. ##############################################################################
  23.  
  24. C_version="2.20-1"
  25. C_copyright_end="2013"
  26. C_default_system="deb"
  27.  
  28. L_INST_COM_01_01="Command executed = %s\n"
  29.  
  30. L_INST_COM_01_02="An error occurred. The package management system cannot be identified.\n"
  31. L_INST_COM_01_03="An error occurred. A necessary package could not be found in the proper location.\n"
  32. L_INST_COM_01_04="Installation has been completed.\n"
  33. L_INST_COM_01_05="An error occurred. Your environment cannot be identified as 32-bit or 64-bit.\nTry to install again by using the following command.\n"
  34. L_INST_COM_01_06="An error occurred. The specified environment differs from your environment.\nTry to install again by using the following command.\n"
  35.  
  36. L_INST_COM_02_01="Usage: %s\n"
  37.  
  38. L_INST_COM_02_02="Uninstallation has been completed.\n"
  39.  
  40. L_INST_COM_03_01="[Package]\n"
  41.  
  42.  
  43. L_INST_SCN_00_01="ScanGear MP"
  44. L_INST_SCN_00_02="Version %s"
  45. L_INST_SCN_00_03="Copyright CANON INC. %s-%s"
  46. L_INST_SCN_00_04="All Rights Reserved."
  47.  
  48.  
  49. C_main_module="scangearmp"
  50. C_copyright_start="2007"
  51.  
  52. #################################################################
  53. #### C_function name define
  54. #################################################################
  55. C_function01="S_FUNC_show_inst_complete"
  56. C_function02="S_FUNC_no_action"
  57. C_function03="S_FUNC_show_copyright"
  58.  
  59. #################################################################
  60. #### Show "install complete" message  $1:L_INST_COM_01_04
  61. #### C_function01
  62. #################################################################
  63. S_FUNC_show_inst_complete(){
  64.     printf "$1"
  65. }
  66.  
  67. #################################################################
  68. #### No action, case scanner
  69. #### C_function02
  70. #################################################################
  71. S_FUNC_no_action(){
  72.     echo -n ""
  73. }
  74.  
  75. #################################################################
  76. #### Show the copyright  $1:version $2:copyright_end
  77. #### C_function03
  78. #################################################################
  79. S_FUNC_show_copyright()
  80. {
  81. #   s_copyright1="ScanGear MP Ver.$1 for Linux"
  82. #   s_copyright2="Copyright CANON INC. 2007-2011"
  83. #   s_copyright3="All Rights Reserved."
  84.  
  85. #   echo $s_copyright1; echo $s_copyright2; echo $s_copyright3
  86.  
  87.     printf "$L_INST_SCN_00_01\n"
  88.     printf "$L_INST_SCN_00_02\n" $1
  89.     printf "$L_INST_SCN_00_03\n" $C_copyright_start $C_copyright_end
  90.     printf "$L_INST_SCN_00_04\n"
  91. }
  92.  
  93. C_ERR_CODE="128"
  94. C_big="50"
  95. C_equal="40"
  96. C_small="30"
  97.  
  98. C_common="common"
  99. C_system=""
  100. C_arch=""
  101. C_arch32=""
  102. C_arch64=""
  103.  
  104. C_err="no_error"
  105. C_err_unknown="err_unknown"
  106. C_err_mismatch="err_mismatch"
  107. C_err_usage="err_usage"
  108.  
  109. C_install_script_fname="install.sh"
  110. C_config_path_rpm="/usr/local/bin"
  111. C_config_path_deb="/usr/bin"
  112.  
  113. C_copyrightb="=================================================="
  114.  
  115. C_arg_inst="[ --bit32 | --bit64 ]"
  116. C_arg_pkg="[ --uninstall | --version ]"
  117.  
  118. C_FUNC_show_and_exec()
  119. {
  120.     printf "$L_INST_COM_01_01" "$1"
  121.     $1
  122. }
  123.  
  124. C_FUNC_version_comp()
  125. {
  126.     local c_tmpstr=""
  127.     local c_ver1=""
  128.     local c_ver2=""
  129.     local c_rela1=""
  130.     local c_reln1=""
  131.     local c_rela2=""
  132.     local c_reln2=""
  133.    
  134.     C_FUNC_makelist()
  135.     {
  136.         echo $1
  137.         echo $2
  138.     }
  139.  
  140.     ## version compare ##
  141.     # ex. 3.10->310, 1.30->130 #
  142.     c_tmpstr=`echo ${1%%-*}`
  143.     c_ver1=`echo ${c_tmpstr%%.*}``echo ${c_tmpstr##*.}`
  144.     c_tmpstr=`echo ${2%%-*}`
  145.     c_ver2=`echo ${c_tmpstr%%.*}``echo ${c_tmpstr##*.}`
  146.  
  147.     # ex. 310 > 300  #
  148.     if [ "$c_ver1" -gt "$c_ver2" ]; then
  149.         return $C_big
  150.     elif [ "$c_ver1" -lt "$c_ver2" ]; then
  151.         return $C_small
  152.     fi
  153.    
  154.     ## release compare ##
  155.     # ex. a13->[a][13], 2->[][2] #
  156.     c_tmpstr=`echo ${1##*-}`
  157.     c_rela1=`echo ${c_tmpstr%%[0-9]*}`
  158.     c_reln1=`echo ${c_tmpstr##*[a-z]}`
  159.     c_tmpstr=`echo ${2##*-}`
  160.     c_rela2=`echo ${c_tmpstr%%[0-9]*}`
  161.     c_reln2=`echo ${c_tmpstr##*[a-z]}`
  162.  
  163.     # ex. [a][13] < [][2] #
  164.     if [ -z "$c_rela1" ] && [ -n "$c_rela2" ]; then
  165.         return $C_big
  166.     elif [ -n "$c_rela1" ] && [ -z "$c_rela2" ]; then
  167.         return $C_small
  168.     fi
  169.    
  170.     # ex. [a][2] < [b][1] #
  171.     if [ -n "$c_rela1" ] && [ "$c_rela1" != "$c_rela2" ]; then
  172.         list=`C_FUNC_makelist $c_rela1 $c_rela2 | sort`
  173.         for c_tmpstr in $list; do
  174.             if [ "$c_tmpstr" = "$c_rela1" ]; then
  175.                 return $C_small
  176.             else
  177.                 return $C_big
  178.             fi
  179.         done
  180.     fi
  181.    
  182.     # ex. [a][2] > [a][1], [b][9] < [b][10] #
  183.     if [ "$c_reln1" -gt "$c_reln2" ]; then
  184.         return $C_big
  185.     elif [ "$c_reln1" -lt "$c_reln2" ];then
  186.         return $C_small
  187.     else
  188.         return $C_equal
  189.     fi
  190. }
  191.  
  192. C_FUNC_get_system()
  193. {
  194.     local c_system_rpm=""
  195.     local c_system_deb=""
  196.  
  197.     ## Judge is the distribution supporting rpm? ##
  198.     rpm --version 1> /dev/null 2>&1
  199.     c_system_rpm=$?
  200.  
  201.     ## Judge is the distribution supporting dpkg(debian)? ##
  202.     dpkg --version 1> /dev/null 2>&1
  203.     c_system_deb=$?
  204.  
  205.     ## rpm error and deb error is error ##
  206.     if [ $c_system_rpm != 0 -a $c_system_deb != 0 ]; then
  207.         return $C_ERR_CODE
  208.     elif [ $c_system_rpm = 0 -a $c_system_deb = 0 ]; then
  209.         C_system=$C_default_system
  210.     else
  211.         if test $c_system_rpm -eq 0; then
  212.             C_system="rpm"
  213.         else
  214.             C_system="deb"
  215.         fi
  216.     fi
  217.  
  218.     if [ $C_system = "rpm" ]; then
  219.         C_arch32="i386"
  220.         C_arch64="x86_64"
  221.     else
  222.         C_arch32="i386"
  223.         C_arch64="amd64"
  224.     fi
  225.    
  226.     return 0
  227. }
  228.  
  229. C_FUNC_get_bitconf()
  230. {
  231.     local c_bit_conf=""
  232.     local c_sudo_command=""
  233.     local c_arg1=$1
  234.  
  235.     if [ $C_system = "deb" ]; then
  236.         c_sudo_command="sudo "
  237.     fi
  238.  
  239.     getconf LONG_BIT 1> /dev/null 2>&1
  240.     if [ $? -eq 0 ]; then
  241.         c_bit_conf=`getconf LONG_BIT`
  242.     else
  243.         c_bit_conf=""
  244.     fi
  245.  
  246.     if [ -z $C_arch ]; then
  247.         # No argment and getconf=32|64 -> continue #
  248.         if [ -z $c_bit_conf ]; then
  249.             if [ -z $c_arg1 ]; then
  250.                 C_err=$C_err_unknown
  251.             elif [ $c_arg1 = "version" ]; then
  252.                 C_arch="*"
  253.             fi
  254.         elif [ $c_bit_conf = "32" ]; then
  255.             C_arch=$C_arch32
  256.         elif [ $c_bit_conf = "64" ]; then
  257.             C_arch=$C_arch64
  258.         else
  259.             C_err=$C_err_unknown
  260.         fi
  261.     else
  262.         if [ $C_arch = "32" ]; then
  263.             # --bit32 and getconf=error -> continue #
  264.             if [ -z $c_bit_conf ]; then
  265.                 C_arch=$C_arch32
  266.             elif [ $c_bit_conf = "32" ]; then
  267.                 C_arch=$C_arch32
  268.             else
  269.                 C_err=$C_err_mismatch
  270.             fi
  271.         elif [ $C_arch = "64" ]; then
  272.             # --bit64 and getconf=error -> continue #
  273.             if [ -z $c_bit_conf ]; then
  274.                 C_arch=$C_arch64
  275.             elif [ $c_bit_conf = "64" ]; then
  276.                 C_arch=$C_arch64
  277.             else
  278.                 C_err=$C_err_mismatch
  279.             fi
  280.         fi
  281.     fi
  282.  
  283.     if [ $C_err = $C_err_mismatch ]; then
  284.         printf "$L_INST_COM_01_06"
  285.         printf "\n  ${c_sudo_command}${0}\n\n"
  286.         return $C_ERR_CODE
  287.     elif [ $C_err = $C_err_unknown ]; then
  288.         printf "$L_INST_COM_01_05"
  289.         printf "\n  ${c_sudo_command}${0} ${C_arg_inst}\n\n"
  290.         return $C_ERR_CODE
  291.     fi 
  292.    
  293.     return 0
  294. }
  295.  
  296. C_FUNC_localize()
  297. {
  298.     local lc_file_dir=$1
  299.  
  300.     ## Get current LANG information ##
  301.     local current_lang=`echo $LANG | tr '[:upper:]' '[:lower:]'`
  302.  
  303.     ## Get printer or scanner ##
  304.     local driver=""
  305.     if [ $C_main_module = "cnijfilter" ]; then
  306.         driver="printer"
  307.     else
  308.         driver="scanner"
  309.     fi
  310.  
  311.     ## Get localize file name ##
  312.     local lc_file="nolocalize"
  313.     case "${current_lang##*.}" in
  314.         utf8 | utf-8)
  315.             case "${current_lang%%.*}" in
  316.                 ja_jp)
  317.                     lc_file="${driver}_ja_utf8.lc"
  318.                     ;;
  319.                 fr_fr)
  320.                     lc_file="${driver}_fr_utf8.lc"
  321.                     ;;
  322.                 zh_cn)
  323.                     lc_file="${driver}_zh_utf8.lc"
  324.                     ;;
  325.             esac
  326.             ;;
  327.     esac
  328.  
  329.     ## Set localize file ##
  330.     if [ $lc_file != "nolocalize" ]; then
  331.         if [ -f ${lc_file_dir}/${lc_file} ]; then
  332.             source ${lc_file_dir}/${lc_file}
  333.         fi
  334.     fi
  335.    
  336.     return 0
  337. }
  338.  
  339. ######################################################
  340. #### _ _ E x e c u t e _ I n s t a l l . s h  _ _ ####
  341. ######################################################
  342. if [ ${0##*/} = $C_install_script_fname ]; then
  343.  
  344.     #################################################################
  345.     #### _ _ B o t h _ P a c k a g e _ C o m m o n _ F l o w _ _ ####
  346.     #################################################################
  347.  
  348.     C_argment=$1
  349.  
  350.     ################
  351.     ### Localize ###
  352.     ################
  353.     C_local_path_inst="`echo $(dirname $0)`/resources"
  354.     C_FUNC_localize "$C_local_path_inst"
  355.  
  356.     ########################
  357.     ## Show the copyright ##
  358.     ########################
  359.     C_FUNC_get_system
  360.     if [ $? -eq 0 ]; then
  361.         if [ $C_system = "rpm" ]; then
  362.             ##  Check permission by root ##
  363.             if test `id -un` != "root"; then
  364.                 su -c "$0 $*"
  365.                 exit
  366.             fi
  367.         else
  368.             sudo echo > /dev/null
  369.             if [ $? -ne 0 ]; then
  370.                 exit
  371.             fi
  372.         fi
  373.     fi
  374.     echo $C_copyrightb; echo
  375.     $C_function03 "${C_version%%-*}"
  376.     echo ; echo $C_copyrightb
  377.  
  378.     #########################
  379.     ### Check the argment ###
  380.     #########################
  381.     if [ $# -eq 1 ]; then
  382.         if  [ $C_argment = "--bit32" ]; then
  383.             C_arch="32"
  384.         elif [ $C_argment = "--bit64" ]; then
  385.             C_arch="64"
  386.         else
  387.             C_err=$C_err_usage
  388.         fi
  389.     elif [ $# -ne 0 ]; then
  390.         C_err=$C_err_usage
  391.     fi
  392.  
  393.     if [ $C_err = $C_err_usage ]; then
  394.         printf "$L_INST_COM_02_01" "${0##*/} $C_arg_inst"
  395.         exit
  396.     fi
  397.  
  398.     #################################
  399.     ### Judge distribution system ###
  400.     #################################
  401.  
  402.     C_FUNC_get_system
  403.     if [ $? -ne 0 ]; then
  404.         printf "$L_INST_COM_01_02"
  405.         exit
  406.     fi
  407.  
  408.     #########################
  409.     ### Judge 32bit/64bit ###
  410.     #########################
  411.  
  412.     C_FUNC_get_bitconf
  413.     if [ $? -ne 0 ]; then
  414.         exit
  415.     fi
  416.  
  417.     ############################
  418.     ### Check file structure ###
  419.     ############################
  420.  
  421.     ## Get full path of script and packages ##
  422.     C_pkg_path=`echo $(dirname $0)`/packages
  423.     if [ ! -d $C_pkg_path ]; then
  424.         printf "$L_INST_COM_01_03"
  425.         exit
  426.     fi
  427.  
  428.     ## Count total files and check the filename ##
  429.     C_file_cnt=0
  430.     C_files=$C_pkg_path/*${C_arch}*
  431.     for filename in $C_files; do
  432.         if [ $filename != $C_pkg_path ]; then
  433.             # Count number of C_files           #
  434.             C_file_cnt=`expr $C_file_cnt + 1`
  435.            
  436.             # Get only file name              #
  437.             C_onlyfname=`echo ${filename##*/}`
  438.             # Check the extension, and the filename for module #
  439.             if [ `echo ${C_onlyfname##*.}` != $C_system -o `echo ${C_onlyfname%%-*}` != $C_main_module ]; then
  440.                 printf "$L_INST_COM_01_03"
  441.                 exit
  442.             fi
  443.  
  444.             # Get device name(ex.mx860series) #
  445.             C_tmpstr=`echo ${C_onlyfname##$C_main_module-}`
  446.             if [ $C_system = "rpm" ]; then
  447.                 if [ `echo ${C_tmpstr%%-$C_version*}` != $C_common ]; then
  448.                     C_device=`echo ${C_tmpstr%%-$C_version*}`
  449.                 fi
  450.             else
  451.                 if [ `echo ${C_tmpstr%%_$C_version*}` != $C_common ]; then
  452.                     C_device=`echo ${C_tmpstr%%_$C_version*}`
  453.                 fi
  454.             fi
  455.         fi
  456.     done
  457.  
  458.     ## Check number of C_files ##
  459.     if [ $C_file_cnt -ne 2 ]; then
  460.         printf "$L_INST_COM_01_03"
  461.         exit
  462.     fi
  463.  
  464.     ## Recheck package names ##
  465.     C_pkgname_common=$C_main_module-$C_common
  466.     C_pkgname_depend=$C_main_module-$C_device
  467.     if [ $C_system = "rpm" ]; then
  468.         C_fpath_common=$C_pkg_path/$C_pkgname_common-$C_version.$C_arch.$C_system
  469.         C_fpath_depend=$C_pkg_path/$C_pkgname_depend-$C_version.$C_arch.$C_system
  470.     else
  471.         C_fpath_common=$C_pkg_path/${C_pkgname_common}_${C_version}_$C_arch.$C_system
  472.         C_fpath_depend=$C_pkg_path/${C_pkgname_depend}_${C_version}_$C_arch.$C_system
  473.     fi
  474.  
  475.     ## Check having common and depend package files ##
  476.     if [ ! -f $C_fpath_common ] || [ ! -f $C_fpath_depend ]; then
  477.         printf "$L_INST_COM_01_03"
  478.         exit
  479.     fi
  480.  
  481.     #####################################################################
  482.     #### _ _ P a c k a g e _ S y s t e m _ D e p e n d _ F l o w _ _ ####
  483.     #####################################################################
  484.  
  485.     C_FUNC_rpm_install_process()
  486.     {
  487.         local c_fpath_pkg_name=$1
  488.         local c_pkg_name=$2
  489.         local c_exec_update=1
  490.         local c_installed_pkg=""
  491.        
  492.         ## result -> 0:Package installed, 1:Package not installed ##
  493.         c_installed_pkg=`rpm -q $c_pkg_name`
  494.         if [ $? -eq 0 ]; then
  495.             c_installed_pkg_ver=`echo ${c_installed_pkg##$c_pkg_name-}`
  496.             c_installed_pkg_ver=`echo ${c_installed_pkg_ver%%.$C_arch32}`
  497.             c_installed_pkg_ver=`echo ${c_installed_pkg_ver%%.$C_arch64}`
  498.             C_FUNC_version_comp $c_installed_pkg_ver $C_version
  499.             if [ $? -ne $C_small ]; then
  500.                 c_exec_update=0
  501.             fi
  502.         fi
  503.  
  504.         if [ $c_exec_update -eq 1 ]; then
  505.             C_FUNC_show_and_exec "rpm -Uvh $c_fpath_pkg_name"
  506.             if [ $? -ne 0 ]; then
  507.                 return $C_ERR_CODE
  508.             fi
  509.         else
  510.             C_FUNC_show_and_exec "rpm --test -U $c_fpath_pkg_name"
  511.         fi
  512.  
  513.         return 0   
  514.     }
  515.  
  516.     C_FUNC_deb_install_process()
  517.     {
  518.         local c_fpath_pkg_name=$1
  519.  
  520.         ## result -> 0:Install process complete, 1:Install process depend error ##
  521.         C_FUNC_show_and_exec "sudo dpkg -iG $c_fpath_pkg_name"
  522.         if [ $? != 0 ]; then
  523.             return $C_ERR_CODE
  524.         fi
  525.        
  526.         return 0
  527.     }
  528.  
  529.     ## Make Package-config script, after Check Newer version config script is installed already ##
  530.     C_FUNC_make_pkgconfig()
  531.     {
  532.         local c_pkgconfig_fname=$1
  533.         local c_script_path=$2
  534.         local c_sudo_command=$3
  535.         local c_pkgconfig_fpath="$c_script_path/$c_pkgconfig_fname"
  536.         local c_config_path=""
  537.  
  538.         if [ ! -d /usr ]; then
  539.             $c_sudo_command mkdir /usr
  540.         fi
  541.         if [ $2 = "rpm" ]; then
  542.             if [ ! -d /usr/local ]; then
  543.                 mkdir /usr/local
  544.             fi
  545.             c_config_path=$C_config_path_rpm
  546.         else
  547.             c_config_path=$C_config_path_deb
  548.         fi
  549.         if [ ! -d $c_config_path ]; then
  550.             $c_sudo_command mkdir $c_config_path
  551.         fi
  552.  
  553.         $c_sudo_command cp -af $(dirname $0)/$C_install_script_fname $c_pkgconfig_fpath
  554.  
  555.         ## Change file permission to same install.sh ##
  556.         $c_sudo_command chmod 755 $c_pkgconfig_fpath
  557.         $c_sudo_command chown root $c_pkgconfig_fpath
  558.         $c_sudo_command chgrp root $c_pkgconfig_fpath
  559.     }
  560.  
  561.     ## Copy Localize-file, after making pkeconfig script ##
  562.     C_FUNC_copy_lcfile()
  563.     {
  564.         local c_lcfile_srcpath=$1
  565.         local c_lcfile_dstname=$2
  566.         local c_sudo_command=$3
  567.         local c_lcfile_dstpath=""
  568.  
  569.         if [ ! -d /usr ]; then
  570.             $c_sudo_command mkdir /usr
  571.         fi
  572.         if [ $C_system = "rpm" ]; then
  573.             if [ ! -d /usr/local ]; then
  574.                 mkdir /usr/local
  575.             fi
  576.             if [ ! -d /usr/local/share ]; then
  577.                 mkdir /usr/local/share
  578.             fi
  579.             c_lcfile_dstpath="/usr/local/share"
  580.         else
  581.             if [ ! -d /usr/share ]; then
  582.                 $c_sudo_command mkdir /usr/share
  583.             fi
  584.             c_lcfile_dstpath="/usr/share"
  585.         fi
  586.  
  587.         $c_sudo_command rm -rf $c_lcfile_dstpath/$c_lcfile_dstname
  588.         $c_sudo_command mkdir $c_lcfile_dstpath/$c_lcfile_dstname
  589.  
  590.         $c_sudo_command cp -a $c_lcfile_srcpath/*.lc $c_lcfile_dstpath/$c_lcfile_dstname/
  591.     }
  592.  
  593.     if [ $C_system = "rpm" ]; then
  594.         C_install_process="C_FUNC_rpm_install_process"
  595.         C_uninstall_command="rpm -e"
  596.         C_script_path=$C_config_path_rpm
  597.         C_sudo_command=""
  598.     else
  599.         C_install_process="C_FUNC_deb_install_process"
  600.         C_uninstall_command="sudo dpkg -P"
  601.         C_script_path=$C_config_path_deb
  602.         C_sudo_command="sudo"
  603.     fi
  604.  
  605.     ## Common-Package install process ##
  606.     $C_install_process $C_fpath_common $C_main_module-$C_common
  607.     if [ $? -ne 0 ]; then
  608.         if [ $C_system = "deb" ]; then
  609.             C_FUNC_show_and_exec "$C_uninstall_command $C_pkgname_common"
  610.         fi
  611.         exit
  612.     fi
  613.        
  614.     ## Depend-Package install process ##
  615.     $C_install_process $C_fpath_depend $C_main_module-$C_device
  616.     if [ $? -ne 0 ]; then
  617.         if [ $C_system = "deb" ]; then
  618.             C_FUNC_show_and_exec "$C_uninstall_command $C_pkgname_depend"
  619.         fi
  620.         C_FUNC_show_and_exec "$C_uninstall_command $C_pkgname_common"
  621.         exit
  622.     fi
  623.        
  624.     C_pkgconfig_fname=$C_main_module-$C_device-pkgconfig.sh
  625.     C_pkgconfig_dname=${C_pkgconfig_fname%%\.sh}
  626.     $C_pkgconfig_fname --pkgconfig 1> /dev/null 2>&1
  627.     if [ $? -ne 0 ]; then
  628.         C_FUNC_make_pkgconfig $C_pkgconfig_fname $C_script_path $C_sudo_command
  629.         C_FUNC_copy_lcfile $C_local_path_inst $C_pkgconfig_dname $C_sudo_command
  630.     else
  631.         C_installed_config_ver=`$C_pkgconfig_fname --pkgconfig`
  632.         C_FUNC_version_comp $C_installed_config_ver $C_version
  633.         if [ $? -lt $C_equal ]; then
  634.             $C_sudo_command rm -rf $C_script_path/$C_pkgconfig_fname
  635.             C_FUNC_make_pkgconfig $C_pkgconfig_fname $C_script_path $C_sudo_command
  636.             C_FUNC_copy_lcfile $C_local_path_inst $C_pkgconfig_dname $C_sudo_command
  637.         fi
  638.     fi
  639.    
  640.     $C_function01 "$L_INST_COM_01_04" "$C_device" "$C_system"
  641.  
  642. ##########################################################
  643. #### _ _ E x e c u t e _ P k g c o n f i g . s h  _ _ ####
  644. ##########################################################
  645. else
  646.     C_argment=$1
  647.  
  648.     #################################
  649.     ### Judge distribution system ###
  650.     #################################
  651.     C_FUNC_get_system
  652.     if [ $? -ne 0 ]; then
  653.         printf "$L_INST_COM_01_02"
  654.         exit
  655.     fi
  656.  
  657.     C_intermediate=${0##*$C_main_module-}
  658.     C_device=${C_intermediate%%-*}
  659.  
  660.     ################
  661.     ### Localize ###
  662.     ################
  663.     if [ $C_system = "rpm" ]; then
  664.         C_local_path_pkgconf="/usr/local/share/${C_main_module}-${C_device}-pkgconfig"
  665.     else
  666.         C_local_path_pkgconf="/usr/share/${C_main_module}-${C_device}-pkgconfig"
  667.     fi
  668.     C_FUNC_localize "$C_local_path_pkgconf"
  669.  
  670.     ## Check the argment ##
  671.     if [ $# -ne 1 ]; then
  672.         C_err=$C_err_usage
  673.     elif [ $C_argment != "--version" ] && [ $C_argment != "--uninstall" ] && [ $C_argment != "--pkgconfig" ]; then
  674.         C_err=$C_err_usage
  675.     fi
  676.  
  677.     if [ $C_err = $C_err_usage ]; then
  678.         printf "$L_INST_COM_02_01" "${0##*/} $C_arg_pkg"
  679.         exit
  680.     fi
  681.  
  682.     ########################
  683.     ### Unistall process ###
  684.     ########################
  685.     if [ $C_argment = "--uninstall" ]; then
  686.    
  687.         C_FUNC_rpm_uninstall_process()
  688.         {
  689.             rpm -q $1 1> /dev/null 2>&1
  690.             ## result -> 0:Package installed, 1:Package not installed ##
  691.             if [ $? -eq 0 ]; then
  692.                 # uninstall #
  693.                 C_FUNC_show_and_exec "rpm -e $1"
  694.                 ## result -> 0:Uninstall complete, 1:Uninstall error by debendency ##
  695.                 if [ $? -ne 0 ]; then
  696.                     # Dependency error #
  697.                     return $C_ERR_CODE
  698.                 fi
  699.             fi
  700.             return 0
  701.         }
  702.  
  703.         C_FUNC_deb_uninstall_process()
  704.         {
  705.             # uninstall #
  706.             C_FUNC_show_and_exec "sudo dpkg -P $1"
  707.             ## result -> 0:Uninstall complete, 1:Uninstall error by debendency ##
  708.             if [ $? -ne 0 ]; then
  709.                 # Dependency error #
  710.                 return $C_ERR_CODE
  711.             fi
  712.            
  713.             return 0
  714.         }
  715.  
  716.         if [ $C_system = "rpm" ]; then
  717.             C_uninstall_process="C_FUNC_rpm_uninstall_process"
  718.             C_sudo_command=""
  719.            
  720.             ##  Check permission by root ##
  721.             if test `id -un` != "root"; then
  722.                 su -c "$0 $C_argment"
  723.                 exit
  724.             fi
  725.         else
  726.             C_uninstall_process="C_FUNC_deb_uninstall_process"
  727.             C_sudo_command="sudo"
  728.  
  729.             sudo echo > /dev/null
  730.                 if [ $? -ne 0 ]; then
  731.                 exit
  732.             fi
  733.         fi
  734.  
  735.         $C_function02 "$C_device" "$C_system"
  736.  
  737.         ##  Uninstall Depend-Package ##
  738.         $C_uninstall_process $C_main_module-$C_device
  739.         if [ $? -ne 0 ]; then
  740.             exit
  741.         fi
  742.  
  743.         ##  Delete mine (pkgconfig.sh)  ##
  744.         $C_sudo_command rm -rf $(dirname $0)/${0##*/}
  745.  
  746.         C_pkgconfigsh=${0##*/}
  747.         C_pkgconfig=${C_pkgconfigsh%%\.sh}
  748.         if [ $C_system = "rpm" ]; then
  749.             C_lcfile_path="/usr/local/share/${C_pkgconfig}"
  750.         else
  751.             C_lcfile_path="/usr/share/${C_pkgconfig}"
  752.         fi
  753.         $C_sudo_command rm -rf $C_lcfile_path
  754.        
  755.         ##  Uninstall Common-Package ##
  756.         $C_uninstall_process $C_main_module-$C_common
  757.  
  758.         printf "$L_INST_COM_02_02"
  759.  
  760.     ###############################
  761.     ### Version display process ###
  762.     ###############################
  763.     elif [ $C_argment = "--version" ]; then
  764.  
  765.         #########################
  766.         ### Judge 32bit/64bit ###
  767.         #########################
  768.          
  769.         C_FUNC_get_bitconf version
  770.         if [ $? -eq $C_ERR_CODE ]; then
  771.             exit
  772.         fi
  773.                
  774.         echo ; $C_function03 "${C_version%%-*}"
  775.         printf "\n$L_INST_COM_03_01"
  776.        
  777.         if [ $C_system = "rpm" ]; then
  778.             echo $C_main_module-$C_common-$C_version.$C_arch.$C_system
  779.             echo $C_main_module-$C_device-$C_version.$C_arch.$C_system
  780.         else
  781.             echo $C_main_module-${C_common}_${C_version}_$C_arch.$C_system
  782.             echo $C_main_module-${C_device}_${C_version}_$C_arch.$C_system
  783.         fi
  784.         echo
  785.  
  786.     elif [ $C_argment = "--pkgconfig" ]; then
  787.         echo $C_version
  788.     fi
  789.  
  790. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement