-
-
Save soifou/8e798e40042c6832bb580058a6f103dd to your computer and use it in GitHub Desktop.
Prestashop 1.6 - some CLI operations in a Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RELEASE_URL = https://download.prestashop.com/download/releases | |
TRANSLATION_URL = https://www.prestashop.com/download/lang_packs/gzip | |
LOCALE = fr | |
DOMAIN = www.website.test | |
ADMIN_FOLDER = admin777 | |
ADMIN_LOGIN = [email protected] | |
# the higher version you want to grab | |
LATEST_PS_VERSION = 1.6.1.20 | |
DOCKER_NETWORK = lamp-network | |
PHP = docker run -ti --rm \ | |
-v $(PWD):/var/www/ \ | |
-w /var/www/ \ | |
-u `id -u`:`id -g` \ | |
--net=$(DOCKER_NETWORK) \ | |
soifou/php-alpine:cli-5.6 | |
DB_SERVER = 127.0.0.1 | |
DB_NAME = dbname | |
DB_USER = root | |
DB_PASS = root | |
MYSQL = docker exec -it lamp_db mysql -u$(DB_USER) -p$(DB_PASS) $(DB_NAME) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.SILENT: | |
.PHONY: cache-clean upgrade debug adminreset | |
.DEFAULT_GOAL= help | |
include .env | |
ifeq (,$(wildcard `pwd`/config/settings.inc.php)) | |
# see list here: https://www.prestashop.com/en/developers-versions | |
# should match php constant _PS_VERSION_ set in config/settings.inc.php | |
CURRENT_PS_VERSION := `cat config/settings.inc.php | grep PS_VERSION | awk -F\' '{print $$4}'` | |
DB_SERVER = `cat config/settings.inc.php | grep DB_SERVER | awk -F\' '{print $$4}'` | |
DB_NAME = `cat config/settings.inc.php | grep DB_NAME | awk -F\' '{print $$4}'` | |
DB_USER = `cat config/settings.inc.php | grep DB_USER | awk -F\' '{print $$4}'` | |
DB_PASSWD = `cat config/settings.inc.php | grep DB_PASSWD | awk -F\' '{print $$4}'` | |
DB_PREFIX = `cat config/settings.inc.php | grep DB_PREFIX | awk -F\' '{print $$4}'` | |
PS_CACHE = `cat config/settings.inc.php | grep _PS_CACHE_ENABLED_ | awk -F\' '{print $$4}'` | |
COOKIE_KEY = `cat config/settings.inc.php | grep COOKIE_KEY | awk -F\' '{print $$4}'` | |
endif | |
help: | |
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | |
cleanup: ## Cleanup smarty cache | |
find cache/smarty ! -name 'index.php' -type f -exec rm -f {} + | |
echo "Smarty has been cleanup!" | |
debug: | |
echo "Current Prestashop version: $(CURRENT_PS_VERSION)" | |
echo "DB_SERVER: $(DB_SERVER)" | |
echo "DB_NAME: $(DB_NAME)" | |
echo "DB_USER: $(DB_USER)" | |
echo "DB_PASSWD: $(DB_PASSWD)" | |
echo "DB_PREFIX: $(DB_PREFIX)" | |
echo "COOKIE_KEY: $(COOKIE_KEY)" | |
echo "CACHE: $(PS_CACHE)" | |
install: ## Perform an install in one shot | |
# grab install folder | |
wget $(RELEASE_URL)/prestashop_$(LATEST_PS_VERSION).zip | |
unzip prestashop_$(LATEST_PS_VERSION).zip 'prestashop/*' -d tmp | |
mv tmp/prestashop/* . | |
rm -rf tmp | |
# install from cli | |
$(PHP) install/index_cli.php -d display_errors=1 \ | |
--step=all \ | |
--domain=$(DOMAIN) --name=$(DOMAIN) \ | |
--db_create=1 --db_server=$(DB_SERVER) --db_name=$(DB_NAME) --db_user=$(DB_USER) --db_password=$(DB_PASS) \ | |
--firstname=admin --lastname=admin --password=admin --email=admin@$(DOMAIN) \ | |
--language=$(LOCALE) --send_email=0 | |
# move backoffice folder | |
ifdef ADMIN_FOLDER | |
mv admin $(ADMIN_FOLDER) | |
endif | |
# done | |
rm -rf install | |
rm -rf prestashop_$(LATEST_PS_VERSION).zip | |
upgrade: ## Upgrade prestashop version | |
ifeq ($(shell expr $(PS_CACHE) \>= 1), 1) | |
echo "\033[1;41m/!\ Disable PrestaShop's cache before you start the update script\033[0m" | |
echo "=> open the config/settings.inc.php file, and check that define('PS_CACHE_ENABLED', '0'); is indeed set to 0." | |
exit 1; | |
endif | |
echo "Download Prestashop version $(LATEST_PS_VERSION)..." | |
wget --quiet $(RELEASE_URL)/prestashop_$(LATEST_PS_VERSION).zip | |
echo "Preparing the upgrade, please wait..." | |
cat /dev/null > ./log/$(shell date +'%Y%m%d')_upgrade.log | |
unzip -q prestashop_$(LATEST_PS_VERSION).zip 'prestashop/*' -d tmp | |
# copy all new stuff | |
cp -rf tmp/prestashop/* . | |
cp -rf admin/* $(ADMIN_FOLDER) | |
# remove cache and zip | |
rm prestashop_$(LATEST_PS_VERSION).zip cache/class_index.php | |
echo "Calling the database upgrade script..." | |
curl -X GET http://$(DOMAIN)/install/upgrade/upgrade.php | |
echo "Upgrading translations..." | |
rm -f translations/$(LOCALE).gzip | |
wget --quiet $(TRANSLATION_URL)/$(LATEST_PS_VERSION)/$(LOCALE).gzip -O translations/$(LOCALE).gzip | |
echo "Change Prestashop version in configuration files" | |
find config/settings.inc.php* -print | xargs sed -i "s/$(CURRENT_PS_VERSION)/$(LATEST_PS_VERSION)/g" | |
echo "Cleanup..." | |
rm -rf admin install tmp | |
echo "Prestashop has been upgraded from $(CURRENT_PS_VERSION) to $(LATEST_PS_VERSION) !" | |
bat ./log/$(shell date +'%Y%m%d')_upgrade.log | |
shopurl: ## Set correct shop URL | |
$(MYSQL) -e "UPDATE $(DB_PREFIX)shop_url SET domain = '$(DOMAIN)', physical_uri = '/'" | |
adminreset: ## Reset admin password | |
$(MYSQL) -e "UPDATE $(DB_PREFIX)employee SET passwd = MD5('"$(COOKIE_KEY)admin"') WHERE email = '$(ADMIN_LOGIN)';" | |
echo "Admin pass has been reset to <admin> for user below:" | |
$(MYSQL) -e "SELECT id_employee, email, last_connection_date FROM $(DB_PREFIX)employee WHERE email = '$(ADMIN_LOGIN)';" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment