-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathbuild-secure-wrapper.sh
64 lines (49 loc) · 1.99 KB
/
build-secure-wrapper.sh
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
56
57
58
59
60
61
62
63
64
# if you're curious about what this does and why it's here,
# see packages/insomnia/src/cpp/README.md
set -e
BUILD_CONTEXT=$1
VERSION=$(jq .version ./packages/insomnia/package.json -rj)
echo "Starting Insomnia secure wrapper build for version $VERSION..."
MAJOR=$(echo $VERSION | cut -d '.' -f 1)
MINOR=$(echo $VERSION | cut -d '.' -f 2)
PATCH=$(echo $VERSION | cut -d '.' -f 3 | cut -d '-' -f 1)
TAG=$(echo $VERSION | cut -d '-' -f 2)
SRC_DIR=packages/insomnia/src
CPP_DIR=$SRC_DIR/cpp
DEST_DIR=packages/insomnia/dist/win-unpacked
DEST_EXE=$DEST_DIR/Insomnia.exe
# use this if you just want to rebuild the wrapper so you can copy into the installation folder
if [ "$BUILD_CONTEXT" == "SOLO" ]; then
DEST_EXE=$CPP_DIR/Insomnia.exe
fi
if [ -n "$TAG" ]; then
TAG="-$TAG"
fi
# if an arg is not passed (SOLO, CI), rebuild the unpacked app
if [ ! $BUILD_CONTEXT ]; then
echo "Building Insomnia electron application..."
npm run package:windows:unpacked -w insomnia
fi
cp $DEST_DIR/Insomnia.exe $DEST_DIR/insomnia.dll
cp $SRC_DIR/icons/icon.ico $CPP_DIR/insomnia.ico
echo "Injecting version strings..."
sed "s/__VERSION__/$VERSION/g" $CPP_DIR/insomnia.cpp > $CPP_DIR/final.cpp
sed "s/__MAJOR__/$MAJOR/g" $CPP_DIR/resources.rc > $CPP_DIR/final.rc
sed -i "s/__MINOR__/$MINOR/g" $CPP_DIR/final.rc
sed -i "s/__PATCH__/$PATCH/g" $CPP_DIR/final.rc
sed -i "s/__TAG__/$TAG/g" $CPP_DIR/final.rc
sed -i "s/__YEAR__/$(date +%Y)/g" $CPP_DIR/final.rc
echo "Compiling resources..."
windres $CPP_DIR/final.rc $CPP_DIR/res.o
echo "Compiling Insomnia..."
g++ -lkernel32 -mwindows -c $CPP_DIR/final.cpp -o $CPP_DIR/insomnia.o
echo "Linking Insomnia..."
g++ -O2 -static -static-libgcc -static-libstdc++ -mwindows -lwinpthread $CPP_DIR/insomnia.o $CPP_DIR/res.o -o $DEST_EXE
echo "Secure wapper built successfully."
if [ ! $BUILD_CONTEXT ]; then
echo "Packaging distributables..."
npm run package:windows:dist -w insomnia
echo "Resetting to prevent accidental loops..."
mv $DEST_DIR/insomnia.dll $DEST_DIR/Insomnia.exe
fi
echo "Done."