diff --git a/.local/bin/scripts/install_programs.sh b/.local/bin/scripts/install_programs.sh new file mode 100644 index 0000000..559d534 --- /dev/null +++ b/.local/bin/scripts/install_programs.sh @@ -0,0 +1,138 @@ +#!/bin/bash + +install_packages() { + sudo apt update + sudo apt install -y jq git curl tmux +} + +install_mariadb() { + sudo apt install -y default-mysql-client mariadb-server + + # Create a database user for the webserver + sudo mysql -u root -e "CREATE USER 'www-data'@'localhost' IDENTIFIED WITH unix_socket; GRANT ALL PRIVILEGES ON *.* TO 'www-data'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;" + sudo mysql -u root -e "CREATE USER '$(whoami)'@'localhost' IDENTIFIED WITH unix_socket; GRANT ALL PRIVILEGES ON *.* TO '$(whoami)'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;" +} + +install_vegvisir() { + local PATH_TMP="/tmp/tmp-vegvisir" + + # Create a git directory where we will install Vegvisir temporarily + sudo rm -rf $PATH_TMP + mkdir $PATH_TMP + cd $PATH_TMP + git init + + # Download and install Vegvisir + cd $PATH_FW + curl -fsSL https://codeberg.org/vegvisir/install/raw/branch/master/nginx/install.sh | bash -s -- --install=y --overwrite=y --example=n --dir="$PATH_TMP" + + # Move the Vegvisir installation to the frameworks folder + sudo rm -rf /var/www/fw/vegvisir + sudo mv $PATH_TMP/vegvisir /var/www/fw/vegvisir + sudo rm -rf $PATH_TMP +} + +install_reflect() { + local PATH_TMP="/tmp/tmp-reflect" + + # Create a git directory where we will install Reflect temporarily + sudo rm -rf $PATH_TMP + mkdir $PATH_TMP + cd $PATH_TMP + git init + + # Download and install Reflect + cd $PATH_FW + curl -fsSL https://codeberg.org/reflect/install/raw/branch/master/nginx/install.sh | bash -s -- --install=y --overwrite=y --seed=n --dir="$PATH_TMP" --endpoints="api" --host="localhost" --user="www-data" --password="null" --db="reflect" + + # Move the Reflect installation to the frameworks folder + sudo rm -rf /var/www/fw/reflect + sudo mv $PATH_TMP/reflect /var/www/fw + sudo rm -rf $PATH_TMP +} + +install_webserver() { + local WWW_PATH="/var/www" + local PATH_NGINX="/etc/nginx" + + sudo apt install -y nginx composer + + sudo mkdir $WWW_PATH/fw + sudo mkdir $WWW_PATH/libs + sudo mkdir $WWW_PATH/tools + sudo mkdir $WWW_PATH/sites + + sudo rm -r $WWW_PATH/html + sudo rm $PATH_NGINX/sites-enabled/default + + # Download default configs + sudo curl -o $PATH_NGINX/snippets/vlw.se-ssl.conf https://git.vlw.se/config/dev/raw/branch/master/nginx/snippets/vlw.se-ssl.conf + sudo curl -o $PATH_NGINX/snippets/fastcgi-php.conf https://git.vlw.se/config/dev/raw/branch/master/nginx/snippets/fastcgi-php.conf + sudo curl -o $PATH_NGINX/sites-available/8001.conf https://git.vlw.se/config/dev/raw/branch/master/nginx/sites-available/8001.conf + sudo curl -o $PATH_NGINX/sites-available/8002.conf https://git.vlw.se/config/dev/raw/branch/master/nginx/sites-available/8002.conf + sudo curl -o $PATH_NGINX/sites-available/8003.conf https://git.vlw.se/config/dev/raw/branch/master/nginx/sites-available/8003.conf + + sudo rm /etc/nginx/sites-enabled/8001.conf + sudo rm /etc/nginx/sites-enabled/8002.conf + sudo rm /etc/nginx/sites-enabled/8003.conf + sudo ln -s /etc/nginx/sites-available/8001.conf /etc/nginx/sites-enabled + sudo ln -s /etc/nginx/sites-available/8002.conf /etc/nginx/sites-enabled + sudo ln -s /etc/nginx/sites-available/8003.conf /etc/nginx/sites-enabled + + sudo chown $(whoami):www-data -R $WWW_PATH + + sudo systemctl restart nginx +} + +install_pma() { + local VERSION="5.2.3" + local PATH_TOOLS="/var/www/tools" + + curl -L https://files.phpmyadmin.net/phpMyAdmin/$VERSION/phpMyAdmin-$VERSION-english.tar.gz | tar -xz -C /tmp + sudo mv /tmp/phpMyAdmin-$VERSION-english $PATH_TOOLS/pma + sudo chown :www-data -R $PATH_TOOLS/pma + + sudo curl -o $PATH_TOOLS/pma/config.inc.php https://git.vlw.se/config/dev/raw/branch/master/pma/config.inc.php +} + +install_php_fpm() { + local PHP_VERSION="8.4" + local PHP_INI_PATH="/etc/php/$PHP_VERSION/fpm/php.ini" + + # https://packages.sury.org/php/README.txt + sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb + sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb + sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' + + # Install packages + sudo apt update + sudo apt -y install lsb-release ca-certificates php$PHP_VERSION-fpm php$PHP_VERSION-mysql php$PHP_VERSION-xdebug php$PHP_VERSION-mbstring php$PHP_VERSION-intl + + # Make a backup of the php.ini file + sudo cp -p "$PHP_INI_PATH" "$PHP_INI_PATH~" + # Use sed to replace the zend_extension line + sudo sed -i 's/^zend_extension=.*/zend_extension=xdebug/' "$PHP_INI_PATH" + + sudo systemctl restart php$PHP_VERSION-fpm +} + +install_code_server() { + local EXTENSIONS_FILE="$HOME/.local/share/code-server/User/extensions.json" + + # https://coder.com/docs/code-server/install + curl -fsSL https://code-server.dev/install.sh | sh + + # Install extensions + jq -r '.[]' $EXTENSIONS_FILE | while IFS= read -r extension; do + code-server --install-extension $extension + done +} + +install_packages +install_php_fpm +install_webserver +install_vegvisir +install_reflect +install_pma +install_mariadb +install_code_server diff --git a/Makefile b/Makefile index 818743b..dd38dd1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -install: dotfiles git-hooks +install: dotfiles git-hooks programs # Install dotfiles in users home directory dotfiles: @@ -11,3 +11,7 @@ git-hooks: # Export code-server extensions to config directory code-extensions: ~/.local/bin/scripts/code_server_export_extensions.sh + +# Install dev programs and configuration files +programs: + ~/.local/bin/scripts/install_programs.sh