Skip to content

Commit 254104f

Browse files
committed
implement modular architecture refactor
1 parent d279270 commit 254104f

File tree

4 files changed

+635
-43
lines changed

4 files changed

+635
-43
lines changed

README.md

Lines changed: 120 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,147 @@
1-
# OpenSSL rpm builder for CentOS/RHEL - build latest OpenSSL binary
1+
# OpenSSL RPM Builder for CentOS/RHEL - Build latest OpenSSL binary
22

33
![GitHub last commit](https://img.shields.io/github/last-commit/philyuchkoff/openssl-RPM-Builder?style=for-the-badge)
44
![GitHub All Releases](https://img.shields.io/github/downloads/philyuchkoff/openssl-RPM-Builder/total?style=for-the-badge)
55

66
## [OpenSSL official site](https://www.openssl.org/)
77

8-
## Remove old versions
9-
````
10-
rpm -qa | grep openssl
11-
rpm -e --justdb --nodeps <yourpackage>
12-
````
13-
14-
# OpenSSL 3.6.1 [release page](https://github.com/openssl/openssl/releases/tag/openssl-3.6.1):
8+
## Quick Start (Recommended)
159

16-
## Build:
10+
Use the new unified build script that supports all OpenSSL versions:
1711

1812
```bash
19-
sudo yum -y groupinstall 'Development Tools'
13+
# Install development tools
14+
sudo yum -y groupinstall 'Development Tools' # or dnf on newer systems
15+
16+
# Clone the repository
2017
git clone https://github.com/philyuchkoff/openssl-RPM-Builder
2118
cd openssl-RPM-Builder
22-
chmod +x install-openssl_3.sh
23-
sudo ./install-openssl_3.sh
24-
```
25-
26-
Builded RPM will be in
2719

28-
/root/rpmbuild/RPMS/x86_64/
29-
30-
After `install-openssl_3.sh` will finish, you can install builded rpm:
20+
# Build OpenSSL (uses latest stable version by default)
21+
sudo ./build-openssl.sh
22+
23+
# Or specify a version
24+
sudo ./build-openssl.sh 3.6.1
25+
sudo ./build-openssl.sh 1.1.1w
26+
```
27+
28+
The built RPMs will be located in:
29+
```
30+
/root/rpmbuild/RPMS/x86_64/
31+
```
32+
33+
### Advanced Usage
3134

3235
```bash
33-
sudo rpm -ivvh /root/rpmbuild/RPMS/x86_64/openssl-3.6.1-1.el9.x86_64.rpm --nodeps
34-
```
36+
# List available OpenSSL versions
37+
./build-openssl.sh --list
38+
39+
# Use custom installation directory
40+
sudo OPENSSL_DIR=/opt/openssl ./build-openssl.sh 3.6.1
3541

36-
# OpenSSL 1.1.1w:
37-
[OpenSSL 1.1.1 End of Life](https://www.openssl.org/blog/blog/2023/03/28/1.1.1-EOL/)
42+
# View help
43+
./build-openssl.sh --help
44+
```
45+
46+
## Remove old versions
3847

39-
## Build:
48+
Before installing the new OpenSSL RPMs, remove existing packages:
4049

4150
```bash
42-
sudo yum -y groupinstall 'Development Tools'
43-
git clone https://github.com/philyuchkoff/openssl-RPM-Builder
44-
cd openssl-RPM-Builder
45-
chmod +x install-openssl_1.1.1.sh
51+
# List OpenSSL packages
52+
rpm -qa | grep openssl
53+
54+
# Remove existing OpenSSL (use with caution)
55+
rpm -e --justdb --nodeps <package-name>
56+
```
57+
58+
## Legacy Scripts (Deprecated)
59+
60+
The old version-specific scripts are still available for backward compatibility:
61+
62+
```bash
63+
# OpenSSL 3.6.1 (deprecated - use unified script instead)
64+
sudo ./install-openssl_3.sh
65+
66+
# OpenSSL 1.1.1w (deprecated - use unified script instead)
4667
sudo ./install-openssl_1.1.1.sh
47-
```
48-
49-
Builded RPM will be in
68+
```
69+
70+
> **Note**: These scripts are deprecated and will be removed in a future version. Please migrate to the unified `build-openssl.sh` script.
71+
72+
## Version-Specific Information
73+
74+
### OpenSSL 3.6.1
75+
- [Release Page](https://github.com/openssl/openssl/releases/tag/openssl-3.6.1)
76+
- Current stable release
77+
- Recommended for new installations
78+
79+
### OpenSSL 1.1.1w
80+
- [OpenSSL 1.1.1 End of Life](https://www.openssl.org/blog/blog/2023/03/28/1.1.1-EOL/)
81+
- Consider upgrading to OpenSSL 3.x if possible
82+
- Use only for compatibility with existing applications
83+
84+
## Installation of Built RPMs
85+
86+
After the build completes, install the generated RPM packages:
87+
88+
```bash
89+
# Find the built RPMs
90+
ls /root/rpmbuild/RPMS/x86_64/openssl-*.rpm
5091

51-
/root/rpmbuild/RPMS/x86_64/
52-
53-
After `install-openssl_1.1.1.sh` will finish, you can install builded rpm:
92+
# Install the main package
93+
sudo rpm -ivvh /root/rpmbuild/RPMS/x86_64/openssl-<version>-1.el<release>.x86_64.rpm --nodeps
94+
95+
# For development, also install the devel package
96+
sudo rpm -ivvh /root/rpmbuild/RPMS/x86_64/openssl-devel-<version>-1.el<release>.x86_64.rpm --nodeps
97+
```
98+
99+
## Verification
100+
101+
Check the installation:
54102

55103
```bash
56-
sudo rpm -ivvh /root/rpmbuild/RPMS/x86_64/openssl-1.1.1w-1.el7.x86_64.rpm --nodeps
57-
```
104+
# Check OpenSSL version
105+
openssl version
106+
107+
# Example output:
108+
# OpenSSL 3.6.1 7 May 2024
109+
# or
110+
# OpenSSL 1.1.1w 11 Sep 2023
111+
112+
# Verify RPM installation
113+
rpm -qa openssl
114+
# Example output:
115+
# openssl-3.6.1-1.el9.x86_64
116+
```
117+
118+
## Architecture
119+
120+
The OpenSSL RPM Builder is now modularized with the following components:
121+
122+
```
123+
openssl-RPM-Builder/
124+
├── README.md # This file
125+
├── common.sh # Shared functions library
126+
├── config.sh # Default configuration
127+
├── build-openssl.sh # Main unified script
128+
├── install-openssl_1.1.1.sh # Legacy script (deprecated)
129+
└── install-openssl_3.sh # Legacy script (deprecated)
130+
```
131+
132+
### Benefits of the New Architecture
58133

59-
## Check:
134+
- **Reduced Code Duplication**: Common functionality is centralized in `common.sh`
135+
- **Easy Version Support**: Add new OpenSSL versions by updating the configuration
136+
- **Unified Interface**: One script supports all OpenSSL versions
137+
- **Better Error Handling**: Consistent error reporting and cleanup
138+
- **Flexible Configuration**: Customize paths and build options
139+
- **Backward Compatibility**: Existing workflows continue to work
60140

61-
$openssl version
62-
OpenSSL 1.1.1w 11 Sep 2023
63-
or
141+
## Contributing
64142

65-
$rpm -qa openssl
66-
openssl-1.1.1w-1.el7.x86_64
143+
Feel free to submit issues and pull requests to improve the OpenSSL RPM Builder!
67144

68-
## For fun
145+
## For Fun
69146

70-
[![Star History Chart](https://api.star-history.com/svg?repos=philyuchkoff/openssl-RPM-Builder&type=date&legend=top-left)](https://www.star-history.com/#philyuchkoff/openssl-RPM-Builder&type=date&legend=top-left)
147+
[![Star History Chart](https://api.star-history.com/svg?repos=philyuchkoff/openssl-RPM-Builder&type=date&legend=top-left)](https://www.star-history.com/#philyuchkoff/openssl-RPM-Builder&type=date&legend=top-left)

build-openssl.sh

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#!/bin/bash
2+
3+
# OpenSSL RPM Builder - Unified Build Script
4+
# This script builds OpenSSL RPM packages for specified versions
5+
# Usage: sudo ./build-openssl.sh [VERSION]
6+
7+
# Strict error handling
8+
set -euo pipefail
9+
10+
# Get script directory
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
13+
# Load configuration and common functions
14+
source "${SCRIPT_DIR}/config.sh"
15+
source "${SCRIPT_DIR}/common.sh"
16+
17+
# Display help
18+
show_help() {
19+
cat << EOF
20+
OpenSSL RPM Builder - Unified Build Script
21+
22+
USAGE:
23+
sudo ./build-openssl.sh [OPTIONS] [VERSION]
24+
25+
ARGUMENTS:
26+
VERSION OpenSSL version to build (e.g., 1.1.1w, 3.6.1)
27+
If not provided, uses DEFAULT_VERSION=${DEFAULT_VERSION}
28+
29+
OPTIONS:
30+
-h, --help Show this help message
31+
-l, --list List available OpenSSL versions
32+
-c, --config FILE Use custom configuration file
33+
34+
ENVIRONMENT VARIABLES:
35+
OPENSSL_DIR OpenSSL installation directory (default: ${OPENSSL_DIR})
36+
BUILD_ROOT RPM build root directory (default: ${BUILD_ROOT})
37+
ARCH System architecture (default: ${ARCH})
38+
39+
EXAMPLES:
40+
# Build with default version (${DEFAULT_VERSION})
41+
sudo ./build-openssl.sh
42+
43+
# Build specific version
44+
sudo ./build-openssl.sh 1.1.1w
45+
sudo ./build-openssl.sh 3.6.1
46+
47+
# Custom installation directory
48+
sudo OPENSSL_DIR=/opt/openssl ./build-openssl.sh 3.6.1
49+
50+
# List available versions
51+
./build-openssl.sh --list
52+
53+
EOF
54+
}
55+
56+
# List available OpenSSL versions
57+
list_versions() {
58+
echo
59+
log_info "Available OpenSSL versions:"
60+
echo
61+
62+
for version_config in "${OPENSSL_VERSIONS[@]}"; do
63+
version="${version_config%=*}"
64+
status="${version_config#*=}"
65+
if [[ "$status" == "stable" ]]; then
66+
echo -e " ${GREEN}${version}${NC} (stable)"
67+
elif [[ "$status" == "dev" ]]; then
68+
echo -e " ${YELLOW}${version}${NC} (development)"
69+
fi
70+
done
71+
echo
72+
}
73+
74+
# Parse command line arguments
75+
parse_args() {
76+
VERSION=""
77+
78+
while [[ $# -gt 0 ]]; do
79+
case $1 in
80+
-h|--help)
81+
show_help
82+
exit 0
83+
;;
84+
-l|--list)
85+
list_versions
86+
exit 0
87+
;;
88+
-c|--config)
89+
shift
90+
if [[ -f "$1" ]]; then
91+
source "$1"
92+
log_info "Using configuration file: $1"
93+
else
94+
log_error "Configuration file not found: $1"
95+
exit 1
96+
fi
97+
;;
98+
*)
99+
if [[ -z "$VERSION" ]]; then
100+
VERSION="$1"
101+
else
102+
log_error "Too many arguments. Use --help for usage."
103+
exit 1
104+
fi
105+
;;
106+
esac
107+
shift
108+
done
109+
110+
# Use default version if not specified
111+
if [[ -z "$VERSION" ]]; then
112+
VERSION="$DEFAULT_VERSION"
113+
log_info "No version specified, using default: $VERSION"
114+
fi
115+
}
116+
117+
# Check prerequisites
118+
check_prerequisites() {
119+
log_info "Checking prerequisites..."
120+
121+
# Check if running as root
122+
if [[ $EUID -ne 0 ]]; then
123+
log_error "This script must be run as root (use sudo)"
124+
exit 1
125+
fi
126+
127+
# Validate version format
128+
validate_version "$VERSION"
129+
130+
# Check if version configuration exists
131+
version_found=0
132+
for version_config in "${OPENSSL_VERSIONS[@]}"; do
133+
if [[ "${version_config%=*}" == "$VERSION" ]]; then
134+
version_found=1
135+
break
136+
fi
137+
done
138+
139+
if [[ $version_found -eq 0 ]]; then
140+
log_warning "Version $VERSION not in predefined configurations"
141+
read -p "Continue anyway? (y/N): " -n 1 -r
142+
echo
143+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
144+
exit 1
145+
fi
146+
fi
147+
148+
log_success "Prerequisites checked"
149+
}
150+
151+
# Main execution
152+
main() {
153+
# Display header
154+
echo
155+
echo "============================================================"
156+
echo " OpenSSL RPM Builder - Unified Build Script"
157+
echo "============================================================"
158+
echo
159+
160+
# Parse command line arguments
161+
parse_args "$@"
162+
163+
# Check prerequisites
164+
check_prerequisites
165+
166+
# Display build configuration
167+
log_info "Build Configuration:"
168+
echo " OpenSSL Version: $VERSION"
169+
echo " Build Root: $BUILD_ROOT"
170+
echo " OpenSSL Directory: $OPENSSL_DIR"
171+
echo " Architecture: $ARCH"
172+
echo " Package Manager: $(detect_package_manager)"
173+
echo
174+
175+
# Execute build steps
176+
install_dependencies "$VERSION"
177+
setup_build_environment "$BUILD_ROOT"
178+
download_openssl "$VERSION" "$BUILD_ROOT"
179+
generate_spec_file "$VERSION" "$BUILD_ROOT"
180+
build_rpm "$VERSION" "$BUILD_ROOT"
181+
182+
# Show completion message
183+
echo
184+
log_success "OpenSSL $VERSION RPM build completed successfully!"
185+
echo
186+
show_install_instructions "$VERSION" "$BUILD_ROOT"
187+
}
188+
189+
# Run main function with all arguments
190+
main "$@"

0 commit comments

Comments
 (0)