自已编写对于hexo管理的脚本

    1. #!/bin/bash
    2. function initUI()
    3. {
    4. while [ true ]
    5. do
    6. echo ""
    7. echo "------------------------"
    8. echo "----- h e x o -----"
    9. echo "------------------------"
    10. echo " 1. start server "
    11. echo " 2. shutdown server "
    12. echo " 3. hexo pid "
    13. echo " 4. auto note update "
    14. echo " 5. auto note deploy "
    15. echo " 6. auto doc update "
    16. echo " 7. update source "
    17. echo " 0. auto All upate "
    18. echo -n " Please enter : "
    19. read num
    20. if [ -z $num ];then
    21. exit 0
    22. elif [ $num = 1 ];then
    23. startServer
    24. elif [ $num = 2 ];then
    25. stopServer
    26. elif [ $num = 3 ];then
    27. getPID
    28. elif [ $num = 4 ];then
    29. autoUpdate
    30. startServer
    31. elif [ $num = 5 ];then
    32. autoDeploy
    33. elif [ $num = 6 ];then
    34. autoDocUpdate
    35. elif [ $num = 7 ];then
    36. updateSou
    37. elif [ $num = 0 ];then
    38. autoAllUpate
    39. else
    40. echo "Input error !!!!!!"
    41. fi
    42. done
    43. }
    44. function startServer()
    45. {
    46. cd /opt/blog
    47. nohup hexo server -p 80 >/dev/null 2>&1 &
    48. echo -n "start server sucess !!! PID ::: "
    49. getPID
    50. }
    51. function stopServer()
    52. {
    53. chkHexo=`ps -ef|grep hexo |grep -v grep | grep -v /bin/bash |awk '{print $2}'`
    54. if [[ -z $chkHexo ]];then
    55. echo " hexo server is stop !!! "
    56. else
    57. ps -ef|grep hexo |grep -v grep | grep -v /bin/bash| awk '{print $2}' | xargs kill -9 >> /dev/null
    58. echo "stop hexo success !!! "
    59. fi
    60. }
    61. function getPID()
    62. {
    63. ps -ef | grep hexo | grep -v grep | grep -v /bin/bash | awk '{print $2}'
    64. echo ""
    65. }
    66. function autoUpdate()
    67. {
    68. stopServer
    69. echo ""
    70. updateEnv /opt/blog
    71. nginx -s reload
    72. }
    73. function autoDocUpdate()
    74. {
    75. stopServer
    76. echo ""
    77. updateEnv /opt/hexo-theme-doc-seed
    78. nginx -s reload
    79. }
    80. function autoAllUpate()
    81. {
    82. stopServer
    83. echo ""
    84. updateEnv /opt/blog
    85. updateEnv /opt/hexo-theme-doc-seed
    86. nginx -s reload
    87. }
    88. function updateEnv()
    89. {
    90. echo $1
    91. cd $1/source
    92. git pull origin master
    93. cd $1
    94. rm -rf db.json
    95. hexo clean
    96. hexo generate
    97. gulp
    98. }
    99. function autoDeploy()
    100. {
    101. autoUpdate
    102. /usr/bin/expect <<-EOF
    103. spawn hexo deploy
    104. expect "Username"
    105. send "$gitUn\r"
    106. expect "Password"
    107. send "$gitPwd\r"
    108. interact
    109. expect eof
    110. EOF
    111. startServer
    112. }
    113. function updateSou()
    114. {
    115. cd /opt/blog/source
    116. git pull origin master
    117. }
    118. clear
    119. initUI