profile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # /etc/profile
  2. # /run is not automatically created by guix
  3. mkdir /run
  4. # Quick access to $GUIX_ENVIRONMENT, for usage on config files
  5. # (currently only /etc/nginx/nginx.conf)
  6. ln -s $GUIX_ENVIRONMENT /env
  7. # Link every file in /usr/etc on /etc
  8. ls -1d /usr/etc/* | while read filepath; do
  9. ln -s $filepath /etc/
  10. done
  11. # Guix' php-fpm and nginx use its installation path as prefix
  12. # This is a containerized application, we don't want that
  13. alias php-fpm='php-fpm -c /etc/php.ini -p ""'
  14. alias nginx='nginx -c "/etc/nginx/nginx.conf" -p "/tmp"'
  15. # To avoid nginx init errors
  16. mkdir /tmp/logs
  17. start () {
  18. mysqld_safe 1>/dev/null &
  19. php-fpm
  20. nginx
  21. }
  22. stop () {
  23. nginx -s stop
  24. mysqladmin shutdown
  25. killall php-fpm
  26. }
  27. # Random password generator
  28. # @param $1 password length
  29. randpw () {
  30. head /dev/urandom | tr -dc '_?!#A-Za-z0-9' | head -c $1 ; echo ''
  31. }
  32. ## Install MariaDB on first run
  33. if [ ! -d /var/lib/mysql/data/mysql ]; then
  34. # Awful hack, required to solve a bug on mariadb guix' package
  35. lc_messages_dir=$(find /gnu/store -type d -name english | grep mysql)
  36. sed -i -e "s|#lc_messages_dir#|$lc_messages_dir|" /usr/etc/my.cnf
  37. mysql_root_password=$(randpw 24)
  38. mysql_install_db
  39. mysqld_safe &
  40. sleep 3
  41. mysql -sf << EOF
  42. # set root password
  43. UPDATE mysql.user SET Password=PASSWORD('$mysql_root_password') WHERE User='root';
  44. # remove anonymous user
  45. DELETE FROM mysql.user WHERE User='';
  46. # remove remote root
  47. DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
  48. # remove test database
  49. DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
  50. # reload privilege tables
  51. FLUSH PRIVILEGES;
  52. EOF
  53. sed -i -e "s|# password|password = $mysql_root_password|" /usr/etc/my.cnf
  54. mysqladmin shutdown
  55. fi
  56. cat << EOF
  57. ____ _ _ _ _ ____ _
  58. / ___| \ | | | | | / ___|_ _(_)_ __
  59. | | _| \| | | | | | | _| | | | \ \/ /
  60. | |_| | |\ | |_| | | |_| | |_| | |> <
  61. \____|_| \_|\___/ \____|\__,_|_/_/\_\\
  62. Welcome! 'start' or 'stop' services using that same words as commands.
  63. EOF