blob: 6e6a1b77992448a17e1cb1790f6cc586f8c3398e [file] [log] [blame]
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +01001#!/bin/bash
Gilles Peskinedea4c7e2023-09-08 16:34:01 +02002
3# Prepare .gitignore for a release.
4
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +01005# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010019
20set -eu
21
22print_usage()
23{
24 echo "Usage: $0"
25 echo -e " -h|--help\t\tPrint this help."
26 echo -e " -i|--ignore\t\tAdd generated files to the gitignores."
27 echo -e " -u|--unignore\t\tRemove generated files from the gitignores."
28}
29
30if [[ $# -eq 0 ]]; then
31 print_usage
32 exit 1
33elif [[ $# -ge 2 ]]; then
34 echo "Too many arguments!"
35 exit 1
36fi
37
38case "$1" in
39 -i | --ignore)
40 IGNORE=true
41 ;;
42 -u | --uignore)
43 IGNORE=false
44 ;;
45 -h | --help | "")
46 print_usage
47 exit 1
48 ;;
49 *)
50 echo "Unknown argument: $1"
51 echo "run '$0 --help' for options"
52 exit 1
53esac
54
55GITIGNORES=$(find . -name ".gitignore")
56for GITIGNORE in $GITIGNORES; do
Agathiyan Bragadeeshb8bd6042023-08-04 14:14:11 +010057 if $IGNORE; then
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010058 sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^# //' $GITIGNORE
59 sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE
60 sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE
61 else
62 sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/# /' $GITIGNORE
63 sed -i 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' $GITIGNORE
64 sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE
65 fi
66done