-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
packaging.sh
158 lines (129 loc) Β· 4.99 KB
/
packaging.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
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
#!/bin/bash
##
# Title: Packaging Automation Tool for pH7Builder software.
#
# Author: Pierre-Henry Soria <hi@ph7.me>
# Copyright: (c) 2014-2022, Pierre-Henry Soria. All Rights Reserved.
# License: GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
##
function run-packaging-cleanup() {
_remove-tmp-files
_remove-tmp-folders
_update-composer
_clear-caches
_remove-dev-files
_remove-dev-folders
_permissions
}
#### Private functions ####
function _permissions() {
# Generic for folders/files
find . -type f -print0 | sudo xargs -0 chmod 666 # for files
find . -type d -print0 | sudo xargs -0 chmod 755 # for folders
# Specific ones
sudo chmod -R 777 ./_install/data/logs/
sudo chmod -R 777 ./_install/data/caches/
sudo chmod -R 777 ./_install/vendor/smarty/* # Change permission to prevent "Auto Install Folder Removal" to fail due to permission issues
sudo chmod -R 777 ./data/system/modules/*
sudo chmod -R 777 ./_repository/module/*
sudo chmod -R 777 ./_repository/upgrade/*
sudo chmod -R 777 ./_protected/app/configs/*
sudo chmod -R 777 ./_protected/data/cache/*
sudo chmod -R 777 ./_protected/data/backup/*
sudo chmod -R 777 ./_protected/data/tmp/*
sudo chmod -R 777 ./_protected/data/log/*
}
function _remove-tmp-files() {
find . -type f \( -name '*~' -or -name '*.log' -or -name '*.tmp' -or -name '*.swp' -or -name '.directory' -or -name '._*' -or -name '.DS_Store*' -or -name 'Thumbs.db' \) -exec rm {} \;
## Cleaning the code
params="-name '*.php' -or -name '*.css' -or -name '*.js' -or -name '*.html' -or -name '*.xml' -or -name '*.xsl' -or -name '*.xslt' -or -name '*.svg' -or -name '*.json' -or -name '*.yml' -or -name '*.tpl' -or -name '*.phs' -or -name '*.ph7' -or -name '*.sh' -or -name '*.sql' -or -name '*.ini' -or -name '*.md' -or -name '*.markdown' -or -name '.htaccess'"
exec="find . -type f \( $params \) -print0 | xargs -0 perl -wi -pe"
eval "$exec 's/\s+$/\n/'"
eval "$exec 's/\t/ /g'"
}
function _remove-tmp-folders() {
# Composer cache folder
rm -rf ./_install/vendor/cache/
rm -rf ./_protected/vendor/cache/
}
function _update-composer() {
# Update Composer itself to the latest version
composer self-update
# Install dependencies for production only (without dev packages)
composer install --no-dev
composer install --working-dir _install --no-dev
# Update the libraries to their latest versions (careful, some might have breaking changes in their minor patches)
composer update --no-dev
composer update --working-dir _install --no-dev
# Optimize Composer
composer dump-autoload --optimize --no-dev
composer dump-autoload --working-dir _install --optimize --no-dev
}
function _clear-caches() {
# public
rm -rf ./_install/data/caches/smarty_compile/*
rm -rf ./_install/data/caches/smarty_cache/*
# protected
rm -rf ./_protected/data/cache/pH7tpl_compile/*
rm -rf ./_protected/data/cache/pH7tpl_cache/*
rm -rf ./_protected/data/cache/pH7_static/*
rm -rf ./_protected/data/cache/pH7_cache/*
rm -rf ./_protected/data/backup/file/*
rm -rf ./_protected/data/backup/sql/*
rm ./_protected/data/tmp/*.txt
}
function _remove-dev-files() {
## Config Files, etc.
rm ./_constants.php
rm ./.gitignore
rm ./.gitattributes
rm ./.scrutinizer.yml
rm ./.travis.yml
rm ./composer.lock
rm ./_install/composer.lock
rm ./phpunit.phar
rm ./phpunit.xml.dist
rm ./_protected/app/configs/config.ini
rm ./nginx.conf
## PHPCS
rm ./phpcs.xml.dist
rm ./.php_cs
rm ./.php_cs.cache
rm ./.php_cs.dist
## Docker
rm ./Dockerfile
rm ./docker-compose.yml
rm ./.dockerignore
}
function _remove-dev-folders() {
# Config folders
rm -rf ./.github/
## Others
rm -f ./_protected/app/system/core/assets/cron/_delay/*
rm -rf ./_repository/import/*
rm -rf ./_repository/module/*
rm -rf ./_tests/
rm -rf ./_tools/
rm -rf ./.git/
}
echo "Please specify the release version number (e.g., 14.8.8)"
read version
if [ ! -z "$version" ]; then
name="pH7Builder"
tmp_project_folder="pH7-Social-Dating-CMS"
git clone git@github.com:pH7Software/pH7-Social-Dating-CMS.git $tmp_project_folder --depth=1
echo "Moving to '${tmp_project_folder}/' folder."
cd $tmp_project_folder
echo "Cleaning up the project. Removing unnecessary folders such as dev/testing files, etc."
run-packaging-cleanup
echo "Creating a zip archive for v${version}"
zip -qr ../${name}-${version}.zip .
echo "Moving back to previous main folder '../'"
cd ..
echo "Removing temporary '${tmp_project_folder}/' folder."
rm -rf $tmp_project_folder
echo "Whoopie! pH7Builder has been successfully packaged and ready to be distributed!"
echo "The zip file is available at: ${PWD}/${name}-${version}.zip"
else
echo "You need to enter a version number for this release."
fi