-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·74 lines (61 loc) · 2.22 KB
/
install.sh
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
#!/usr/bin/env bash
set -eu -o pipefail
sudo apt update
sudo apt upgrade -y
sudo apt install -y python3-pip
sudo apt install -y python-is-python3
sudo apt install -y python3-venv
sudo mkdir -p /data
sudo chown ubuntu /data
mkdir -p /data/repos/log
mkdir -p ~/venv/cgit && python -m venv ~/venv/cgit
source ~/venv/cgit/bin/activate
pip install --upgrade pip
cd ~/git-integration
pip install -e .
# Move one directory up from the git-integration folder
cd ~
# Check if git-integration-environment folder exists
if [ ! -d "git-integration-environment" ]; then
git clone [email protected]:CrowdDotDev/git-integration-environment.git
else
# Pull the latest changes from git-integration-environment repository if it exists
cd git-integration-environment
git pull origin main
cd ~
fi
# Move back into the git-integration folder
cd ~
if [ "$1" == "prod" ]; then
# Copy the dotenv-prod file as .env, replacing it if it already exists
cp -f ~/git-integration-environment/dotenv-prod .env
cp -f ~/git-integration-environment/dotenv-prod git-integration/.env
echo "The dotenv-prod file has been copied as .env"
else
# Copy the dotenv-staging file as .env, replacing it if it already exists
cp -f ~/git-integration-environment/dotenv-staging .env
cp -f ~/git-integration-environment/dotenv-staging git-integration/env
echo "The dotenv-staging file has been copied as .env"
fi
echo "Setting up cron job"
# Create a temporary file
touch tmp-cron
# Check if the user has a crontab
if crontab -l >/dev/null 2>&1; then
# If the cron jobs already exist, skip adding
if crontab -l | grep -q "/home/ubuntu/venv/cgit/bin/crowd-git-ingest" && crontab -l | grep -q "/home/ubuntu/venv/cgit/bin/crowd-git-maintainers"; then
echo "Cron jobs already exist. Nothing to do."
rm tmp-cron
exit 0
fi
# Save the current crontab into a temporary file
crontab -l >tmp-cron
fi
# Append the new cron job entries
echo "0 */5 * * * /home/ubuntu/venv/cgit/bin/crowd-git-ingest >> /data/repos/log/cron.log 2>&1" >>tmp-cron
echo "0 0 * * * /home/ubuntu/venv/cgit/bin/crowd-git-maintainers >> /data/repos/log/maintainers.log 2>&1" >>tmp-cron
# Install the new crontab
crontab tmp-cron
# Remove the temporary file
rm tmp-cron
echo "Cron jobs added successfully."