Skip to content

Instantly share code, notes, and snippets.

@JacobDB
Created July 19, 2019 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobDB/606aba6b93ef6d58a56e45f8873f9ade to your computer and use it in GitHub Desktop.
Save JacobDB/606aba6b93ef6d58a56e45f8873f9ade to your computer and use it in GitHub Desktop.
Initialization script for git-deploy
<?php
define("TOKEN", "g430vdsj07jDSFj93g21");
define("REMOTE_REPOSITORY", "https://gitlab+deploy-token-123:g430vdsj07jDSFj93g21@gitlab.com/JacobTheDev/new-site.git");
define("DIR", "{$_SERVER["DOCUMENT_ROOT"]}/.gitlab/repository/");
define("BRANCH", "refs/heads/master");
define("LOGFILE", "deploy.log");
define("GIT", "/usr/bin/git");
define("MAX_EXECUTION_TIME", 180);
define("BEFORE_PULL", "");
define("AFTER_PULL", "");
// get the server path
$_PATH = $_SERVER["DOCUMENT_ROOT"];
// get the theme name
preg_match("/\/([^\/]+)\.git$/", REMOTE_REPOSITORY, $_MATCHES);
$_NAME = $_MATCHES ? $_MATCHES[1] : false;
// verify that settings are configured
if (!$_PATH || !$_NAME) {
$_ERROR = !$_PATH && $_NAME ? "\$_PATH is" : ($_PATH && !$_NAME ? "\$_NAME is" : "\$_PATH and \$NAME are");
echo "error! {$_ERROR} not set properly!<br>"; exit;
}
echo "Using \"{$_PATH}\" as website directory...<br>";
echo "Using \"{$_NAME}\" as theme name...<br>";
// clone the repository
if (!exec("/usr/bin/git clone " . REMOTE_REPOSITORY . " " . DIR)) echo "ERROR! Repository was not cloned!<br />";
// generate the symlink
if (!symlink(DIR . "/dist", "{$_PATH}/wp-content/themes/{$_NAME}")) echo "ERROR! Symlink was not created!<br />";
// delete the file
if (!unlink(__FILE__)) echo "ERROR! Delete this file manually!<br>";
echo "initialized!"; exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment