Skip to content

Instantly share code, notes, and snippets.

@mahi424
Last active June 11, 2024 23:59
Show Gist options
  • Save mahi424/4d6e088e81f190704955fc2c704fddb7 to your computer and use it in GitHub Desktop.
Save mahi424/4d6e088e81f190704955fc2c704fddb7 to your computer and use it in GitHub Desktop.
function update_sys {
echo 'updating...'
sudo apt update
sudo apt upgrade -y
}
function install_nginx {
echo 'installing nginx'
sudo apt install nginx-full -y
sudo mv /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/default.bak
sudo nginx -s reload
}
function configure_firewall {
echo 'Configuring firewall...'
sudo apt install ufw -y
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable
}
function add_nginx_conf {
site_name=$1
p=$2
c=$3
port="${p:-3000}"
conf_name="${c:-$1.conf}"
path="/etc/nginx/conf.d/$conf_name"
echo $site_name $port $conf_name $path
echo "server {
server_name $site_name www.$site_name;
# server_name video.bizup.app;
location / {
proxy_pass http://127.0.0.1:$port;
}
}" | sudo tee $path
}
function install_certbot {
echo 'install certbot'
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx
}
function install_node {
echo 'installing NodeJs...'
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
source ~/.bashrc
nvm install --lts
echo 'install yarn'
npm i yarn -g
}
function install_pm2 {
echo 'install and configuring pm2'
npm install -g pm2
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 100M
}
function install_git {
echo 'install git'
sudo apt install git
git config --global credential.helper store
}
function clone_repo {
echo 'Cloning Git repository...'
repo_url=$1
repo_name=$(basename $repo_url .git)
if [ -d "$repo_name" ]; then
echo "Repository $repo_name already exists. Skipping cloning."
else
git clone $repo_url
fi
}
function install_dependencies {
echo 'Installing dependencies...'
repo_name=$1
cd $repo_name
yarn install
}
# ensure permissions or do sudo before
function renew_cert {
echo "0 12 * * * /usr/bin/certbot renew --quiet" >> /var/spool/cron/root
}
function install_mysql {
echo 'Installing MySQL...'
sudo apt install mysql-server -y
}
function configure_mysql {
echo 'Configuring MySQL...'
mysql_root_password=$1
sudo mysql <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$mysql_root_password';
EOF
}
# update_sys
# install_node
# install_pm2
# install_git
# install_nginx
# add_nginx_conf
# install_certbot
@mahi424
Copy link
Author

mahi424 commented Apr 14, 2022

It is tested code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment