Skip to content
Snippets Groups Projects
deploy.sh 2.65 KiB
Newer Older
Eric Vidal's avatar
Eric Vidal committed
#!/usr/bin/bash
# Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
# All rights reserved.
# 
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

PROG="${0}"
install=0

reset='\033[0m'
red='\033[1;31m'   
green='\033[1;32m'
yellow='\033[1;33m'
bold='\033[1m'

out() {
	local errno="${1}" color="${2}" msg="${@:3}" 
	printf "${PROG}: ${color}%s${reset}: %s\n" "${errno}" "$msg" >&1
}

out_trace() {
	out "tracing" "${bold}" "${@}"
}

out_success() {
	out "success" "${green}" "${@}"
}

out_warn(){
	out "warning" "${yellow}" "${@}"
}

out_error(){
	out "fatal" "${red}" "${@}"
}

out_usage() {
	out "usage" "${reset}" "${@}"
}

die() {
	out_error "${@}"
	exit 111
}

Eric Vidal's avatar
Eric Vidal committed
extra_pkg=( "openssh" )

out_trace "Install extra packages"
pacman -Sy ${extra_pkg[@]} --noconfirm || die "Unable to install extra packages"
Eric Vidal's avatar
Eric Vidal committed

out_trace "Starts ssh-agent"
eval $(ssh-agent)

out_trace "Configure ssh"
mkdir -p ~/.ssh || die "Unable to create ~/.ssh directory"
echo "${ssh_private_key}"| tr -d '\r' > ~/.ssh/id_rsa
chmod 700 ~/.ssh/id_rsa || die "Unable to change permissions of ~/.ssh/id_rsa"
ssh-add ~/.ssh/id_rsa || die "Unable to add key ~/.ssh/id_rsa"
echo ${ssh_known_host} > ~/.ssh/known_hosts
	
out_trace "Configure git"
git config --global user.name ${GITLAB_USER_NAME}
git config --global user.email ${GITLAB_USER_EMAIL}

out_trace "Cd to /tmp"
cd /tmp

out_trace "Clone git@${CI_SERVER_HOST}:/${CI_PROJECT_PATH}.git"
Eric Vidal's avatar
Eric Vidal committed
git clone git@${CI_SERVER_HOST}:/${CI_PROJECT_PATH}.git || die "Unable to clone git@${CI_SERVER_HOST}:/${CI_PROJECT_PATH}.git"
Eric Vidal's avatar
Eric Vidal committed

out_trace "Cd to ${CI_PROJECT_NAME}"
cd ${CI_PROJECT_NAME}

Eric Vidal's avatar
Eric Vidal committed
out_trace "Checkout to branch ${pkg_target}"
git checkout ${pkg_target} || die "Unable to checkout to ${pkg_target}"

Eric Vidal's avatar
Eric Vidal committed
out_trace "Retrieve pkgver and pkgrel variables from PKGBUILD"
Eric Vidal's avatar
Eric Vidal committed
source trunk/PKGBUILD || die "Unable to source PKGBUILD"
Eric Vidal's avatar
Eric Vidal committed

out_trace "Make directory of version: ${pkgver}-${pkgrel}"
Eric Vidal's avatar
Eric Vidal committed
mkdir -p version/${pkgver}-${pkgrel} || die "Unable to make directory version/${pkgver}-${pkgrel}"
Eric Vidal's avatar
Eric Vidal committed

out_trace "Copy file from trunk to version/${pkgver}-${pkgrel}"
Eric Vidal's avatar
Eric Vidal committed
cp trunk/* version/${pkgver}-${pkgrel} || die "Unable to copy trunk/* to version/${pkgver}-${pkgrel}"
Eric Vidal's avatar
Eric Vidal committed

out_trace "Git add new file"
git add . || die "Unable to git add"

out_trace "Git commit message: upgpkg: ${pkgver}-${pkgrel}"
git commit -m "upgpkg: ${pkgver}-${pkgrel}" || die "Unable to commit"

out_trace "Push the new version"
git push --all || die "Unable to push at git@${CI_SERVER_HOST}:/${CI_PROJECT_PATH}.git"

exit 0