install 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
  3. if [ "$(command -v sqlite3)" == "" ]
  4. then
  5. echo "SQLite3 is not installed. Install it and try again."
  6. exit -1
  7. fi
  8. if [ "$(command -v php)" == "" ]
  9. then
  10. echo "PHP is not installed. Install it and try again."
  11. exit -2
  12. fi
  13. if [ "$(php -m | grep sqlite3)" == "" ]
  14. then
  15. echo "PHP module sqlite3 is not installed. Install it and try again."
  16. exit -3
  17. fi
  18. reinstall=0
  19. for i in "$@"
  20. do
  21. if [[ $i == "--reinstall" ]] ; then
  22. reinstall=1;
  23. fi
  24. done
  25. if [ -f $SCRIPTPATH/data/sw.sqlite ] && [ $reinstall == 0 ]
  26. then
  27. echo "User data database exist. It will not be overwritten. Use the --reinstall argument to override."
  28. else
  29. echo "Setting up user tables..."
  30. rm $SCRIPTPATH/data/sw.sqlite
  31. cp $SCRIPTPATH/installer/data_empty.sqlite $SCRIPTPATH/data/sw.sqlite
  32. fi
  33. # Ask for admin user and password
  34. correct=0
  35. while [ $correct -eq 0 ]
  36. do
  37. read -p "Enter admin username:" $user
  38. if [[ $user =~ ^[a-zA-Z0-9]{4, 32}$ ]]
  39. then
  40. correct=1
  41. else
  42. echo "Invalid username. Use numbers or letters. Length must be between 4 and 32 characters."
  43. fi
  44. done
  45. correct=0
  46. while [ $correct -eq 0]
  47. do
  48. read -p "Enter admin email:" $mail
  49. if [[ $mail =~ ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$ ]]
  50. then
  51. correct=1
  52. else
  53. echo "Invalid email."
  54. fi
  55. match=0
  56. while [ $match -eq 0 ]
  57. do
  58. read -s -p "Enter password:" $password
  59. read -s -p "Enter password:" $passwordRepeat
  60. if [ "$password" = "$passwordRepeat" ]
  61. then
  62. match=1
  63. else
  64. echo "Paswords do not match"
  65. fi
  66. done
  67. hash=$(echo -n $password | sha256sum)
  68. api=$(head -1 <(fold -w 16 <(tr -dc 'a-zA-Z0-9' < /dev/urandom)))
  69. query="INSERT INTO USER VALUES (0, '$user', '$mail', '$hash', '$api', 1, 0);"
  70. echo "All done. You can start the web server by typing ./start_server or edit the config file for the server options"