Update zh.json translation
[gitter.git] / obtain-secrets
blob5a246804d493520ff94770a544b6123881323ae9
1 #!/usr/bin/env bash
3 function browse_to {
4 if (which xdg-open >/dev/null); then
5 xdg-open $1
6 else
7 open $1
8 fi
11 function hash {
12 if (which sha256sum >/dev/null); then
13 sha256sum
14 else
15 md5
19 function generate_password {
20 if (which openssl >/dev/null); then
21 openssl rand -hex 32
22 else
23 (hostname; date +%s; ls -la /) | rev | hash | base64 | head -c 32
27 if [[ -f .env ]]; then
28 source .env
32 echo "Welcome..."
34 if [[ -z "${gitlaboauth__client_id}${gitlaboauth__client_secret}" ]]; then
35 echo ""
36 echo "You need to create a GitLab Application to connect with GitLab"
37 echo "Application Name: Gitter User Dev"
38 echo "Redirect URI: http://localhost:5000/login/gitlab/callback"
39 echo "Select the \"api\" and \"read_user\" scope"
40 echo ""
41 echo "Press ENTER to open GitLab"
42 read nothing
43 browse_to https://gitlab.com/profile/applications
44 echo ""
45 echo "Paste the Application ID below and press ENTER"
46 read gitlaboauth__client_id
47 echo "Paste the Secret below and press ENTER"
48 read gitlaboauth__client_secret
49 echo ""
52 if [[ -z "${github__user_client_id}${github__user_client_secret}" ]]; then
53 echo ""
54 echo "You need to create a GitHub Application to connect with GitHub"
55 echo "Application Name: Gitter User Dev"
56 echo "Homepage URL: http://localhost:5000"
57 echo "Authorisation callback URL: http://localhost:5000/login/callback"
58 echo ""
59 echo "Press ENTER to open GitHub"
60 read nothing
61 browse_to https://github.com/settings/applications/new
62 echo ""
63 echo "Paste the Client ID below and press ENTER"
64 read github__user_client_id
65 echo "Paste the Client Secret below and press ENTER"
66 read github__user_client_secret
67 echo ""
70 if [[ -z "${github__client_id}${github__client_secret}" ]]; then
71 echo ""
72 echo "You need to do this again to create a scoped token for Private Repository access"
73 echo "Application Name: Gitter Private Dev"
74 echo "Homepage URL: http://localhost:5000"
75 echo "Authorisation callback URL: http://localhost:5000/login/callback"
76 echo ""
77 echo "Press ENTER to open GitHub"
78 read nothing
79 browse_to https://github.com/settings/applications/new
80 echo ""
81 echo "Paste the Client ID below and press ENTER"
82 read github__client_id
83 echo "Paste the Client Secret below and press ENTER"
84 read github__client_secret
85 clear
88 if [[ -z "${twitteroauth__consumer_key}${twitteroauth__consumer_secret}" ]]; then
89 echo ""
90 echo "We also connect with Twitter, so, yeah, you need to create a Twitter App too."
91 echo "Name: Gitter Twitter YOURTWITTERUSERNAME"
92 echo "Description: Connect Gitter with Twitter"
93 echo "Website: http://test.gitter.im"
94 echo "Callback URL: http://localhost:5000/login/twitter/callback"
95 echo ""
96 echo "Press ENTER to open Twitter"
97 read nothing
98 browse_to https://developer.twitter.com/en/apps/create
99 echo "Click 'keys and tokens' to get your Consumer API Keys"
100 echo "Paste the Consumer API Key below and press ENTER"
101 read twitteroauth__consumer_key
102 echo "Paste the Consumer API Secret Key below and press ENTER"
103 read twitteroauth__consumer_secret
104 clear
107 if [[ -f .env ]]; then
108 cp .env .env.backup.$(date +%s)
111 cat <<EOF >.env
112 export web__sessionSecret="$(generate_password)"
113 export ws__superClientPassword="$(generate_password)"
114 export web__messageSecret="$(generate_password)"
115 export email__unsubscribeNotificationsSecret="$(generate_password)"
116 export integrations__secret="$(generate_password)"
117 export github__statePassphrase="$(generate_password)"
118 export twitteroauth__consumer_key="${twitteroauth__consumer_key}"
119 export twitteroauth__consumer_secret="${twitteroauth__consumer_secret}"
120 export gitlaboauth__client_id="${gitlaboauth__client_id}"
121 export gitlaboauth__client_secret="${gitlaboauth__client_secret}"
122 export github__client_id="${github__client_id}"
123 export github__client_secret="${github__client_secret}"
124 export github__user_client_id="${github__user_client_id}"
125 export github__user_client_secret="${github__user_client_secret}"
126 export github__anonymous_app__client_id="${github__user_client_id}"
127 export github__anonymous_app__client_secret="${github__user_client_secret}"
128 export tokens__anonymousPassword="$(generate_password)"
129 export matrix__bridge__id="$(generate_password)"
130 export matrix__bridge__hsToken="$(generate_password)"
131 export matrix__bridge__asToken="$(generate_password)"
134 echo "You're good to go"
135 echo "Run 'source .env' to export your secret environment variables"
136 echo "Then run 'npm start'"