Skip to content

Commit 244c611

Browse files
authored
Merge pull request #6 from faysal-ishtiaq/master
add linux support
2 parents 15f4336 + 07d7aff commit 244c611

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

cli/create-cert.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ BLUE='\033[0;34m'
88
YELLOW='\033[0;93m'
99
NC='\033[0m'
1010

11+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
12+
OPENSSL_CNF_PATH=/etc/ssl/openssl.cnf
13+
fi
14+
15+
if [[ "$OSTYPE" == "darwin"* ]]; then
16+
OPENSSL_CNF_PATH=/System/Library/OpenSSL/openssl.cnf
17+
fi
18+
1119
openssl req \
1220
-newkey rsa:2048 \
1321
-x509 \
@@ -18,7 +26,7 @@ openssl req \
1826
-subj /CN=myapp.local \
1927
-reqexts SAN \
2028
-extensions SAN \
21-
-config <(cat /System/Library/OpenSSL/openssl.cnf \
29+
-config <(cat $OPENSSL_CNF_PATH \
2230
<(printf '[SAN]\nsubjectAltName=DNS:myapp.local')) \
2331
-sha256 \
2432
-days 3650
@@ -28,4 +36,4 @@ mkdir -p ../certs
2836
mv *.crt ../certs/
2937
mv *.key ../certs/
3038

31-
echo -e ${GREEN}"Cert created in /cert! ${NC}";
39+
echo -e ${GREEN}"Cert created in /cert! ${NC}"

cli/setup-hosts-file.sh

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,28 @@ if [ ${QUESTION} == "a" ]; then
2222

2323
HOSTS_LINE="$IP\t$HOSTNAME"
2424

25-
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
26-
then
27-
echo -e ${YELLOW}"$HOSTNAME already exists: $(grep $HOSTNAME $ETC_HOSTS) ${NC}"
28-
else
29-
echo -e ${GREEN}"Adding $HOSTNAME to your $ETC_HOSTS ${NC}";
30-
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts";
31-
32-
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
33-
then
34-
echo -e ${GREEN}"$HOSTNAME was added succesfully \n $(grep $HOSTNAME /etc/hosts) ${NC}";
35-
else
36-
echo -e ${RED}"Failed to Add $HOSTNAME, Try again! ${NC}";
37-
fi
25+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
26+
echo -e ${YELLOW}"$HOSTNAME already exists: $(grep $HOSTNAME $ETC_HOSTS) ${NC}"
27+
else
28+
echo -e ${GREEN}"Adding $HOSTNAME to your $ETC_HOSTS ${NC}"
29+
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts"
30+
31+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
32+
echo -e ${GREEN}"$HOSTNAME was added succesfully \n $(grep $HOSTNAME /etc/hosts) ${NC}"
33+
else
34+
echo -e ${RED}"Failed to Add $HOSTNAME, Try again! ${NC}"
35+
fi
3836
fi
3937

4038
fi
4139

42-
4340
if [ ${QUESTION} == "r" ]; then
4441

45-
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
46-
then
47-
echo -e ${GREEN}"$HOSTNAME Found in your $ETC_HOSTS, Removing now... ${NC}";
48-
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS
42+
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]; then
43+
echo -e ${GREEN}"$HOSTNAME Found in your $ETC_HOSTS, Removing now... ${NC}"
44+
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS
4945
else
50-
echo -e ${RED}"$HOSTNAME was not found in your $ETC_HOSTS ${NC}";
46+
echo -e ${RED}"$HOSTNAME was not found in your $ETC_HOSTS ${NC}"
5147
fi
5248

5349
fi

cli/trust-cert.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ BLUE='\033[0;34m'
88
YELLOW='\033[0;93m'
99
NC='\033[0m'
1010

11-
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "../certs/myapp.local.crt"
11+
if [[ "$OSTYPE" == "darwin"* ]]; then
12+
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "../certs/myapp.local.crt"
13+
fi
1214

13-
echo -e ${GREEN}"The cert should now be trusted in macOS System Keychain. Trusted in Chrome and Safari. (Not Firefox since it's using its own keychain manager) ${NC}";
15+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
16+
cp ../certs/* /usr/local/share/ca-certificates/
17+
sudo update-ca-certificates
18+
fi
19+
echo -e ${GREEN}"The cert should now be trusted in macOS System Keychain. Trusted in Chrome and Safari. (Not Firefox since it's using its own keychain manager) ${NC}"

0 commit comments

Comments
 (0)