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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
path = frontend
url = https://github.com/CSSS/csss-site-frontend
branch = build
[submodule "events"]
path = events
url = https://github.com/CSSS/csss-site-events
11 changes: 6 additions & 5 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# make sure user is root
user=$(whoami)
if [ $user != 'root' ]; then
echo "this script must be run as the superuser."
exit 1
echo "this script must be run as the superuser."
exit 1
fi

cd /home/csss-site/csss-site-config
if [ $? -ne 0 ]; then
echo "couldn't enter directory /home/csss-site/csss-site-config."
echo "stopping here."
exit 1
echo "couldn't enter directory /home/csss-site/csss-site-config."
echo "stopping here."
exit 1
fi

echo "----"
Expand All @@ -26,6 +26,7 @@ rm -Rf /var/www/html/*
echo "----"
echo "copying from csss-site-frontend to /var/www/html..."
cp -Rf ./frontend/* /var/www/html
cp -Rf ./events/* /var/www/html

echo "----"
echo "all done!"
52 changes: 34 additions & 18 deletions deploy_frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This is for updating both the `build` and `test` folders.
# This will update the `csss-site-repo` based on what flag you use.
# This will not update the `backend` submodule.

# This will update both the `frontend` and `events` submodules.
BASE_WWW="/var/www" # Where the hosted files live
BACKUP_DIR="/tmp/backup" # Backup of the currently hosted files
GIT_USER="csss-site" # The Linux user that controls the git repo on the deployment VM
Expand Down Expand Up @@ -48,7 +48,7 @@ while [[ $# -gt 0 ]]; do
break
;;
*)
echo "Unknown option $($1). Use $($0) -h/--help for usage."
echo "Unknown option $1. Use $0 -h/--help for usage."
exit 1
;;
esac
Expand Down Expand Up @@ -93,32 +93,40 @@ sudo -u $GIT_USER bash <<EOF
echo "Running commands as \$(whoami)..."
echo "Checking current branch"
current_branch=\$(git branch --show-current)
if [ ${branch} != \$current_branch ]; then
if [ "${branch}" != "\$current_branch" ]; then
echo -n "Switching to ${branch}..."
git switch ${branch}
if [ $? -ne 0 ]; then
if [ \$? -ne 0 ]; then
echo -e "\rSwitching to ${branch}...FAILED"
echo "Failed to check out ${branch}."
exit 1
fi
echo -e "\Switching to ${branch}...SUCCESS"
echo -e "\rSwitching to ${branch}...SUCCESS"
fi
echo -ne "Updating csss-site-config..."
git pull origin ${branch}
if [ $? -ne 0 ]; then
if [ \$? -ne 0 ]; then
echo -e "Updating csss-site-config...FAILED"
echo "Failed to pull from ${branch}."
exit 1
fi
echo -e "Updating csss-site-config...SUCCESS"
echo -ne "Updating frontend submodule..."
git submodule update frontend
if [ $? -ne 0 ]; then
if [ \$? -ne 0 ]; then
echo -e "Updating frontend submodule...FAILED"
echo "Failed to update frontend submodule."
exit 1
fi
echo -e "Updating frontend submodule...SUCCESS"
echo -ne "Updating events submodule..."
git submodule update events
if [ \$? -ne 0 ]; then
echo -e "Updating events submodule...FAILED"
echo "Failed to update events submodule."
exit 1
fi
echo -e "Updating events submodule...SUCCESS"
echo "Returning to master branch"
git switch master
EOF
Expand All @@ -133,32 +141,39 @@ echo ""
echo "Replacing deployed files..."
echo "Running commands as $(whoami)..."
echo -ne "Backing up ${target}..."
cp -r ${target} ${BACKUP_DIR}
if [ ! -d "$BACKUP_DIR" ]; then
rm -rf ${BACKUP_DIR} # remove old backup if it exists
if ! cp -r ${target} ${BACKUP_DIR}; then
echo -e "\rBacking up ${target}...FAILED"
echo "Stopping here."
exit 1
fi
echo -e "\rBacking up ${target}...SUCCESS"

echo "Removing current files..."
rm -rf ${target}/*
echo -ne "Copying updated files..."
cp -rf ./frontend/* ${target}
if [ ! -d "$target" ]; then
echo -e "\rCopying updated files...FAILED"
echo -ne "Copying frontend files..."
if ! cp -rf ./frontend/* ${target}; then
echo -e "\rCopying frontend files...FAILED"
echo "Moving backup files."
mv ${BACKUP_DIR} ${target}
rm -rf ${target}/*
cp -rf ${BACKUP_DIR}/* ${target}
echo "Stopping here."
exit 1
fi
echo -e "\rCopying updated files...SUCCESS"
echo -e "\rCopying frontend files...SUCCESS"

echo -ne "Copying event sites and creating symlinks..."
EVENTS=("tech-fair" "fall-hacks" "madness" "frosh")
echo "Creating symlinks to the latest year"
for event in "${EVENTS[@]}"; do
event_dir="${target}/${event}"

if ! cp -rf ./events/* ${target}; then
echo -e "\rCopying ${event}...FAILED"
echo "Moving backup files."
rm -rf ${target}/*
cp -rf ${BACKUP_DIR}/* ${target}
echo "Stopping here."
exit 1
fi

if [ ! -d "$event_dir" ]; then
echo "${event_dir} does not exist."
continue
Expand All @@ -174,6 +189,7 @@ for event in "${EVENTS[@]}"; do
ln -sfn "$latest_year" "${event_dir}/latest"
echo "Updated latest symlink in ${event_dir} -> ${latest_year}"
done
echo -e "\rCopying event sites and creating symlinks...SUCCESS"

echo "Cleaning up backup files..."
rm -rf ${BACKUP_DIR}
Expand Down
1 change: 1 addition & 0 deletions events
Submodule events added at 86a04f