#!/bin/bash
#
# Name:   m2-bootstrap.sh
# Author: g.columbro@sourcesense.com
#
# Description:
# This script is needed *only* in case you *don't* have you don't have alfresco artifacts available in any public repo,
# and you can't connect to Sourcesense public repo. 
# So you can manually downlaod JAR and WAR alfresco artifacts in $BASE_DIR (1st param)
# and have them deployed to $TARGET_REPO (2nd param) and $TARGET_REPO_URL (3rd param)
# by running this script and passing the 5 params in the command line. 4th param indicates the version
# while the 5th one the alfresco distro (labs vs enteprise) we're going to deploy.
#
# Note: 
# This script works for alfresco > 3.0 artifacts. It must be modified for
# earlier versions (as share.war won't be present)
#
# License:
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#    
# http://www.apache.org/licenses/LICENSE-2.0
#    
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Example run:  
#				./m2-bootstrap.sh 
#				/Users/mindthegab/downloads/alfresco/alfresco-labs-war-3a.1032_2 
#				ss-public 
#				scp://repository.sourcesense.com/var/www/demo.sourcesense.com/maven2 
#				3a.1032 
#				labs
#
# Artifacts will be deployed with the following pattern:
#
#  org.alfresco:alfresco[-*]:[jar|war]:[VERSION]:[RELEASE]
#
# To have this fully working you need to have the following alfresco BASE_DIR layout:
#
#   BASE_DIR
#		|____ alfresco.war
#		|____ alfresco
#		|			|__ WEB-INF
#		|					|__ lib
#		|						 |___ alfresco-*.jar
#		|____ share.war
#		|____ share
#		|		|__ WEB-INF
#		|				|__ alfresco-*.jar
#		|
#		|____ amps

# which you can easily obtain downloading an alfresco WAR distribution and unpacking both alfresco.war and share.war in folders with the same name

MAVEN_OPTS="-Xms256m -Xmx512m -XX:PermSize=128m"
export MAVEN_OPTS
# 1st command line param: 
# directory where jar and war dependencies are stored
BASE_DIR=$1
# 2st command line param: 
# target repo id (matches in settings)
TARGET_REPO=$2
# 3rd command line param: 
# target repo url
TARGET_REPO_URL=$3
# 4th command line param: 
# Version 
VERSION=$4
# 5th command line param: 
# Release [labs|enterprise]
RELEASE=$5
# 6th param command line
# The version still used in the Ant alfresco build to point to artifacts (normally the suffix of the alfresco-* jars in alfresco/WEB-INF/lib
ALF_INTERNAL_VERSION=$6

echo "Starting Alfresco JARs uploading to repo ${TARGET_REPO} at ${TARGET_REPO_URL}"

mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-core-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-core -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar  -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-deployment-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-deployment -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-jlan-embed-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-jlan-embed -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-linkvalidation.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-linkvalidation -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-mbeans-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO}  -DgroupId=org.alfresco -DartifactId=alfresco-mbeans -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-remote-api-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-remote-api -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-repository-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-repository -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-web-client-${ALF_INTERNAL_VERSION}.jar   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-web-client -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-webscript-framework-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-webscript-framework -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco/WEB-INF/lib/alfresco-wdr-deployment-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-wdr-deployment -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/share/WEB-INF/lib/alfresco-share-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO}  -DgroupId=org.alfresco -DartifactId=alfresco-share -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/share/WEB-INF/lib/alfresco-web-framework-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-web-framework -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
mvn deploy:deploy-file -Dfile=${BASE_DIR}/share/WEB-INF/lib/alfresco-web-framework-commons-${ALF_INTERNAL_VERSION}.jar  -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-web-framework-commons -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/jars/aggadget.jar   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=aggadget -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco-bm.jar   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-bm -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/jars/alfresco-web-service-client.jar   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-web-service-client -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=jar -Dclassifier=${RELEASE}

echo "Starting Alfresco AMPs uploading to repo ${TARGET_REPO} at ${TARGET_REPO_URL}"

#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/alfresco-fb-doclib.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-fb-doclib -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/alfresco-recordsmanagement.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-recordsmanagement -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/alfresco-truncateMalformedXml.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=alfresco-truncateMalformedXml -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/phpIntegration.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=phpIntegration -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/TabbedPropertySheet.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=TabbedPropertySheet -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/amps/vti-module.amp   -DrepositoryId=${TARGET_REPO} -DgroupId=org.alfresco -DartifactId=vti-module -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=amp -Dclassifier=${RELEASE}
echo "Starting Alfresco WARs uploading to repo ${TARGET_REPO} at ${TARGET_REPO_URL}"

mvn deploy:deploy-file -Dfile=${BASE_DIR}/alfresco.war  -DrepositoryId=${TARGET_REPO}  -DgroupId=org.alfresco -DartifactId=alfresco -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=war -Dclassifier=${RELEASE} 
mvn deploy:deploy-file -Dfile=${BASE_DIR}/share.war  -DrepositoryId=${TARGET_REPO}  -DgroupId=org.alfresco -DartifactId=share -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=war -Dclassifier=${RELEASE}
#mvn deploy:deploy-file -Dfile=${BASE_DIR}/ROOT.war  -DrepositoryId=${TARGET_REPO}  -DgroupId=org.alfresco -DartifactId=sharepoint-webapp -Dversion=${VERSION} -Durl=${TARGET_REPO_URL} -Dpackaging=war -Dclassifier=${RELEASE}
echo "Artifacts uploaded successfully!"

