Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Last active April 13, 2020 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattkenefick/60b1505ceed36e789b6337eecddc0aed to your computer and use it in GitHub Desktop.
Save mattkenefick/60b1505ceed36e789b6337eecddc0aed to your computer and use it in GitHub Desktop.
Setup HackerNews.com in hosts
#!/bin/bash
#
# Auto-install:
#
# curl https://gist.githubusercontent.com/mattkenefick/60b1505ceed36e789b6337eecddc0aed/raw/f086f387f8d751ac70e1fc94d832e54703401edb/hn-install-0.1.sh -O && chmod 0777 hn-install-0.1.sh && sh hn-install-0.1.sh && rm -rf hn-install-0.1.sh
#
#
# Requirements:
# - For both, requires curl
# - For windows, Run as administrator cmd prompt
#
# What it does:
# - Downloads gist script
# - Script checks for host file (win v mac)
# - Script appends Ycombinator IP to hosts file
# - curl fetches hackernews.com to test
# - Script opens hackernews.com in browser
#
IS_WIN=0
# Add to hosts
if [[ -f "C:\windows\system32\drivers\etc\hosts" ]]; then
printf "\n# HackerNews Script\n209.216.230.240 hackernews.com www.hackernews.com\n# End HackerNews Script\n" >> "C:\windows\system32\drivers\etc\hosts"
IS_WIN=1
elif [[ -f "/etc/hosts" ]]; then
sudo printf "\n# HackerNews Script\n209.216.230.240 hackernews.com www.hackernews.com\n# End HackerNews Script\n" >> /etc/hosts
fi
# Test webpage
HTML=$(curl -L -s hackernews.com)
# Test & Output
if [[ "$HTML" == *"Hacker News"* ]]; then
printf "\n\e[32m \xE2\x9C\x94 \e[m Navigating to HackerNews.com \n\n"
if [[ $IS_WIN == 1 ]]; then
explorer "http://hackernews.com"
else
open "http://hackernews.com"
fi
else
printf "\n⚠️ Could not reach YCombinator by HackerNews.com \n\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment