-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·260 lines (232 loc) · 8.23 KB
/
setup.sh
File metadata and controls
executable file
·260 lines (232 loc) · 8.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
# NoteByNote Complete Setup Script
# Display banner
echo "=========================================================="
echo " _ _ _ ______ _ _ _ "
echo "| \ | | | | | ___ \ | \ | | | | "
echo "| \| | ___ | |_ ___| |_/ /_ _| \| | ___ | |_ ___ "
echo "| . \` |/ _ \| __/ _ \ ___ \ | | | . \` |/ _ \| __/ _ \\"
echo "| |\ | (_) | || __/ |_/ / |_| | |\ | (_) | || __/"
echo "\_| \_/\___/ \__\___\____/ \__, \_| \_/\___/ \__\___|"
echo " __/ | "
echo " |___/ "
echo "=========================================================="
echo " Fragrance Formulation & Analysis Platform"
echo "==============================================="
echo " Setup & Installation Script"
echo "==============================================="
# Check for required programs
echo "[SETUP] Checking system requirements..."
command -v python3 >/dev/null 2>&1 || { echo "Error: Python 3 is required but not installed. Aborting."; exit 1; }
command -v pip3 >/dev/null 2>&1 || { echo "Error: pip3 is required but not installed. Aborting."; exit 1; }
# Check for virtual environment and create if it doesn't exist
if [ ! -d "venv" ]; then
echo "[SETUP] Creating virtual environment..."
python3 -m venv venv
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to create virtual environment. Please install Python 3.8+ and try again."
exit 1
fi
fi
# Activate virtual environment
echo "[SETUP] Activating virtual environment..."
source venv/bin/activate
# Install dependencies
echo "[SETUP] Installing dependencies..."
pip install --upgrade pip
pip install -e .
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to install dependencies. Please check your internet connection and try again."
exit 1
fi
# Make sure required directories exist
echo "[SETUP] Creating required directories..."
mkdir -p instance
# Check if .env file exists, create template if not
if [ ! -f ".env" ]; then
echo "[SETUP] Creating .env file template..."
cat > .env << EOF
# NoteByNote Environment Configuration
# Flask Settings
FLASK_APP=run.py
FLASK_ENV=development
SECRET_KEY=$(python -c 'import os; import binascii; print(binascii.hexlify(os.urandom(24)).decode())')
# Database Settings
SQLALCHEMY_DATABASE_URI=sqlite:///instance/notebynote.db
SQLALCHEMY_TRACK_MODIFICATIONS=False
# Mail Settings
MAIL_SERVER=smtp.example.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USERNAME=your_email@example.com
MAIL_PASSWORD=your_mail_password
MAIL_DEFAULT_SENDER=your_email@example.com
# Application Settings
ADMIN_EMAIL=admin@example.com
EOF
echo "[SETUP] Created .env file template. Please update with your settings if needed."
fi
# Set up database
echo "[SETUP] Setting up database..."
python -c "from app import create_app, db; app = create_app(); app.app_context().push(); db.create_all()"
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to initialize database schema. Aborting."
exit 1
fi
echo "[SETUP] Database schema created successfully."
# Create admin user if it doesn't exist
echo "[SETUP] Creating admin user..."
python -c "
from app import create_app, db
from app.models import User
from werkzeug.security import generate_password_hash
from datetime import datetime
import os
app = create_app()
with app.app_context():
admin = User.query.filter_by(role='admin').first()
if not admin:
admin_user = User(
username='admin',
email='admin@example.com',
password_hash=generate_password_hash('admin123'),
role='admin',
created_at=datetime.utcnow(),
email_confirmed=True,
is_active=True
)
db.session.add(admin_user)
db.session.commit()
print('Admin user created with username: admin and password: admin123')
else:
print('Admin user already exists.')
"
# Populate database with notes
echo "[SETUP] Populating database with notes..."
python -c "
from app import create_app
from SetUpfiles.seed_notes import seed_notes
app = create_app()
with app.app_context():
seed_notes()
"
# Seed analytics data
echo "[SETUP] Setting up analytics data..."
python -c "
from app import create_app
from SetUpfiles.seed_analytics import seed_analytics
try:
seed_analytics()
print('Analytics data seeded successfully.')
except Exception as e:
print(f'Error seeding analytics data: {str(e)}')
print('Continuing with setup...')
"
# Create sample ingredients
echo "[SETUP] Creating sample ingredients..."
python -c "
from app import create_app, db
from app.models import Ingredient
app = create_app()
with app.app_context():
if Ingredient.query.count() == 0:
ingredients = [
Ingredient(
name='Bergamot Oil',
description='Essential oil expressed from the rind of bergamot orange',
source='Citrus bergamia fruit',
sustainability_rating=7,
allergen_level=2,
price_per_unit=120.00,
unit_type='ml',
supplier='Premium Essentials',
is_natural=True,
is_synthetic=False,
is_organic=True,
max_allowed_percentage=0.4
),
Ingredient(
name='Oakmoss',
description='Fragrant moss with woody, earthy character',
source='Evernia prunastri lichen',
sustainability_rating=5,
allergen_level=4,
price_per_unit=200.00,
unit_type='g',
supplier='Natural Aromatics',
is_natural=True,
is_synthetic=False,
is_organic=False,
max_allowed_percentage=0.1
),
Ingredient(
name='Birch Tar',
description='Smoky, leathery material derived from birch bark',
source='Betula alba bark',
sustainability_rating=6,
allergen_level=3,
price_per_unit=150.00,
unit_type='ml',
supplier='Forest Extracts',
is_natural=True,
is_synthetic=False,
is_organic=False,
max_allowed_percentage=0.2
),
Ingredient(
name='Synthetic Musk',
description='Clean, powdery musk alternative',
source='Laboratory synthesis',
sustainability_rating=8,
allergen_level=1,
price_per_unit=80.00,
unit_type='ml',
supplier='Modern Aromatics',
is_natural=False,
is_synthetic=True,
is_organic=False,
max_allowed_percentage=5.0
),
Ingredient(
name='Ambroxan',
description='Amber-like, woody, musky material',
source='Laboratory synthesis',
sustainability_rating=9,
allergen_level=1,
price_per_unit=180.00,
unit_type='ml',
supplier='Modern Aromatics',
is_natural=False,
is_synthetic=True,
is_organic=False,
max_allowed_percentage=10.0
)
]
db.session.add_all(ingredients)
db.session.commit()
print(f'Added {len(ingredients)} ingredients to the database.')
else:
print('Ingredients already exist in the database.')
"
# Make scripts executable
echo "[SETUP] Setting correct permissions for scripts..."
chmod +x start.sh
chmod +x setup.sh
# Success message
echo ""
echo "==============================================="
echo " Setup Complete! 🎉"
echo "==============================================="
echo ""
echo "NoteByNote has been successfully set up with:"
echo " - Virtual environment in ./venv/"
echo " - Database in ./instance/notebynote.db"
echo " - Admin user: admin / admin123"
echo " - Notes, ingredients and analytics data"
echo ""
echo "To start the application, run:"
echo " ./start.sh"
echo ""
echo "Don't forget to change the admin password"
echo "after your first login!"
echo "==============================================="