-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-binary.sh
More file actions
executable file
·161 lines (128 loc) · 4.68 KB
/
build-binary.sh
File metadata and controls
executable file
·161 lines (128 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# Create build directory
BUILD_DIR="build"
BINARY_NAME="wp-docker"
echo "Creating build directory..."
# remove existing wp-docker binary
mkdir -p "$BUILD_DIR"
rm -f "$BUILD_DIR/$BINARY_NAME"
# Create a temporary combined script
TEMP_SCRIPT="$BUILD_DIR/combined_script.sh"
echo "Combining all scripts..."
# Start with shebang and header
cat > "$TEMP_SCRIPT" << 'EOF'
#!/bin/bash
# Combined WP-Docker Script
# Developed by CodesVault <https://github.com/CodesVault>
# Author: Keramot UL Islam <https://abmsourav.com>
EOF
# Add embedded Docker configuration files
echo "Embedding Docker configuration files..."
# Function to encode file content in base64 and add to script
embed_file() {
local file_path="$1"
local var_name="$2"
if [ -f "$file_path" ]; then
echo "Embedding $file_path as $var_name..."
echo "" >> "$TEMP_SCRIPT"
echo "# Embedded file: $file_path" >> "$TEMP_SCRIPT"
echo "$var_name=\"$(base64 -i "$file_path" | tr -d '\n')\"" >> "$TEMP_SCRIPT"
else
echo "Warning: $file_path not found"
fi
}
# Embed all Docker configuration files
embed_file "master_docker/docker-compose.yml" "DOCKER_COMPOSE_YML"
embed_file "master_docker/configs/app.dockerfile" "APP_DOCKERFILE"
embed_file "master_docker/configs/nginx.dockerfile" "NGINX_DOCKERFILE"
embed_file "master_docker/configs/php.ini" "PHP_INI"
embed_file "master_docker/configs/nginx/default.conf" "NGINX_CONF"
# Add helper function to create files from embedded content
cat >> "$TEMP_SCRIPT" << 'EOF'
# Helper function to create files from embedded base64 content
create_docker_files() {
local target_dir="$1"
mkdir -p "$target_dir/configs/nginx"
# Create docker-compose.yml
echo "$DOCKER_COMPOSE_YML" | base64 -d > "$target_dir/docker-compose.yml"
# Create dockerfiles and configs
echo "$APP_DOCKERFILE" | base64 -d > "$target_dir/configs/app.dockerfile"
echo "$NGINX_DOCKERFILE" | base64 -d > "$target_dir/configs/nginx.dockerfile"
echo "$PHP_INI" | base64 -d > "$target_dir/configs/php.ini"
echo "$NGINX_CONF" | base64 -d > "$target_dir/configs/nginx/default.conf"
}
EOF
# Function to add a file with proper function wrapping
add_file_content() {
local file_path="$1"
if [ -f "$file_path" ]; then
echo "Adding $file_path..."
echo "" >> "$TEMP_SCRIPT"
echo "# Content from $file_path" >> "$TEMP_SCRIPT"
# Remove shebang and source statements
if [[ "$file_path" == "cli/bingo" ]]; then
# Special handling for bingo to remove source statements
sed '1{/^#!/d;}; /^source.*cli\//d' "$file_path" >> "$TEMP_SCRIPT"
else
# For other files, remove shebang and source statements
sed '1{/^#!/d;}; /^source.*cli\//d' "$file_path" >> "$TEMP_SCRIPT"
fi
echo "" >> "$TEMP_SCRIPT"
else
echo "Warning: $file_path not found"
fi
}
# Add all CLI dependencies in proper order
add_file_content "cli/ui"
add_file_content "cli/random_port"
add_file_content "cli/routes"
add_file_content "cli/get_inputs"
add_file_content "cli/update_hosts"
add_file_content "cli/generate_files" # This will be modified to use embedded files
add_file_content "cli/docker_environment"
add_file_content "cli/prepare_wp"
add_file_content "cli/congrats"
# Add the main bingo function
add_file_content "cli/bingo"
# Add main execution logic (from codesvault)
cat >> "$TEMP_SCRIPT" << 'EOF'
# Main execution
function main {
bingo $1
}
# Execute main function with all arguments
main "$@"
EOF
echo "Making combined script executable..."
chmod +x "$TEMP_SCRIPT"
# Create binary using shc
echo "Creating binary with shc..."
if command -v shc &> /dev/null; then
shc -f "$TEMP_SCRIPT" -o "$BUILD_DIR/$BINARY_NAME"
if [ $? -eq 0 ]; then
echo "Binary created successfully: $BUILD_DIR/$BINARY_NAME"
# Clean up temporary files
rm -f "$TEMP_SCRIPT"
rm -f "$BUILD_DIR/combined_script.sh.x.c"
echo "Build completed successfully!"
echo "Binary location: $(pwd)/$BUILD_DIR/$BINARY_NAME"
# Make binary executable
chmod +x "$BUILD_DIR/$BINARY_NAME"
# Test the binary
echo ""
echo "Testing binary..."
if "$BUILD_DIR/$BINARY_NAME" --routes 2>/dev/null; then
echo "Binary test passed!"
else
echo "Binary created but test failed. Please check manually."
fi
else
echo "Error: Failed to create binary with shc"
exit 1
fi
else
echo "Error: shc not found. Please install shc first."
echo "On macOS: brew install shc"
echo "On Ubuntu: sudo apt-get install shc"
exit 1
fi