_common.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # ============= FUTURE YUNOHOST HELPER =============
  3. # Delete a file checksum from the app settings
  4. #
  5. # $app should be defined when calling this helper
  6. #
  7. # usage: ynh_remove_file_checksum file
  8. # | arg: file - The file for which the checksum will be deleted
  9. ynh_delete_file_checksum () {
  10. local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
  11. ynh_app_setting_delete $app $checksum_setting_name
  12. }
  13. #Zabbix part
  14. #===================GET GUEST DEFAULT USER STATE==============
  15. #return 0 if enable, else 1
  16. get_state_guest_user(){
  17. return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9")
  18. }
  19. #================ DISABLE DEFAULT ZABBIX USER GUEST ===================
  20. disable_guest_user(){
  21. if [ get_state_guest_user -eq 0 ];then
  22. lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`")
  23. lastid=$(("$lastid" + 1 ))
  24. $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);"
  25. fi
  26. }
  27. #===================GET ADMIN DEFAULT USER STATE==============
  28. #return 0 if enable, else 1
  29. get_state_admin_user(){
  30. return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9")
  31. }
  32. #================ DISABLE DEFAULT ADMIN USER ===================
  33. disable_admin_user(){
  34. if [ get_state_admin_user -eq 0 ] ;then
  35. lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`")
  36. lastid=$((lastid + 1 ))
  37. $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);"
  38. fi
  39. }
  40. enable_admin_user(){
  41. if [ get_state_admin_user -eq 1 ] ;then
  42. ynh_print_info "Enable default admin"
  43. #enable default admin temporaly
  44. mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;"
  45. fi
  46. }