GitRoot

craft your forge, build your project, grow your community freely
 1#!/usr/bin/env bash
 2
 3# SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
 4#
 5# SPDX-License-Identifier: EUPL-1.2
 6
 7function calc_crc16() 
 8{
 9    while read -r -d "" -n 1 ; do astring+=( "$REPLY" ) ; done <<< "$1"
10
11    cnt=${#1}
12    c=65535
13
14    for ((x=0;x<$cnt;x++)); do
15        char=$(printf '%d' \'"${1:$x:1}")
16        e=$(((c ^ char) & 0x00FF))
17        s=$(((e << 4) & 0x00FF))
18        f=$(((e ^ s) & 0x00FF))
19        r1=$(((c >> 8) ^ (f << 8) ^ (f << 3) ^ (f >> 4)))
20        c=$r1
21    done
22    c=$((c ^ 0xffff))
23    printf "%x" $c
24}
25
26crc16=$(calc_crc16 $1)
27filepath=$(echo "issues/$crc16-$1.md")
28
29if [ ! -e $filepath ]
30then 
31    echo "---" > $filepath
32    printf "id: '$crc16'\npriority: 50\nsprint: ''\n---\n\n#Title\n\nDescription" >> $filepath
33    echo "Created: $filepath"
34else
35    echo "Already exist: $filepath"
36    exit 1
37fi
38