Example WSP (SharePoint Solution Package) deployment script

Example WSP (SharePoint Solution Package) deployment script….
 
@echo off
REM  This file is complete.  There should be no reason to edit it.
REM  Run it on a SharePoint front end with administrator privileges.
if “”%1″” NEQ “”NewCommandStarted”” (
    cls
    echo.
    REM
    REM                         SET ENVIRONMENT
    REM
    set SPDIR=%ProgramFiles%\common files\microsoft shared\web server extensions\12
    set FOUNDITEM=false
    set Names_CAB=cab_names%1.txt
    set Names_Features=feature_names%1.txt
    echo Enter the URL to install the Solutions
    echo.
    set /p PortalUrl=eg.http://website:2034 :
    echo.
    REM
    REM                       RUN A BETTER CMD ENVIRONMENT
    REM
    cmd.exe /V:ON /Q /C Install.cmd NewCommandStarted
    goto end
)

if not EXIST %Names_CAB% (
    echo The file “”%Names_CAB%”” doesn’t exist in the current folder.
    echo.
    echo   This batch file must be run from within the same folder as %Names_CAB%
    echo and %Names_Features%
    goto end
)
if “”%PortalUrl%”” EQU “””” (
    echo Install aborted.  No server name was specified.
    goto end
)
echo Installing to %PortalUrl%
echo.
echo Hit {CTRL-C} to abort or Prepare to install
pause
cls
echo Preparing to install…
echo.
echo.
echo           UnInstalling possible old versions of the solution
echo.
echo  (Failures are expected when the feature and/or solution is not installed)
echo ____________________________________________________________________________
echo.
if not EXIST %Names_Features% goto RetractSolutions
for /F “”tokens=1* delims=,”” %%i in (%Names_Features%) do (
    if “”%%i”” NEQ “””” (
        echo Deactivating feature %%i
        if “”%%j”” NEQ “””” (
            “”%SPDIR%\bin\stsadm.exe”” -o deactivatefeature -name “”%%i”” -url %PortalUrl%/%%j -force > nul
        ) else (
            “”%SPDIR%\bin\stsadm.exe”” -o deactivatefeature -name “”%%i”” -url %PortalUrl% -force > nul
        )
        echo Uninstalling feature %%i
        “”%SPDIR%\bin\stsadm.exe”” -o uninstallfeature -name “”%%i”” -force
        echo.
    )
)
:RetractSolutions
for /F “”tokens=1* delims=,”” %%i in (%Names_CAB%) do (
    if “”%%i”” NEQ “””” (
        echo Trying to retract Solution %%i from the site…
        echo.
        “”%SPDIR%\bin\stsadm.exe”” -o retractsolution -name “”%%i”” -url %PortalUrl% -immediate > nul
        if !ERRORLEVEL! == 0 (
            SET FOUNDITEM=true
        ) else (
            if !ERRORLEVEL! == -1 (
                echo Trying to retract Solution %%i globally…
                echo.
                “”%SPDIR%\bin\stsadm.exe”” -o retractsolution -name “”%%i”” -immediate > nul
                if !ERRORLEVEL! == 0 SET FOUNDITEM=true
            )
        )
        echo.
    )
)
if “”%FOUNDITEM%”” EQU “”true”” (
    echo ____________________________________________________________________________
    echo.
    echo Please wait for the solutions to be retracted.
    “”%SPDIR%\bin\stsadm.exe”” -o execadmsvcjobs > nul
    echo Done retracting solution.
)
echo.
for /F “”tokens=1* delims=,”” %%i in (%Names_CAB%) do (
    if “”%%i”” NEQ “””” (
        echo Deleting Solution %%i
        “”%SPDIR%\bin\stsadm.exe”” -o deletesolution -name “”%%i”” -override
 if !ERRORLEVEL! == 0 SET FOUNDITEM=true
        echo.
    )
)
cls
echo Installing…
echo.
echo                    Adding and Deploying Solutions
echo.
echo                (There should be no errors from now on)
echo ____________________________________________________________________________
echo.
SET FOUNDITEM=false
for /F “”tokens=1* delims=,”” %%i in (%Names_CAB%) do (
    if “”%%i”” NEQ “””” (
        echo Adding Solution %%i
        “”%SPDIR%\bin\stsadm.exe”” -o addsolution -filename “”%%i””
        if !ERRORLEVEL! == -1 (
            echo ending the install.
            echo.
            echo ____________________________________________________________________________
            echo.
            echo This error is often one of two problems:
            echo.
            echo If the %%i solution didn’t retract completely, you can
            echo manually retract and delete the solution, and re-start the install.
            echo.
            echo Or, it may be with the with the solution manifest.
            echo You should contact development for a %%i solution file that
            ECHO installs properly.
            echo.
            goto end
        )
 if NOT !ERRORLEVEL! == 0 (
            echo ending the install.
            echo.
            echo ____________________________________________________________________________
            echo.
            echo The solution is not complete!
            echo.
            echo “”%%i”” is included in the “”%Names_CAB%”” file, and is not on
            echo the file system.  This may be a file copy issue or a development issue.
            echo.
            echo After it’s resolved, re-start the install.
            goto end
        )
        echo.
        if /i “”%%j”” EQU “”allowgacdeployment”” (
            echo.
            echo Trying to deploy %%i to %PortalUrl%…
            echo.
            “”%SPDIR%\bin\stsadm.exe”” -o deploysolution -immediate -name “”%%i”” -url %PortalUrl% -allowgacdeployment -force > nul
            if NOT !ERRORLEVEL! == 0 (
                echo.
                echo Trying to deploy %%i globally…
                echo.
                “”%SPDIR%\bin\stsadm.exe”” -o deploysolution -immediate -name “”%%i”” -allowgacdeployment -force > nul
            )
        ) else (
            echo.
            echo Trying to deploy %%i to %PortalUrl%…
            echo.
            “”%SPDIR%\bin\stsadm.exe”” -o deploysolution -immediate -name “”%%i”” -url %PortalUrl% -force > nul
            if NOT !ERRORLEVEL! == 0 (
                echo.
                echo Trying to deploy %%i globally…
                echo.
                “”%SPDIR%\bin\stsadm.exe”” -o deploysolution -immediate -name “”%%i”” -force > nul
            )
        )
        if NOT !ERRORLEVEL! == 0 (
            echo ending the install.
            echo.
            echo ____________________________________________________________________________
            echo.
            echo Please contact development for a fix to “”%%i””
            echo.
            goto end
        )
        echo Successful Deployment
        echo.
        SET FOUNDITEM=true
    )
)
if not EXIST %Names_Features% goto InstallComplete
if “”%FOUNDITEM%”” NEQ “”true”” (
    echo There are no solutions in %Names_CAB% to deploy!
    goto activate
)

echo ____________________________________________________________________________
echo.
echo Please wait for the solution(s) to be deployed. 
echo.
“”%SPDIR%\bin\stsadm.exe”” -o execadmsvcjobs > nul
echo.
echo Continue activating the features
pause
:activate
SET FOUNDITEM=false
echo.
echo ____________________________________________________________________________
echo.
echo                          Activating Features
echo.
echo ____________________________________________________________________________
echo.
for /F “”tokens=1* delims=,”” %%i in (%Names_Features%) do (
    if “”%%i”” NEQ “””” (
     echo Installing Feature %%i
     “”%SPDIR%\bin\stsadm.exe”” -o installfeature -name “”%%i”” -force
        echo Activating Feature %%i
        if “”%%j”” NEQ “””” (
            “”%SPDIR%\bin\stsadm.exe”” -o activatefeature -name “”%%i”” -url %PortalUrl%/%%j
        ) else (
            “”%SPDIR%\bin\stsadm.exe”” -o activatefeature -name “”%%i”” -url %PortalUrl%
        )
        if %ERRORLEVEL% == -1 (
            echo.
            echo This feature likely doesn’t exist in any cab files as per %Names_Features%
            echo You can edit %Names_Features% to remove %%i
            echo and / or contact development to resolve the issue.
            goto end
        )
        echo.
        SET FOUNDITEM=true
    )
)
if “”%FOUNDITEM%”” NEQ “”true”” (
    echo There are no features in %Names_Features% to activate.
)
:InstallComplete
echo.
echo.
echo ____________________________________________________________________________
echo.
echo                          Install complete!
echo ____________________________________________________________________________
echo.
:end
echo.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s