#!/bin/bash # # Author: Yanis Guenane # # Licensed 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. # # This script has for objective to automate the generation of a basic puppet # module that would be compliant with PuppetOpenstack standard. # It handles both part the cookiecutter file generation and the modulesync # common file synchronization # # Requirements: # # * git (package) # * git-review (package or pip) # * cookiecutter (package or pip) # * modulesync (gem) # * digest (gem) set -e proj=$1 user=$2 testing=${OS_NEW_MODULE_TEST:+yes} cookiecutter_url=https://opendev.org/openstack/puppet-openstack-cookiecutter if [ -z "$proj" ] || [ -z "$user" ] ; then echo "usage: $0 project-name gerrit-user-id" exit 1 fi check_gerrit_user() { if [[ -z $(git config --global user.name) ]]; then echo "WARNING: Git commiter name is not set, setting it locally..." git config --local user.name "Puppet OpenStack Cookiecutter" fi if [[ -z $(git config --global user.email) ]]; then echo "WARNING: Git commiter email is not set, setting it locally..." git config --local user.email "puppet-openstack-cookiecutter@example.com" fi } cleanup_gerrit_user() { if [[ -n $(git config --local user.name) || -n $(git config --local user.email) ]]; then echo " WARNING: We configured a temporary user/email for the initial commit. You will need to reset this information prior to running git review. Please configure your name and email in the git config and update the previous commit with your author information. git config --global user.name "Your Name" git config --global user.email "your@email" cd `pwd` git commit --amend --author='Your Name '" git config --local --unset user.name git config --local --unset user.email fi } if [ -z "${testing}" ]; then tmp_var="/tmp/puppet-${proj}" else tmp_var="${PWD}/puppet-${proj}" cookiecutter_conf="${PWD}/default-config.yaml" set +e which pip3 2>&1 ret=$? set -e if [ $ret -eq 0 ]; then pip_bin=pip3 else pip_bin=pip fi sudo $pip_bin install cookiecutter==1.7.0 cat > "${cookiecutter_conf}" < managed_modules.yml < modulesync.yml <