Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Gilles Peskine | dea4c7e | 2023-09-08 16:34:01 +0200 | [diff] [blame^] | 2 | |
| 3 | # Prepare .gitignore for a release. |
| 4 | |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 5 | # 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 Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 19 | |
| 20 | set -eu |
| 21 | |
| 22 | print_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 | |
| 30 | if [[ $# -eq 0 ]]; then |
| 31 | print_usage |
| 32 | exit 1 |
| 33 | elif [[ $# -ge 2 ]]; then |
| 34 | echo "Too many arguments!" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | case "$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 |
| 53 | esac |
| 54 | |
| 55 | GITIGNORES=$(find . -name ".gitignore") |
| 56 | for GITIGNORE in $GITIGNORES; do |
Agathiyan Bragadeesh | b8bd604 | 2023-08-04 14:14:11 +0100 | [diff] [blame] | 57 | if $IGNORE; then |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 58 | 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 |
| 66 | done |