Skip to content

Instantly share code, notes, and snippets.

@SoftCreatR
Last active September 29, 2020 21:29
Show Gist options
  • Save SoftCreatR/5f1ceaba04f372256b10205c3062aba3 to your computer and use it in GitHub Desktop.
Save SoftCreatR/5f1ceaba04f372256b10205c3062aba3 to your computer and use it in GitHub Desktop.
Windows Build Script for WoltLab Suite packages using 7zip
@ECHO OFF
goto :start
MIT License
Copyright (c) 2020 Sascha Greuel <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
:start
Rem Set package name based on the current directory
FOR %%I IN (.) DO SET PACKAGE_NAME=%%~nI%%~xI
Rem Extract version number from package.xml
FOR /f "delims=" %%a in ('findstr /i /l /c:"<version>" "package.xml"') DO SET "PACKAGE_VERSION=%%a"
SET "PACKAGE_VERSION=%PACKAGE_VERSION:*<version>=%"
FOR /f "delims=<" %%a in ("%PACKAGE_VERSION%") DO SET "PACKAGE_VERSION=%%a"
Rem Replace spaces with underscores
SET PACKAGE_VERSION=%PACKAGE_VERSION: =_%
Rem Replace uppercase letters to lowercase (supports the words "alpha", "beta", "dev", "pl" & "rc"
FOR %%a IN ("A=a" "B=b" "C=c" "D=d" "E=e" "H=h" "L=l" "M=m" "P=p" "R=r" "T=t" "V=v") DO (
CALL SET PACKAGE_VERSION=%%PACKAGE_VERSION:%%~a%%
)
Rem Delete files*.tar if present
IF EXIST files*.tar (
del files*.tar
)
Rem Delete templates*.tar if present
IF EXIST templates*.tar (
del templates*.tar
)
Rem Delete acptemplates*.tar if present
IF EXIST acptemplates*.tar (
del acptemplates*.tar
)
Rem Delete PACKAGE_NAME*.tar if present
IF EXIST %PACKAGE_NAME%*.tar (
del %PACKAGE_NAME%*.tar
)
Rem Delete PACKAGE_NAME*.tar.gz if present
IF EXIST %PACKAGE_NAME%*.tar.gz (
del %PACKAGE_NAME%*.tar.gz
)
Rem Compress files directory if present
IF EXIST files (
7z a -ttar -mx=9 files.tar .\files\*
)
Rem Compress files_update directory if present
IF EXIST files_update (
7z a -ttar -mx=9 files_update.tar .\files_update\*
)
Rem Compress templates directory if present
IF EXIST templates (
7z a -ttar -mx=9 templates.tar .\templates\*
)
Rem Compress templates_update directory if present
IF EXIST templates_update (
7z a -ttar -mx=9 templates_update.tar .\templates_update\*
)
Rem Compress acptemplates directory if present
IF EXIST acptemplates (
7z a -ttar -mx=9 acptemplates.tar .\acptemplates\*
)
Rem Compress acptemplates_update directory if present
IF EXIST acptemplates_update (
7z a -ttar -mx=9 acptemplates_update.tar .\acptemplates_update\*
)
Rem Create PACKAGE_NAME.tar
7z a -ttar -mx=9 %PACKAGE_NAME%_v%PACKAGE_VERSION%.tar .\* -x!acptemplates -x!acptemplates_update -x!files -x!files_update -x!templates -x!templates_update -x!%PACKAGE_NAME%.tar -x!.git -x!.gitignore -x!make.bat -x!make.sh -x!.vscode -x!.idea -x!constants.php
timeout 1 >nul
Rem Create PACKAGE_NAME.tar.gz
7z a -tgzip %PACKAGE_NAME%_v%PACKAGE_VERSION%.tar.gz %PACKAGE_NAME%_v%PACKAGE_VERSION%.tar
timeout 1 >nul
Rem Delete files*.tar if present
IF EXIST files*.tar (
del files*.tar
)
Rem Delete templates*.tar if present
IF EXIST templates*.tar (
del templates*.tar
)
Rem Delete acptemplates*.tar if present
IF EXIST acptemplates*.tar (
del acptemplates*.tar
)
timeout 1 >nul
Rem Delete PACKAGE_NAME*.tar if present
IF EXIST %PACKAGE_NAME%*.tar (
del %PACKAGE_NAME%*.tar
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment