-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaltium-mk-snapshot
executable file
·55 lines (44 loc) · 1.47 KB
/
altium-mk-snapshot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
## Create new revision from existing revision
## Usage: Run mk-snapshot from within project folder
## Variables
REVNAME="rev-"
## Get last revision and calculate new
LAST_DES=$(ls | grep rev | tail -1 | sed -n "s/$REVNAME//p;")
NEW_DES=$(echo $LAST_DES | tr 'a-y' 'b-z' | tr -d '0-9')
if [ -z $NEW_DES ]
then
NEW_DES=a
fi
## Use last revision to create snapshot.
## The -i and /i switches of grep and sed make them case insensitive.
LAST_PATH="${REVNAME}${LAST_DES}"
PRJNAME=$(ls "$LAST_PATH" | grep -o -m 1 "[A-Za-z0-9].*\.PrjPcb" | sed -n "s/-${LAST_DES}.PrjPcb//p")
NEW_PATH="${REVNAME}${NEW_DES}"
echo Creating "${PRJNAME} / ${NEW_PATH} from ${LAST_PATH} ..."
mkdir "$NEW_PATH"
## Copy project files that need renaming
for i in 'PrjPcb' 'PrjPcbStructure' 'PrjPcbVariants'
do
checkfile=$(ls "$LAST_PATH" | grep "$i")
if [ -n "$checkfile" ]
then
cp "$LAST_PATH"/*."$i" ./"$NEW_PATH"/"$PRJNAME"-"$NEW_DES"."$i"
fi
done
## Copy schematics, PCBs, ... that keep their names
for i in 'PcbDoc' 'SchDoc' 'BomDoc' 'Harness' 'OutJob' 'txt'
do
checkfile=$(ls "$LAST_PATH" | grep "$i")
if [ -n "$checkfile" ]
then
cp "$LAST_PATH"/*."$i" ./"$NEW_PATH"
fi
done
## Edit Rev parameter of new project file
sed -i "/Name=Rev/,/Value=${LAST_DES}/{s//Name=Rev\r\nValue=${NEW_DES}/}" ./"${NEW_PATH}/${PRJNAME}-${NEW_DES}.PrjPcb"
## Set write access to all files
chmod -R +w "$NEW_PATH"
## Clean up old outputs and history
rm -rf "$LAST_PATH/Outputs" "$LAST_PATH/History"
echo Done.