]> Untitled Git - lemmy.git/blob - scripts/install.sh
work around race condition on community fetch (#3414)
[lemmy.git] / scripts / install.sh
1 #!/usr/bin/env bash
2 set -e
3
4 # Set the database variable to the default first.
5 # Don't forget to change this string to your actual database parameters
6 # if you don't plan to initialize the database in this script.
7 export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
8
9 # Set other environment variables
10 export JWT_SECRET=changeme
11 export HOSTNAME=rrr
12
13 yes_no_prompt_invalid() {
14   echo "Invalid input. Please enter either \"y\" or \"n\"." 1>&2
15 }
16
17 ask_to_init_db() {
18   init_db_valid=0
19   init_db_final=0
20   while [ "$init_db_valid" == 0 ]
21   do
22     read -p "Initialize database (y/n)? " init_db
23     case "$init_db" in
24       [yY]* ) init_db_valid=1; init_db_final=1;;
25       [nN]* ) init_db_valid=1; init_db_final=0;;
26       * ) yes_no_prompt_invalid;;
27     esac
28     echo
29   done
30   if [ "$init_db_final" = 1 ]
31   then
32     source ./db-init.sh
33     read -n 1 -s -r -p "Press ANY KEY to continue execution of this script, press CTRL+C to quit..."
34     echo
35   fi
36 }
37
38 ask_to_auto_reload() {
39   auto_reload_valid=0
40   auto_reload_final=0
41   while [ "$auto_reload_valid" == 0 ]
42   do
43     echo "Automagically reload the project when source files are changed?"
44     echo "ONLY ENABLE THIS FOR DEVELOPMENT!"
45     read -p "(y/n) " auto_reload
46     case "$auto_reload" in
47       [yY]* ) auto_reload_valid=1; auto_reload_final=1;;
48       [nN]* ) auto_reload_valid=1; auto_reload_final=0;;
49       * ) yes_no_prompt_invalid;;
50     esac
51     echo
52   done
53   if [ "$auto_reload_final" = 1 ]
54   then
55     cd ui && yarn start
56     cd server && cargo watch -x run
57   fi
58 }
59
60 # Optionally initialize the database
61 ask_to_init_db
62
63 # Build the web client
64 cd ui
65 yarn
66 yarn build
67
68 # Build and run the backend
69 cd ../server
70 RUST_LOG=debug cargo run
71
72 # For live coding, where both the front and back end, automagically reload on any save
73 ask_to_auto_reload