Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
pull_request:
push:
schedule:
- cron: '21 5 * * *'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# - name: Configure SSH
# env:
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
# SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
# SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
# run: bin/config-ssh 'ed25519'

- name: Run the web filtering script
run: bash main.sh
50 changes: 50 additions & 0 deletions bin/config-ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# NOTE: set -o pipefail is needed to ensure that any error or failure causes the whole pipeline to fail.
# Without this specification, the CI status will provide a false sense of security by showing builds
# as succeeding in spite of errors or failures.
set -eo pipefail

bin/definitions

SSH_FILENAME="$1"
PATH_SSH_PRIVATE_KEY="$HOME/.ssh/id_$SSH_FILENAME"
PATH_SSH_PUBLIC_KEY="$PATH_SSH_PRIVATE_KEY.pub"
PATH_SSH_KNOWN_HOSTS="$HOME/.ssh/known_hosts"

echo '-----------------------------------'
echo 'Configuring SSH For GitHub Workflow'
mkdir -p "$HOME/.ssh"
echo "$SSH_PRIVATE_KEY" > "$PATH_SSH_PRIVATE_KEY"
echo "$SSH_PUBLIC_KEY" > "$PATH_SSH_PUBLIC_KEY"
echo "$SSH_KNOWN_HOSTS" > "$PATH_SSH_KNOWN_HOSTS"

# PERMISSIONS/OWNERSHIP NEEDED
# PATH_SSH_PRIVATE_KEY: -rw------- 1 runner docker
# PATH_SSH_PUBLIC_KEY: -rw-r--r-- 1 runner docker
# PATH_SSH_KNOWN_HOSTS: -rw-r--r-- 1 runner docker

# Set permissions for PATH_SSH_PRIVATE_KEY
sudo chmod a-x "$PATH_SSH_PRIVATE_KEY" # Non-executable for all
sudo chmod a-r "$PATH_SSH_PRIVATE_KEY" # Non-readable for all
sudo chmod a-w "$PATH_SSH_PRIVATE_KEY" # Non-writable for all
sudo chmod u+r "$PATH_SSH_PRIVATE_KEY" # Readable for owner
sudo chmod u+w "$PATH_SSH_PRIVATE_KEY" # Writable for owner

# Set permissions for PATH_SSH_PUBLIC_KEY
sudo chmod a-x "$PATH_SSH_PUBLIC_KEY" # Non-executable for all
sudo chmod a+r "$PATH_SSH_PUBLIC_KEY" # Readable for all
sudo chmod a-w "$PATH_SSH_PUBLIC_KEY" # Non-writable for all
sudo chmod u+w "$PATH_SSH_PUBLIC_KEY" # Writable for owner

# Set permissions for PATH_SSH_KNOWN_HOSTS
sudo chmod a-x "$PATH_SSH_KNOWN_HOSTS" # Non-executable for all
sudo chmod a+r "$PATH_SSH_KNOWN_HOSTS" # Readable for all
sudo chmod a-w "$PATH_SSH_KNOWN_HOSTS" # Non-writable for all
sudo chmod u+w "$PATH_SSH_KNOWN_HOSTS" # Writable for owner

echo ''
echo '----------------'
echo "ls -l $HOME/.ssh"
ls -l $HOME/.ssh
echo ''
17 changes: 17 additions & 0 deletions bin/definitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# NOTE: set -o pipefail is needed to ensure that any error or failure causes the whole pipeline to fail.
# Without this specification, the CI status will provide a false sense of security by showing builds
# as succeeding in spite of errors or failures.
set -eo pipefail

# The scripts are called from the main directory of this repository, NOT the bin directory.
DIR_MAIN=$PWD

if [ ! -f "$DIR_MAIN/tmp/timestamp.txt" ]
then
TIME_STAMP=`date -u +%Y-%m%d-%H%M%S`
mkdir -p "$DIR_MAIN/tmp"
echo "$TIME_STAMP" > "$DIR_MAIN/tmp/timestamp.txt"
fi
TIME_STAMP=`cat tmp/timestamp.txt`
30 changes: 17 additions & 13 deletions bin/main
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ echo '--------------'
echo "mkdir $DIR_TMP"
mkdir $DIR_TMP

echo '--------------------------------------------------'
echo 'git clone https://github.com/StevenBlack/hosts.git'
echo 'NOTE: This is a LONG download!'
cd $DIR_TMP && git clone https://github.com/StevenBlack/hosts.git
wait

cd $DIR_HOSTS && docker run --pull always --rm -it -v /etc/hosts:/etc/hosts \
ghcr.io/stevenblack/hosts:latest updateHostsFile.py --auto \
--replace --extensions fakenews gambling porn social

echo "The old $FILE_HOSTS file is at $FILE_HOSTS_OLD ."
echo 'If you wish to visit any blocked sites, just comment them out'
echo "in the $FILE_HOSTS file."
echo '---------------------------------------------------------------------'
echo 'git clone https://github.com/rubyonracetracks/repo-manager-sample-app'
git clone https://github.com/rubyonracetracks/repo-manager-sample-app

# echo '----------------------------------------------'
# echo 'git clone https://github.com/StevenBlack/hosts'
# echo 'NOTE: This is a LONG download!'
# cd $DIR_TMP && git clone https://github.com/StevenBlack/hosts
# wait

# cd $DIR_HOSTS && docker run --pull always --rm -it -v /etc/hosts:/etc/hosts \
# ghcr.io/stevenblack/hosts:latest updateHostsFile.py --auto \
# --replace --extensions fakenews gambling porn social

# echo "The old $FILE_HOSTS file is at $FILE_HOSTS_OLD ."
# echo 'If you wish to visit any blocked sites, just comment them out'
# echo "in the $FILE_HOSTS file."
86 changes: 86 additions & 0 deletions setup-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# NOTE: set -o pipefail is needed to ensure that any error or failure causes the whole pipeline to fail.
# Without this specification, the CI status will provide a false sense of security by showing builds
# as succeeding in spite of errors or failures.
set -eo pipefail

echo ''
echo 'It is time to up SSH key files.'
echo 'This allows GitHub Workflows to use the git clone command to'
echo 'download an existing repository.'
echo ''
echo 'If you have already done this, then press Ctrl-Break to stop now.'
echo 'To continue, press Enter.'
read
echo ''

source bin/definitions

TYPE='ed25519'
FILENAME="id_$TYPE"
PATHNAME_SSH="$HOME/.ssh"
PATHNAME_SSH_OLD="$HOME/.ssh-old-$TIME_STAMP"
PATHNAME_SSH_NEW="$HOME/.ssh-$TIME_STAMP"
PATHNAME_PRIVATE="$PATHNAME_SSH/$FILENAME"
PATHNAME_PUBLIC="$PATHNAME_PRIVATE.pub"
PATHNAME_KNOWN_HOSTS="$PATHNAME_SSH/known_hosts"

echo "STEP 4: saving the old SSH key files in $PATHNAME_SSH_OLD (if applicable)"
if [ -d "$PATHNAME_SSH" ]; then
mv $PATHNAME_SSH $PATHNAME_SSH_OLD
fi

# Use default path name for SSH key files.
# Use no password for the SSH key files.
# Piping in the newline character means automatically pressing enter.
echo 'STEP 5: generating the SSH key'
ssh-keygen -t "$TYPE" -N '' -f "$PATHNAME_PRIVATE" -C 'jhsu802701@jasonhsu.com' <<<$'\n'

wait
echo '------------'
echo 'ssh-agent -s'
eval "$(ssh-agent -s)"
echo ''
wait

echo 'STEP 6: adding the SSH private key to the ssh-agent'
ssh-add ~/.ssh/id_$TYPE
echo ''

# Necessary to establish the authenticity of the host and skip another prompt
echo 'STEP 7: ssh-keyscan'
ssh-keyscan -H github.com >> ~/.ssh/known_hosts

echo "STEP 8: Saving the new ssh keys in $PATHNAME_SSH_NEW"
cp -r $PATHNAME_SSH $PATHNAME_SSH_NEW

echo 'STEP 9: Go to https://github.com/settings/keys .'
echo "Copy the contents of $PATHNAME_PUBLIC to SSH Public Keys and"
echo 'click on "Save".'
echo 'Press Enter when finished.'
read
echo ''
echo 'STEP 10: Go to this repository on GitHub.'
echo 'Click on Settings -> Security -> Secrets and Variables -> Actions'
echo 'Add the repository secret SSH_PUBLIC_KEY (if it is not already present)'
echo 'or replace the value (if it is already present).'
echo "Copy and paste the contents of $PATHNAME_PUBLIC"
echo 'into the value of this repository secret.'
echo "Click on 'Add secret' or 'Update secret' button, whichever is applicable."
echo 'Press Enter when finished.'
read
echo ''
echo 'STEP 11: Repeat the above procedure, but paste the contents of'
echo "$PATHNAME_PRIVATE into the repository secret SSH_PRIVATE_KEY."
echo 'Press Enter when finished.'
read
echo ''
echo 'STEP 12: Repeat the above procedure, but paste the contents of'
echo "$PATHNAME_KNOWN_HOSTS into the repository secret SSH_KNOWN_HOSTS."
echo 'Press Enter when finished.'
read
echo ''
echo 'Congratulations! GitHub Workflows should now be able to automatically'
echo 'push changes to a repository.'
echo ''