Skip to content

Commit

Permalink
version:1.0.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyamMaity committed Feb 19, 2023
1 parent 9871794 commit c481d30
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.env
*.deb
*.snap
parts/
stage/
snap/
packages/
8 changes: 7 additions & 1 deletion DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Package: shreyam-do
Version: 1.0
Version: 1.0.1
Architecture: all
Maintainer: Shreyam Maity <rey@shreyam.dev>
Description: A package that contains my personal server setup scripts
Homepage: https://shreyam.dev
Source: shreyam-do
Section: misc
Priority: optional
Depends: make
Pre-Depends: make
12 changes: 2 additions & 10 deletions DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

set -e

if [ "$1" = "configure" ]; then
# Check if make is installed
if ! dpkg -s make >/dev/null 2>&1; then
# Install make
apt-get update
apt-get install -y make
fi
chmod +x /usr/bin/shreyam-do

# Run make
make -f /usr/share/shreyam-do/Makefile $2
fi
exit 0
15 changes: 3 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
FROM ubuntu:22.04

RUN apt-get update && \
apt-get clean && \
# apt-get install -y snapcraft dpkg-dev build-essential && \
rm -rf /var/lib/apt/lists/*

WORKDIR /pkg

COPY . .

ARG PACKAGE_NAME
ARG PACKAGE_VERSION
ENV SNAPCRAFT_DISABLE_REMOTE_PARTS=true

RUN chmod 755 /pkg/DEBIAN/postinst
RUN mkdir -p /packages && \
dpkg-deb --build /pkg /packages/${PACKAGE_NAME}_${PACKAGE_VERSION}.deb
# && \
# cd /pkg && \
# snapcraft
dpkg-deb --build /pkg /packages/${PACKAGE_NAME}_${PACKAGE_VERSION}.deb

CMD cp /packages/*.deb /build
# && \
# cp /pkg/*.snap /build
CMD cp /packages/*.deb /build
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
up:
docker-compose --env-file=.env up -d --build
docker-compose --env-file=.env up -d --build
docker-compose down
test:
docker-compose --profile test --env-file=.env up -d --build
version:
@if [ -z "$(word 2, $(MAKECMDGOALS))" ]; then echo "Usage: make version <version>"; exit 1; fi
@if [ ! -f DEBIAN/control ]; then echo "Error: DEBIAN/control does not exist"; exit 1; fi
@echo "Current version: $(grep -oP 'Version: \K.*' DEBIAN/control | cut -d' ' -f1)"
@echo "Setting version $(word 2, $(MAKECMDGOALS))"
@sed -i "s/Version:.*/Version: $(word 2, $(MAKECMDGOALS))/" DEBIAN/control
@echo "New version: $(grep -oP 'Version: \K.*' DEBIAN/control | cut -d' ' -f1)"
@echo "Done"
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
## `TLDR:` This tool is for me and it might not be useful for you. But if you want to use it, you can.


---

### Options
```dotnetcli
shreyam-do - Shreyam's setup scripts
Usage: shreyam-do [options]
Options:
[command] Run a specific setup script
-h, --help Display this help message
-v, --version Display version information
-s, --setup Set up the system with all the required packages
-r, --remove Remove all installed packages
```
---
### How to use

- `shreyam-do -s` - installs all the required packages on a fresh vm and configure with npm, zsh, autosuggestions etc.
- `shreyam-do -r` - removes all the packages installed by the tool
- `shreyam-do -v` - displays the version of the tool
- `shreyam-do -h` - displays the help message and the options available
- `shreyam-do <command>` - runs the specific command

---
### Commands Available

Expand All @@ -24,4 +48,17 @@
- `shreyam-do ssl-nginx <domain>` - generates ssl certificate for the domain from letsencrypt and automatically configures nginx to serve the domain with ssl
- `shreyam-do ssl-cert <domain>` - generates ssl certificate for the domain from letsencrypt and saves it in `/etc/letsencrypt/live/<domain>`
- `shreyam-do open-ports` - opens necessary ports for nginx on firewall
- `shreyam-do symLink <conf-file>` - creates a symlink of the conf file in nginx
- `shreyam-do symLink <conf-file>` - creates a symlink of the conf file in nginx

---
### How to contribute
- Create an issue if you find any bug or want to suggest a feature
- Fork the repo and create a PR if you want to contribute

---
### License
#### Apache License 2.0
---
### Author
#### [Shreyam Maity](https://shreyam.dev)
---
27 changes: 26 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
version: "3"
services:
build:
shreyam-do:
build:
context: .
args:
PACKAGE_NAME: ${PACKAGE_NAME:-shreyam-do}
PACKAGE_VERSION: ${VERSION:-1.0.0}
volumes:
- ./build:/build
tests:
image: ubuntu:22.04
volumes:
- ./build:/build
environment:
- LC_ALL=C.UTF-8
- LANG=C.UTF-8
- PACKAGE_NAME=${PACKAGE_NAME:-shreyam-do}
- VERSION=${VERSION:-1.0.0}
working_dir: /tmp
depends_on:
- shreyam-do
profiles:
- test
command: sh -c '
set -e;
apt-get update;
apt-get install -y make;
cd /build;
ls -l;
dpkg -i /build/${PACKAGE_NAME}_${VERSION}.deb;
shreyam-do -v;
shreyam-do -h;
shreyam-do test;
shreyam-do'
6 changes: 6 additions & 0 deletions serve/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ PACKAGE_VERSION=${TAG#"v"}
# Download the package
curl -sSLO "https://github.com/${GITHUB_USERNAME}/${GITHUB_REPO}/releases/download/${TAG}/${PACKAGE_NAME}_${PACKAGE_VERSION}.deb"

# Install dependencies
if ! dpkg-query -W -f='${Status}' make 2>/dev/null | grep -c "ok installed" >/dev/null; then
sudo apt-get -y update && sudo apt-get -y install make
fi


# Install the package
sudo dpkg -i ${PACKAGE_NAME}_${PACKAGE_VERSION}.deb

Expand Down
6 changes: 1 addition & 5 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ parts:
stage-packages:
- make
make:
plugin: nil
plugin: autotools
source: https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
source-type: tar
build-packages:
- gettext
override-build: |
./configure
make
make install
66 changes: 65 additions & 1 deletion usr/bin/shreyam-do
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
#!/bin/bash

make -f /usr/share/shreyam-do/Makefile "$@"
set -e

function print_usage {
make -s -f /usr/share/shreyam-do/Makefile help
}

function print_version {
echo "shreyam-do version 1.0.1"
}

function setup_all {
echo "Setting up all packages"
sudo apt-get update
sudo apt-get install -y git
sudo apt-get install -y vim
sudo apt-get install -y curl
sudo apt-get install -y zsh
sudo apt-get install -y tmux
sudo apt-get install -y npm
chsh -s $(which zsh)
which $SHELL
/usr/bin/zsh
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
echo "Setup complete"
}

if [ $# -eq 0 ]; then
print_usage
exit 1
fi

while [[ $# -gt 0 ]]; do
key="$1"

case $key in
-h | --help)
print_usage
exit 0
;;
-v | --version)
print_version
exit 0
;;
-s | --setup)
setup_all
exit 0
;;
-r | --remove)
echo "Removing all installed packages"
sudo apt-get remove -y tmux
sudo apt-get remove -y npm
exit 0
;;
*)
# if the argument doesn't match any flag, execute the make command
make -s -f /usr/share/shreyam-do/Makefile "$@"
exit 0
;;
esac
shift
done

print_usage
exit 1
43 changes: 39 additions & 4 deletions usr/share/shreyam-do/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#setts up system env for docker
.DEFAULT_GOAL := help

.PHONY: help

help:
@#Help: prints this help message
@echo "shreyam-do - Shreyam's setup scripts"
@echo "Usage: shreyam-do [options]"
@echo "Options:"
@echo " [command] Run a specific setup script"
@echo " -h, --help Display this help message"
@echo " -v, --version Display version information"
@echo " -s, --setup Set up the system with all the required packages"
@echo " -r, --remove Remove all installed packages"
@echo "Available commands:"
@printf "%-20s %s\n" "Commands" "Description"
@printf "%-20s %s\n" "------" "-----------"
@awk -F'[ :]' '!/^all:/ && /^([A-z_-]+):/ {print $$1}' $(lastword $(MAKEFILE_LIST)) \
| sort \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
| xargs -I _ sh -c 'printf "%-20s " _; make -f $(lastword $(MAKEFILE_LIST)) _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"'

%:
@echo "Error: Command $@ not available."
@echo "Run 'shreyam-do -h' to see available commands."

#sets up system env for docker
doker-setup:
@# Help: sets up system env for docker
echo "Setting up env" && \
sudo apt-get update && \
curl -sSL https://get.docker.com/ | sh && \
Expand All @@ -21,25 +48,29 @@ doker-setup:

#enables overcommit which helps with memory issues on virtual machines
enable-overcommit:
@# Help: enables overcommit which helps with memory issues on virtual machines
echo "Enabling overcommit" && \
sudo sysctl vm.overcommit_memory=1 && \
echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf && \
echo "Overcommit enabled"

#installs certbot and obtains ssl certificates for the domain names passed as arguments
ssl-cert:
@# Help: installs certbot and obtains ssl certificates for the domain names passed as arguments
echo "Setting up ssl using certbot for $(subst ssl-cert,,$(MAKECMDGOALS))" && \
sudo apt-get update && \
sudo snap install --classic certbot && \
sudo certbot certonly $(addprefix -d ,$(subst ssl-cert,,$(MAKECMDGOALS))) && \
echo "SSL setup done for $(subst ssl-cert,,$(MAKECMDGOALS)) and certificated stored in /etc/letsencrypt/live/$(subst ssl-cert,,$(MAKECMDGOALS))"

#fixes sentry issues on memory profiler
##fixes sentry issues on memory profiler
sentry-fix:
@# Help: fixes sentry issues on memory profiler
sudo apt-get update && sudo apt-get upgrade libstdc++6 -y

#opens ports for http, https
open-ports:
@# Help: opens ports for http, https
echo "Opening ports" && \
sudo apt-get update && \
sudo apt install -y firewalld && \
Expand All @@ -51,11 +82,11 @@ open-ports:
sudo firewall-cmd --zone=public --permanent --add-port=443/tcp && \
sudo firewall-cmd --reload && \
sudo firewall-cmd --list-all && \
sudo systemctl restart docker && \
echo "Ports opened"

#installs certbot and obtains ssl certificates for the domain names passed as arguments for nginx
ssl-nginx:
@# Help: installs certbot and obtains ssl certificates for the domain names passed as arguments for nginx
echo "Setting up ssl using certbot for $(subst ssl-nginx,,$(MAKECMDGOALS))" && \
sudo apt-get update && \
sudo snap install --classic certbot && \
Expand All @@ -65,13 +96,15 @@ ssl-nginx:

#installs nginx
nginx-install:
@# Help: installs nginx
echo "Installing nginx" && \
sudo apt-get update && \
sudo apt-get install nginx -y && \
echo "Nginx installed"

#installs fpm a dpkg package manager for non-Debian systems
fpm-install:
@# Help: installs fpm a dpkg package manager for non-Debian systems
echo "Installing fpm" && \
sudo gem install fpm && \
brew install rpm squashfs && \
Expand All @@ -80,6 +113,7 @@ fpm-install:

#builds dpkg package for the package name and version passed as arguments
build-dpkg:
@# Help: builds dpkg package for the package name and version passed as arguments
@if [ -z "$(word 2, $(MAKECMDGOALS))" ] || [ -z "$(word 3, $(MAKECMDGOALS))" ]; then \
echo "Usage: make build-dpkg <package-name> <version>" ; \
else \
Expand All @@ -88,8 +122,9 @@ build-dpkg:
echo "Dpkg built" ; \
fi

# creates a symlink for the file name passed as argument in nginx sites-enabled
#creates a symlink for the file name passed as argument in nginx sites-enabled
symLink:
@# Help: creates a symlink for the file name passed as argument in nginx sites-enabled
@if [ -z "$(word 2, $(MAKECMDGOALS))" ]; then \
echo "Usage: make symLink <file-name>" ; \
else \
Expand Down

0 comments on commit c481d30

Please sign in to comment.