jamal 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +4 -0
- data/exe/jamal +54 -0
- data/lib/jamal/version.rb +5 -0
- data/lib/jamal.rb +294 -0
- data/sig/jamal.rbs +4 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9402212f10aa8571ed0e83d0a5dbed70eb5c70598bb85f6508f55ee96105fffe
|
4
|
+
data.tar.gz: 0f35b747064337969aec3d450a0a851192b42efcc9e546000be8248588ce3ac9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3f2177e08b89eb443e48a55e41fe73773073ec5c54ba114cf3fb0886fb295ce93d855b3d193b7778c692570c44fd70b6f4f6a71a1faf898f9dbdf7214df654d
|
7
|
+
data.tar.gz: e413711576342ddbae07b48238507232e2a10f314ccaa79c2f9c87ba12f8c63b6d79ab1e5edf61ae40ef9fe81435a04b93b1694986bbe79a5fd9781f6254a7a2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mounir@ahmina.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Mounir Ahmina
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Jamal
|
2
|
+
|
3
|
+
Jamal is a lightweight tool to deploy static websites to remote web servers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install jamal
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
1. Run `jamal init` to initialize the configuration file `_jamal.yml`.
|
13
|
+
2. Edit the `_jamal.yml` file to match your server configuration.
|
14
|
+
3. Run the `jamal setup` command to setup the server.
|
15
|
+
4. Run the `jamal deploy` command to deploy your website.
|
16
|
+
|
17
|
+
## Configuration
|
18
|
+
|
19
|
+
The `_jamal.yml` file is used to configure the server. It contains the following fields:
|
20
|
+
|
21
|
+
- `name`: The name of the website, this acts like an identifier for the website.
|
22
|
+
- `host`: The hostname of the server.
|
23
|
+
- `user`: The username of the server.
|
24
|
+
- `password`: The password of the server.
|
25
|
+
- `domains`: The domains of the website.
|
26
|
+
- `path`: The path to the website on your local machine.
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE.txt) file for details.
|
data/Rakefile
ADDED
data/exe/jamal
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "jamal"
|
5
|
+
|
6
|
+
command = ARGV[0]
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
case command
|
10
|
+
when "setup"
|
11
|
+
# Parse setup options
|
12
|
+
require 'optparse'
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: jamal deploy [--config CONFIG_PATH]"
|
15
|
+
|
16
|
+
opts.on("--config CONFIG", "Path to config file") { |c| options[:config_path] = c }
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
Jamal::CLI.setup(**options)
|
20
|
+
|
21
|
+
when "deploy"
|
22
|
+
# Parse deploy options
|
23
|
+
require 'optparse'
|
24
|
+
OptionParser.new do |opts|
|
25
|
+
opts.banner = "Usage: jamal deploy [--config CONFIG_PATH]"
|
26
|
+
|
27
|
+
opts.on("--config CONFIG", "Path to config file") { |c| options[:config_path] = c }
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
Jamal::CLI.deploy(**options)
|
31
|
+
|
32
|
+
when "remove"
|
33
|
+
# Parse remove options
|
34
|
+
require 'optparse'
|
35
|
+
OptionParser.new do |opts|
|
36
|
+
opts.banner = "Usage: jamal remove [--config CONFIG_PATH]"
|
37
|
+
|
38
|
+
opts.on("--config CONFIG", "Path to config file") { |c| options[:config_path] = c }
|
39
|
+
end.parse!
|
40
|
+
|
41
|
+
Jamal::CLI.remove(**options)
|
42
|
+
|
43
|
+
when "init"
|
44
|
+
Jamal::CLI.init(**options)
|
45
|
+
|
46
|
+
when "-v"
|
47
|
+
puts "Jamal #{Jamal::VERSION}"
|
48
|
+
exit 0
|
49
|
+
|
50
|
+
else
|
51
|
+
puts "Unknown command: #{command}"
|
52
|
+
puts "Available commands: setup, deploy, remove, init, -v"
|
53
|
+
exit 1
|
54
|
+
end
|
data/lib/jamal.rb
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "jamal/version"
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'net/sftp'
|
6
|
+
require 'yaml'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'tempfile'
|
9
|
+
|
10
|
+
module Jamal
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
class CLI
|
14
|
+
def self.setup(config_path: '_jamal.yml')
|
15
|
+
# Load configuration
|
16
|
+
config = YAML.load_file(config_path)
|
17
|
+
|
18
|
+
begin
|
19
|
+
# Establish SSH connection using config values
|
20
|
+
Net::SSH.start(config['host'], config['user'],
|
21
|
+
password: config['password']
|
22
|
+
) do |ssh|
|
23
|
+
puts "Connected to #{config['host']}..."
|
24
|
+
|
25
|
+
# Check if nginx is installed
|
26
|
+
result = ssh.exec!("nginx -v")
|
27
|
+
if result && !result.include?("not found")
|
28
|
+
puts "nginx is already installed"
|
29
|
+
else
|
30
|
+
puts "Installing nginx..."
|
31
|
+
# Update package list and install nginx
|
32
|
+
ssh.exec!("sudo apt-get update")
|
33
|
+
ssh.exec!("sudo apt-get install -y nginx")
|
34
|
+
|
35
|
+
# Verify installation
|
36
|
+
result = ssh.exec!("nginx -v")
|
37
|
+
if result && !result.include?("not found")
|
38
|
+
puts "nginx installed successfully"
|
39
|
+
else
|
40
|
+
raise Error, "Failed to install nginx"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Set up rsync daemon configuration
|
45
|
+
puts "Setting up rsync daemon..."
|
46
|
+
|
47
|
+
# Create rsyncd configuration with consistent user permissions
|
48
|
+
rsyncd_conf = <<~CONFIG
|
49
|
+
uid = #{config['user']}
|
50
|
+
gid = #{config['user']}
|
51
|
+
use chroot = no
|
52
|
+
max connections = 4
|
53
|
+
pid file = /var/run/rsyncd.pid
|
54
|
+
exclude = .git/ .gitignore
|
55
|
+
|
56
|
+
[#{config['name']}]
|
57
|
+
path = /var/www/#{config['name']}
|
58
|
+
comment = Website files for #{config['name']}
|
59
|
+
read only = no
|
60
|
+
auth users = #{config['name']}
|
61
|
+
secrets file = /etc/rsyncd.secrets
|
62
|
+
CONFIG
|
63
|
+
|
64
|
+
# Generate a random password for rsync
|
65
|
+
special_chars = '!@#$%^&*()_+-=[]{}|;:,.<>?'.chars
|
66
|
+
numbers = '0123456789'.chars
|
67
|
+
letters = ('a'..'z').to_a + ('A'..'Z').to_a
|
68
|
+
rsync_password = (letters + numbers + special_chars).shuffle[0,16].join
|
69
|
+
|
70
|
+
# First, clean up any existing entries for both the site name and root user
|
71
|
+
ssh.exec!("sudo sed -i '/^#{config['name']}:/d' /etc/rsyncd.secrets")
|
72
|
+
|
73
|
+
# Add new entry with the website name
|
74
|
+
ssh.exec!("echo '#{config['name']}:#{rsync_password}' | sudo tee -a /etc/rsyncd.secrets")
|
75
|
+
ssh.exec!("sudo chmod 600 /etc/rsyncd.secrets")
|
76
|
+
|
77
|
+
# Remove any existing module configuration and create new one
|
78
|
+
ssh.exec!("sudo sed -i '/\\[#{config['name']}\\]/,/^$/d' /etc/rsyncd.conf")
|
79
|
+
|
80
|
+
# Write the full rsyncd configuration
|
81
|
+
ssh.exec!("echo '#{rsyncd_conf}' | sudo tee -a /etc/rsyncd.conf")
|
82
|
+
|
83
|
+
# Update the config file with the rsync password
|
84
|
+
config['rsync_password'] = rsync_password
|
85
|
+
File.write(config_path, config.to_yaml)
|
86
|
+
|
87
|
+
# Enable and start rsync daemon
|
88
|
+
ssh.exec!("sudo systemctl enable rsync")
|
89
|
+
ssh.exec!("sudo systemctl start rsync")
|
90
|
+
|
91
|
+
puts "Rsync daemon configured successfully!"
|
92
|
+
end
|
93
|
+
rescue Net::SSH::AuthenticationFailed
|
94
|
+
raise Error, "SSH authentication failed"
|
95
|
+
rescue StandardError => e
|
96
|
+
raise Error, "Setup failed: #{e.message}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.deploy(config_path: '_jamal.yml')
|
101
|
+
# Load configuration
|
102
|
+
config = YAML.load_file(config_path)
|
103
|
+
temp_password_file = nil # Declare variable outside begin block
|
104
|
+
|
105
|
+
begin
|
106
|
+
Net::SSH.start(config['host'], config['user'],
|
107
|
+
password: config['password']
|
108
|
+
) do |ssh|
|
109
|
+
puts "Connected to #{config['host']}..."
|
110
|
+
|
111
|
+
# Check rsync daemon status
|
112
|
+
puts "Checking rsync daemon status..."
|
113
|
+
status = ssh.exec!("sudo systemctl status rsync")
|
114
|
+
unless status.include?("active (running)")
|
115
|
+
puts "Restarting rsync daemon..."
|
116
|
+
ssh.exec!("sudo systemctl restart rsync")
|
117
|
+
end
|
118
|
+
|
119
|
+
# Create nginx configuration with support for multiple domains
|
120
|
+
nginx_config = <<~CONFIG
|
121
|
+
server {
|
122
|
+
listen 80;
|
123
|
+
server_name #{Array(config['domains']).join(' ')};
|
124
|
+
root /var/www/#{config['name']};
|
125
|
+
index index.html index.htm;
|
126
|
+
|
127
|
+
location / {
|
128
|
+
try_files $uri $uri/ =404;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
CONFIG
|
132
|
+
|
133
|
+
# Check if nginx config already exists and is the same
|
134
|
+
existing_config = ssh.exec!("sudo cat /etc/nginx/sites-available/#{config['name']} 2>/dev/null")
|
135
|
+
if existing_config == nginx_config
|
136
|
+
puts "Nginx configuration unchanged, skipping update..."
|
137
|
+
else
|
138
|
+
# Create directory and upload nginx config
|
139
|
+
puts "Setting up nginx configuration..."
|
140
|
+
ssh.exec!("sudo mkdir -p /var/www/#{config['name']}")
|
141
|
+
ssh.exec!("sudo chown -R #{config['user']}:#{config['user']} /var/www/#{config['name']}")
|
142
|
+
ssh.exec!("sudo chmod -R 755 /var/www/#{config['name']}")
|
143
|
+
|
144
|
+
# Upload nginx config using SFTP
|
145
|
+
File.write('/tmp/temp_nginx.conf', nginx_config)
|
146
|
+
ssh.sftp.connect do |sftp|
|
147
|
+
sftp.upload!('/tmp/temp_nginx.conf', "/tmp/#{config['name']}.conf")
|
148
|
+
File.delete('/tmp/temp_nginx.conf')
|
149
|
+
end
|
150
|
+
|
151
|
+
# Move config to nginx sites and enable it
|
152
|
+
ssh.exec!("sudo mv /tmp/#{config['name']}.conf /etc/nginx/sites-available/#{config['name']}")
|
153
|
+
ssh.exec!("sudo ln -sf /etc/nginx/sites-available/#{config['name']} /etc/nginx/sites-enabled/")
|
154
|
+
|
155
|
+
# Test and reload nginx
|
156
|
+
puts "Testing nginx configuration..."
|
157
|
+
result = ssh.exec!("sudo nginx -t")
|
158
|
+
if result && !result.include?("error")
|
159
|
+
ssh.exec!("sudo systemctl reload nginx")
|
160
|
+
puts "Nginx configuration updated successfully!"
|
161
|
+
else
|
162
|
+
raise Error, "Invalid nginx configuration"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Replace SSH-based rsync with daemon-based rsync
|
167
|
+
local_path = config['local_path']
|
168
|
+
local_path = "#{local_path}/" unless local_path.end_with?('/')
|
169
|
+
|
170
|
+
# Create temporary password file for rsync
|
171
|
+
temp_password_file = Tempfile.new('rsync_password')
|
172
|
+
temp_password_file.write(config['rsync_password'])
|
173
|
+
temp_password_file.close
|
174
|
+
FileUtils.chmod(0600, temp_password_file.path)
|
175
|
+
|
176
|
+
# Build rsync command for daemon mode with simplified output
|
177
|
+
rsync_cmd = [
|
178
|
+
"rsync",
|
179
|
+
"-ahi", # archive mode, human-readable, itemize changes
|
180
|
+
"--delete", # delete extraneous files
|
181
|
+
"--out-format='%i | %n'", # simplified output format showing changes and filename
|
182
|
+
"--password-file=#{temp_password_file.path}",
|
183
|
+
local_path,
|
184
|
+
"rsync://#{config['name']}@#{config['host']}/#{config['name']}/"
|
185
|
+
].join(" ")
|
186
|
+
|
187
|
+
# Execute rsync with better error handling
|
188
|
+
puts "Syncing website files..."
|
189
|
+
|
190
|
+
IO.popen(rsync_cmd) do |io|
|
191
|
+
while line = io.gets
|
192
|
+
info = line.partition('|').first.strip
|
193
|
+
filename = line.partition('|').last.strip
|
194
|
+
|
195
|
+
if info[0] == '<'
|
196
|
+
puts "Uploading #{filename}"
|
197
|
+
elsif info[0] == '.'
|
198
|
+
if info[1] == 'd'
|
199
|
+
puts "Acessing #{filename}"
|
200
|
+
else
|
201
|
+
puts "Unchanged #{filename}"
|
202
|
+
end
|
203
|
+
elsif info == "*deleting"
|
204
|
+
puts "Deleting #{filename}"
|
205
|
+
elsif info == "cd+++++++++"
|
206
|
+
puts "Creating #{filename}"
|
207
|
+
else
|
208
|
+
puts line
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
exit_status = $?.exitstatus
|
214
|
+
|
215
|
+
# Clean up temporary password file
|
216
|
+
temp_password_file.unlink
|
217
|
+
|
218
|
+
if exit_status != 0
|
219
|
+
puts "Rsync failed. Checking daemon accessibility..."
|
220
|
+
system("nc -zv #{config['host']} 873")
|
221
|
+
raise Error, "Rsync failed with status: #{exit_status}. Please check the rsync daemon is running and port 873 is accessible."
|
222
|
+
end
|
223
|
+
|
224
|
+
puts "Sync completed!"
|
225
|
+
end
|
226
|
+
rescue Net::SSH::AuthenticationFailed
|
227
|
+
raise Error, "SSH authentication failed"
|
228
|
+
rescue StandardError => e
|
229
|
+
raise Error, "Deployment failed: #{e.message}"
|
230
|
+
ensure
|
231
|
+
# Now temp_password_file will be in scope
|
232
|
+
temp_password_file&.unlink
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.remove(config_path: '_jamal.yml')
|
237
|
+
# Load configuration
|
238
|
+
config = YAML.load_file(config_path)
|
239
|
+
|
240
|
+
begin
|
241
|
+
Net::SSH.start(config['host'], config['user'],
|
242
|
+
password: config['password']
|
243
|
+
) do |ssh|
|
244
|
+
puts "Connected to #{config['host']}..."
|
245
|
+
|
246
|
+
# Remove nginx configuration
|
247
|
+
puts "Removing nginx configuration..."
|
248
|
+
ssh.exec!("sudo rm -f /etc/nginx/sites-enabled/#{config['name']}")
|
249
|
+
ssh.exec!("sudo rm -f /etc/nginx/sites-available/#{config['name']}")
|
250
|
+
ssh.exec!("sudo systemctl reload nginx")
|
251
|
+
|
252
|
+
# Remove website files
|
253
|
+
puts "Removing website files..."
|
254
|
+
ssh.exec!("sudo rm -rf /var/www/#{config['name']}")
|
255
|
+
|
256
|
+
# Remove rsync secrets
|
257
|
+
puts "Removing rsync secrets..."
|
258
|
+
ssh.exec!("sudo sed -i '/#{config['name']}:.*$/d' /etc/rsyncd.secrets")
|
259
|
+
|
260
|
+
# Remove rsync configuration
|
261
|
+
puts "Removing rsync configuration..."
|
262
|
+
ssh.exec!("sudo sed -i '/\\[#{config['name']}\\]/,/^$/d' /etc/rsyncd.conf")
|
263
|
+
|
264
|
+
# Clean up empty lines in rsync config
|
265
|
+
ssh.exec!("sudo sed -i '/^$/N;/^\\n$/D' /etc/rsyncd.conf")
|
266
|
+
|
267
|
+
# Remove rsync_password from local config file
|
268
|
+
config.delete('rsync_password')
|
269
|
+
File.write(config_path, config.to_yaml)
|
270
|
+
|
271
|
+
puts "Successfully removed all configurations for #{config['name']}!"
|
272
|
+
end
|
273
|
+
rescue Net::SSH::AuthenticationFailed
|
274
|
+
raise Error, "SSH authentication failed"
|
275
|
+
rescue StandardError => e
|
276
|
+
raise Error, "Removal failed: #{e.message}"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def self.init(config_path: '_jamal.yml')
|
281
|
+
# Create the config file
|
282
|
+
File.write(config_path, {
|
283
|
+
'name' => 'example',
|
284
|
+
'host' => '1.2.3.4',
|
285
|
+
'user' => 'root',
|
286
|
+
'password' => 'password',
|
287
|
+
'domains' => ['example.com', 'www.example.com'],
|
288
|
+
'local_path' => './_site'
|
289
|
+
}.to_yaml)
|
290
|
+
puts "Created #{config_path} with default configuration."
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
data/sig/jamal.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jamal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mounir Ahmina
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-ssh
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-sftp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: optparse
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.6.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fileutils
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yaml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.4.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tempfile
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.3.1
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
executables:
|
100
|
+
- jamal
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CODE_OF_CONDUCT.md
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- exe/jamal
|
109
|
+
- lib/jamal.rb
|
110
|
+
- lib/jamal/version.rb
|
111
|
+
- sig/jamal.rbs
|
112
|
+
homepage: https://github.com/mojl/jamal
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
allowed_push_host: https://rubygems.org
|
117
|
+
homepage_uri: https://github.com/mojl/jamal
|
118
|
+
source_code_uri: https://github.com/mojl/jamal
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 3.0.0
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.5.10
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Deploy your static website to a remote server
|
138
|
+
test_files: []
|