docker-entrypoint.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. supportDatabases=(mysql sqlite pgsql)
  3. installLockFile=${FeehiCMSPath}/install/install.lock
  4. yiiCmd=$FeehiCMSPath/yii
  5. function inArray(){
  6. i=0
  7. while [ $i -lt ${#supportDatabases[@]} ]
  8. do
  9. if [ "${supportDatabases[$i]}" == "$1" ];then
  10. return 0
  11. fi
  12. ((i++))
  13. done
  14. return 1
  15. }
  16. function initConfig(){
  17. "${FeehiCMSPath}/init" --env="${Env}" --overwrite=All
  18. }
  19. function importDB(){
  20. dbType=(${DBDSN//:/ })
  21. if ! inArray "$dbType"; then
  22. echo "DBHost error, only support ${supportDatabases[*]}"
  23. exit 1
  24. fi
  25. if [ "${dbType}" == sqlite ];then
  26. temp=${DBDSN%/*}
  27. sqliteDataPath=${temp/sqlite:/}
  28. if [ ! -d "${sqliteDataPath}" ]; then
  29. mkdir -p "$sqliteDataPath"
  30. fi
  31. else
  32. if [ "${DBUser}" == "" ];then
  33. echo "${dbType} must set env DBUser"
  34. fi
  35. fi
  36. sed -i "s#.*'dsn'.*# 'dsn' => '${DBDSN}',#g" "${FeehiCMSPath}/common/config/main-local.php"
  37. sed -i "s#.*'charset'.*# 'charset' => '${DBCharset}',#g" "${FeehiCMSPath}/common/config/main-local.php"
  38. sed -i "s#.*'tablePrefix'.*# 'tablePrefix' => '${TablePrefix}',#g" "${FeehiCMSPath}/common/config/main-local.php"
  39. if [ "${dbType}" != sqlite ];then
  40. sed -i "s#.*'username'.*# 'username' => '${DBUser}',#g" "${FeehiCMSPath}/common/config/main-local.php"
  41. sed -i "s#.*'password'.*# 'password' => '${DBPassword}',#g" "${FeehiCMSPath}/common/config/main-local.php"
  42. fi
  43. $yiiCmd migrate/up --interactive=0 frontendUri="${FrontendUri}" adminUsername="${AdminUsername}" adminPassword="${AdminPassword}"
  44. echo "Import database success; Configured Database info:"
  45. echo -e "DBDSN ${DBDSN}"
  46. if [ "$dbType" != sqlite ];then
  47. echo -e "DBUser ${DBUser} \nDBPassword ${DBPassword}"
  48. fi
  49. }
  50. start(){
  51. if [ "$fpmMode" -eq 1 ];then
  52. php-fpm
  53. else
  54. $yiiCmd serve "${Listening}"
  55. fi
  56. }
  57. onlineInstall=1
  58. downloadUploadFiles=0
  59. forceInstall=0
  60. fpmMode=0
  61. while getopts "odfm" OPT; do
  62. case ${OPT} in
  63. o)
  64. onlineInstall=0 #${OPTARG}
  65. ;;
  66. d)
  67. downloadUploadFiles=1 #download FeehiCMS init articles uploaded files
  68. ;;
  69. f)
  70. forceInstall=1 #will force to install no matter whether installed
  71. ;;
  72. m)
  73. fpmMode=1 #run fpm
  74. ;;
  75. ?)
  76. echo "Invalid option: -$OPTARG"
  77. exit 1
  78. esac
  79. done
  80. case ${!#} in
  81. start)
  82. if [ $forceInstall -eq 1 ];then
  83. rm -rf "$installLockFile"
  84. fi
  85. if [ ! -f "$installLockFile" ];then #need to install
  86. initConfig
  87. if [ $onlineInstall -eq 1 ];then #auto install
  88. importDB
  89. else
  90. rm -rf "$installLockFile" #need visis http://your-server-ip:port/install.php and then fill info for install FeehiCMS
  91. fi
  92. if [ $downloadUploadFiles -eq 1 ];then
  93. $yiiCmd feehi/download-upload-files
  94. fi
  95. fi
  96. start
  97. ;;
  98. sh|bash|/bin/bash|/bin/sh)
  99. /bin/bash -C
  100. ;;
  101. *)
  102. echo "usage:
  103. start: start server(if not installed will install first)
  104. sh: entry bash
  105. options
  106. -f will force to install FeehiCMS, no matter whether installed
  107. -o will not auto import database. you need visit host:port/install.php for online install
  108. -d download init FeehiCMS existed articles uplaoded files(pictures)
  109. -m run fpm(port 9000 cannot be modified)
  110. examples:
  111. docker run -it -name feehi -p 80:80 -v /data:/data -e Listening=0.0.0.0:80 -e feehi/cms -o start #start server then visit http://your-server-ip/install.php
  112. docker run -it -name feehi -p 80:80 -v /data:/data -e Listening=0.0.0.0:80 -e FrontendUri=//your-server-ip -e DBDSN=sqlite:/data/feehi.db -e TablePrefix=feehi_ -e AdminUsername=admin -e AdminPassword=123456 feehi/cms #auto import database sqlite
  113. docker run -it -name feehi -p 80:80 -v /data:/data -e Listening=0.0.0.0:80 -e FrontendUri=//your-server-ip -e DBDSN=mysql:host=x.x.x.x;dbname=feehi -e DBUser=xxx -e DBPassword=xxxxxx -e TablePrefix=feehi_ -e AdminUsername=admin -e AdminPassword=123456 feehi/cms #auto import database mysql
  114. "
  115. exit 1
  116. esac