Skip to content

Instantly share code, notes, and snippets.

@tikenn
Last active April 20, 2020 20:46
Show Gist options
  • Save tikenn/31ca95af67b76dc9f474d6f63950c691 to your computer and use it in GitHub Desktop.
Save tikenn/31ca95af67b76dc9f474d6f63950c691 to your computer and use it in GitHub Desktop.
Renames and nginx site by propagating folder and file changes
CURRENT_NAME=$1
NEW_NAME=$2
if [[ -z "$CURRENT_NAME" ]] || [[ -z "$NEW_NAME" ]]; then
echo "Must provide current name and new name"
exit 1
fi
# nginx files
mv /etc/nginx/sites-available/$CURRENT_NAME /etc/nginx/sites-available/$NEW_NAME
rm /etc/nginx/sites-enabled/$CURRENT_NAME
ln -s /etc/nginx/sites-available/$NEW_NAME /etc/nginx/sites-enabled/$NEW_NAME
sed -ir "s|\(/var/www/\).*;|\1$NEW_NAME;|g" /etc/nginx/sites-available/$NEW_NAME
sed -ir "s|\(server_name \).*;|\1$NEW_NAME;|g" /etc/nginx/sites-available/$NEW_NAME
# html files
[[ -d "/var/www/$CURRENT_NAME" ]] && mv /var/www/$CURRENT_NAME /var/www/$NEW_NAME
[[ -d "/srv/www/$CURRENT_NAME" ]] && mv /srv/www/$CURRENT_NAME /srv/www/$NEW_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment