-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_prod.sh
87 lines (74 loc) · 2.35 KB
/
setup_prod.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
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
echo
echo '-- Setting up PRODUCTION site --'
echo
echo "Paths:"
CURRENT_PATH=$PWD
if [[ $CURRENT_PATH = /chroot* ]]; then
BASE="${CURRENT_PATH:7}";
else
BASE=${CURRENT_PATH}
fi
RELEASES="$BASE/releases";
RELEASE="$RELEASES/1";
SHARED="$BASE/shared"
printf "Current: ${PWD}\nRoot: ${BASE}\nReleases: ${RELEASES}\nRelease: ${RELEASE}\nShared: ${SHARED}\n\n"
if [ -d "$RELEASES" ]; then
echo "The releases dir (${RELEASES}) already exists. Cannot continue."
exit 1
fi
PHP_VERSION=$(php -v|grep --only-matching --perl-regexp "(PHP )\d+\.\\d+\.\\d+"|cut -c 5-7)
PHP_MINIMUM_VERSION=8.4
printf "Current PHP version: ${PHP_VERSION}\nMinimum PHP version: ${PHP_MINIMUM_VERSION}\n"
if [ $(echo "$PHP_VERSION >= $PHP_MINIMUM_VERSION" | bc) -eq 0 ]; then
echo "************"
echo "Will switch PHP version to ${PHP_MINIMUM_VERSION}"
echo "************"
fi
echo
read -p "Are you in the domain dir, where the html dir is and the paths above are correct? (Y/n) " -n 1 -r
echo # move to a new line after response
if [[ ! $REPLY =~ ^[Y]$ ]]; then
echo
echo 'Cancelled'
echo
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
printf "\n\n"
cd $BASE || exit
echo "Working in: $PWD"
printf "\n\n"
echo "Creating ssh key dir/files"
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
echo "Install oh-my-zsh"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
printf "\nDISABLE_AUTO_TITLE=\"true\"" >> ~/.zshrc
printf "\n\n"
if [ $(echo "$PHP_VERSION >= $PHP_MINIMUM_VERSION" | bc) -eq 0 ]; then
echo "Switching PHP version to ${PHP_MINIMUM_VERSION}"
printf "\nsource /opt/remi/php81/enable" >> ~/.zshrc
printf "\nsource /opt/remi/php81/enable" >> ~/.bashrc
source /opt/remi/php81/enable
php -v
fi
echo "Creating dirs in ${BASE}"
cd $BASE || exit
mkdir -p $RELEASE
mkdir -p $RELEASE/public
mkdir -p $SHARED/public/assets
ln -s $RELEASE current
rm -rf html
ln -s current/public html
mkdir -p $SHARED/storage
mkdir -p $SHARED/storage/rebrand
ln -s $SHARED/storage $RELEASE/storage
ln -s $SHARED/public/assets $RELEASE/public/assets
printf "\n\n"
cd $RELEASE || exit
echo "Ready! You can attempt a deploy."
echo
echo "To switch to oh-my-zsh, run: /bin/zsh"
echo