├── LICENSE ├── README.MD ├── linux-common ├── apache-cli │ ├── apache-cli-remove │ ├── create-host │ ├── delete-host │ ├── edit-host │ └── example.conf ├── install └── resources │ └── act-loc-redirect └── ubuntu ├── apache-cli ├── apache-cli-remove ├── create-host ├── delete-host ├── edit-host └── example.conf ├── install └── resources └── act-loc-redirect /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Apache Toolkit 2 | 3 | This toolkit is designed to make virtual host management more easier from command line. 4 | 5 | ## What's inside 6 | This toolkit contains 3 utilites: 7 | * `create-host` - Create a new virtual host (it will prepare all config's and folder) 8 | * `delete-host` - Delete a virtual host (including files and config) 9 | * `edit-host` - Edit host's configuration in VIM. 10 | 11 | ## Features 12 | * Virtual host management 13 | * Quick configuration edit 14 | * Creating template for new hosts 15 | * Create dns mask for all `.loc` and `.dev` domains (only Ubuntu) **optional** 16 | 17 | ## Installation 18 | * Clone this repo or go to releases tab and download suitable version. 19 | * Open nessesary distributive folder 20 | * Run `install` file and follow instructions on screen. 21 | 22 | ## Builds 23 | * **ubuntu** - Release for all Ubuntu-based products. 24 | * **linux-common** - Rest Linux systems, include only common stuff. 25 | * **darwin** - Soon. Will include OSX build. 26 | 27 | ## Support 28 | * Ubuntu - Supported. 29 | * Debian - Experimental, may work with ubuntu's package. 30 | * RHEL/CentOS - Supported. 31 | * Darwin/OSX - Soon will be available. 32 | 33 | ## Usage 34 | 35 | ### Create virtual hosts 36 | To create virtual host, just run `sudo create-host site.com`. 37 | Tool will create and enable config file and directory for the site. 38 | 39 | ### Delete vitrual hosts 40 | To edit host, use `sudo delete-host site.com`. 41 | Also you will be prompted if you want to delete a host directory. 42 | 43 | ### Edit virtualhost configuration 44 | To edit configuration, use `sudo edit-host site.com`. 45 | 46 | ### Edit general host configuration template 47 | General template is stored in `/etc/apache-cli/example.conf`. 48 | To edit it, you have to use `sudo`. 49 | 50 | ### Edit Toolkit configuration 51 | Configuration can be found in `/etc/apache-cli/config.sh`. 52 | 53 | ## Uninstall 54 | To remove toolkit, just run `sudo apache-cli-remove`; 55 | -------------------------------------------------------------------------------- /linux-common/apache-cli/apache-cli-remove: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # absolute path to this script. Works for OSX, Linux and BSD 3 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 4 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 5 | 6 | # Include config 7 | source "$SCRIPTPATH/config.sh"; 8 | 9 | XAPPDIR="$SCRIPTPATH"; 10 | 11 | # Bin path (empty) 12 | BIN_PATH=''; 13 | 14 | checkBinDir() { 15 | if [ -d '/usr/local/bin' ]; then 16 | BIN_PATH='/usr/local/bin'; 17 | else 18 | BIN_PATH='/usr/bin'; 19 | fi 20 | } 21 | 22 | x_cli_uninstall() { 23 | x_rm_bin 'create-host'; 24 | x_rm_bin 'delete-host'; 25 | x_rm_bin 'edit-host'; 26 | x_rm_bin 'apache-cli-remove'; 27 | 28 | sudo rm -rf "$XAPPDIR"; 29 | } 30 | 31 | function x_rm_bin { 32 | sudo rm -f "$BIN_PATH/$1"; 33 | sudo rm -f "$XAPPDIR/$1"; 34 | } 35 | 36 | checkBinDir; 37 | 38 | read -p "Remove $APP_CLI_NAME [y/n] ? " rmhosts; 39 | if [ "$rmhosts" = "y" ]; then 40 | x_cli_uninstall; 41 | else 42 | exit; 43 | fi; -------------------------------------------------------------------------------- /linux-common/apache-cli/create-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | 11 | # Check args count 12 | if [ $# -eq 0 ] 13 | then 14 | echo "$APP_CLI_NAME v$APP_CLI_VER"; 15 | echo "Create a new virtual host"; 16 | echo " Usage: $0 'hostname'"; 17 | exit 1; 18 | fi 19 | 20 | # params 21 | conf_p="$DIR_CONF" 22 | conf_ext=".conf" 23 | conf_file="$conf_p/$1$conf_ext" 24 | 25 | # owner 26 | own_name="$USR_NAME"; 27 | own_grp="$USR_GROUP"; 28 | 29 | HOST_OWN="$USR_NAME:$USR_GROUP"; 30 | if [ "$USR_GROUP" = "root" ]; then 31 | HOST_OWN="$USR_NAME"; 32 | fi; 33 | 34 | # Sites path 35 | www_path="$DIR_HOSTS/hosts" 36 | 37 | # folder with html files 38 | public_html="public_html" 39 | 40 | host_path="$www_path/$1" 41 | 42 | # check hosts path 43 | if [ ! -d "$DIR_HOSTS" ]; then 44 | sudo mkdir -p "$DIR_HOSTS"; 45 | sudo chmod 777 "$DIR_HOSTS"; 46 | fi; 47 | 48 | # create host path 49 | sudo mkdir -p "$host_path"; 50 | sudo mkdir "$host_path/$public_html"; 51 | 52 | # permissions 53 | sudo chmod 777 "$host_path" 54 | sudo chmod 777 "$host_path/$public_html"; 55 | 56 | # ownership 57 | sudo chown "$HOST_OWN" "$host_path"; 58 | sudo chown "$HOST_OWN" "$host_path/$public_html"; 59 | 60 | echo "* Host directory: $host_path"; 61 | echo "* Documents root: '$host_path/$public_html'"; 62 | # Test index.php 63 | echo '' > "$host_path/$public_html/index.php"; 64 | 65 | # Create config 66 | sudo cp "$SCRIPTPATH/example.conf" "$conf_file"; 67 | 68 | function repl_args { 69 | sed -i -e "s#%$1%#$2#g" "$conf_file"; 70 | } 71 | 72 | # replace hostname 73 | # sed -i -e "s#%HOSTRING%#$1#g" "$conf_file"; 74 | repl_args "HOSTRING" "$1"; 75 | repl_args "HOSTPATH" "$DIR_HOSTS"; 76 | 77 | 78 | echo "* Host config: $conf_file"; 79 | echo "Configuration and directory for host '$1' were created successfuly"; 80 | echo "To edit configuration, run 'edit-host $1'"; 81 | echo "To apply changes, run 'sudo apachectl restart'"; 82 | -------------------------------------------------------------------------------- /linux-common/apache-cli/delete-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | # Check args count 11 | if [ $# -eq 0 ] 12 | then 13 | echo "$APP_CLI_NAME v$APP_CLI_VER"; 14 | echo "Delete a virtual host"; 15 | echo " Usage: $0 'hostname'"; 16 | exit 1; 17 | fi 18 | 19 | # params 20 | conf_p="$DIR_CONF" 21 | conf_ext=".conf" 22 | conf_file="$conf_p/$1$conf_ext" 23 | 24 | # Sites path 25 | www_path="$DIR_HOSTS/hosts" 26 | 27 | # folder with html files 28 | public_html="public_html" 29 | 30 | host_path="$www_path/$1" 31 | 32 | XSUCCESS='true'; 33 | if [ ! -f "$conf_file" ]; then 34 | echo "WARNING! Virtual host '$1' not exists. Configuration file '$conf_file' not found."; 35 | XSUCCESS='false'; 36 | else 37 | # delete config 38 | sudo rm -f "$conf_file"; 39 | fi; 40 | 41 | 42 | if [ -d "$host_path" ]; then 43 | read -p "Delete host directory content? [y/n]: " rmdir; 44 | if [ "$rmdir" = "y" ]; then 45 | # delete host path 46 | sudo rm -rf "$host_path"; 47 | fi; 48 | else 49 | echo "WARNING! Virtual host directory not exists: '$host_path'."; 50 | XSUCCESS='false'; 51 | fi; 52 | 53 | 54 | if [ "$XSUCCESS" = 'true' ]; then 55 | echo "Configuration and directory for host '$1' were removed successfuly"; 56 | else 57 | echo "Virtual host '$1' was removed, but with errors."; 58 | fi; 59 | 60 | echo "To apply changes, run 'sudo apachectl restart'"; 61 | -------------------------------------------------------------------------------- /linux-common/apache-cli/edit-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | 11 | conf_p="$DIR_CONF" 12 | conf_ext=".conf" 13 | sudo "$CONF_EDITOR" "$conf_p/$1$conf_ext"; 14 | -------------------------------------------------------------------------------- /linux-common/apache-cli/example.conf: -------------------------------------------------------------------------------- 1 | # This file was generated by Apache CLI Tools 2 | # 2016 (c) Denis Sedchenko [http://github.com/odin3] 3 | # 4 | # Configuration for host '%HOSTRING%' 5 | 6 | 7 | # Host URL 8 | ServerName www.%HOSTRING% 9 | ServerAlias %HOSTRING% 10 | ServerAdmin info@%HOSTRING% 11 | 12 | # Path to document root 13 | DocumentRoot %HOSTPATH%/hosts/%HOSTRING%/public_html 14 | 15 | 16 | # Directory index 17 | DirectoryIndex index.html index.htm index.php 18 | # Allow .htaccess 19 | AllowOverride All 20 | # Access 21 | Order allow,deny 22 | Allow from all 23 | # New directive needed in Apache 2.4.3: 24 | Require all granted 25 | 26 | 27 | # Error logs 28 | ErrorLog %HOSTPATH%/hosts/%HOSTRING%/error.log 29 | CustomLog %HOSTPATH%/hosts/%HOSTRING%/requests.log combined 30 | -------------------------------------------------------------------------------- /linux-common/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # OSX Document Root 4 | OSX_WWW='/Library/WebServer'; 5 | 6 | # Rest UNIX 7 | REST_WWW='/var/www'; 8 | 9 | 10 | # Debian's Apache conf dir 11 | DEB_CONF='/etc/apache2/sites-available'; 12 | 13 | # Rest 14 | REST_CONF='/etc/httpd/conf.d'; 15 | 16 | # Default location 17 | APP_CLI_PATH='/etc/apache-cli'; 18 | 19 | # Product name 20 | APP_CLI_NAME='Apache Toolkit'; 21 | 22 | # App conf file name 23 | APP_CONF_NAME='config.sh'; 24 | 25 | # Bin path (empty) 26 | BIN_PATH=''; 27 | 28 | # Apache CLI version 29 | APP_CLI_VER='1.1-linux-common'; 30 | 31 | SCRIPTPATH=$(cd "$(dirname "$0")"; pwd); 32 | 33 | USERNAME=$(whoami); 34 | 35 | 36 | setEditor() { 37 | echo '5. Enter name of default text editor for hosts ("vi" by default) or leave empty for default value.'; 38 | read -p "Edit .conf files with: " DEF_EDITOR; 39 | if [ -z "$DEF_EDITOR" ]; then 40 | DEF_EDITOR='vi'; 41 | echo "- Default editor used - 'vi'"; 42 | fi; 43 | echo ""; 44 | checkConfig; 45 | } 46 | 47 | checkBinDir() { 48 | if [ -d '/usr/local/bin' ]; then 49 | BIN_PATH='/usr/local/bin'; 50 | else 51 | BIN_PATH='/usr/bin'; 52 | fi; 53 | } 54 | 55 | setConfig() { 56 | echo "1. Enter the path to apache configs folder (usualy '/etc/apache2/sites-enabled' or '/etc/httpd') or leave empty for autodetect" 57 | echo ""; 58 | promptConfig; 59 | } 60 | 61 | detectConfPath() { 62 | echo '- Setup is trying to detect the path to config folder...'; 63 | if [ -d "$DEB_CONF" ]; then 64 | DIR_CONFIG="$DEB_CONF"; 65 | confDetected; 66 | elif [ -d "$REST_CONF" ]; then 67 | DIR_CONFIG="$REST_CONF"; 68 | confDetected; 69 | else 70 | echo "Cannot detect path, enter the path to Apache config folder:" 71 | promptConfig; 72 | fi; 73 | } 74 | 75 | 76 | 77 | 78 | 79 | confDetected() { 80 | echo "- Apache config path detected: $DIR_CONFIG"; 81 | setHostsPath; 82 | } 83 | 84 | detectHostsPath() { 85 | echo '- Setup is trying to detect the path to apache 'www' folder...'; 86 | if [ -d "$REST_WWW" ]; then 87 | DIR_HOSTS="$REST_WWW"; 88 | wwwDetectSuccess; 89 | elif [ -d "$OSX_WWW" ]; then 90 | DIR_HOSTS="$OSX_WWW"; 91 | wwwDetectSuccess; 92 | else 93 | echo "- Setup can't find Apache 'www' folder :("; 94 | promptHosts; 95 | fi; 96 | } 97 | 98 | wwwDetectSuccess() { 99 | echo "- Apache 'www' folder detected: $DIR_HOSTS"; 100 | checkIfHostsEmpty; 101 | } 102 | 103 | checkIfHostsEmpty() { 104 | if [ -d "$DIR_HOSTS/hosts" ]; then 105 | echo "- Selected folder already has 'hosts' folder: $DIR_HOSTS"; 106 | askRemoveHosts; 107 | else 108 | setUser; 109 | fi; 110 | } 111 | 112 | 113 | askRemoveHosts() { 114 | echo -n "Rename 'hosts' to 'hosts_old' [y/n] ? "; 115 | read -r rmhosts; 116 | if [ -z "$rmhosts" ]; then 117 | askRemoveHosts; 118 | elif [ "$rmhosts" = "y" ]; then 119 | sudo mv "$DIR_HOSTS/hosts" "$DIR_HOSTS/hosts_old"; 120 | DIR_HOSTS='/var/www'; 121 | setUser; 122 | elif [ "$rmhosts" = "n" ]; then 123 | setHostsPath; 124 | else 125 | echo "'y' or 'n' only allowed."; 126 | askRemoveHosts; 127 | fi; 128 | } 129 | 130 | promptConfig() { 131 | read -p 'Apache config path: ' DIR_CONFIG 132 | if [ -z "$DIR_CONFIG"]; then 133 | detectConfPath; 134 | elif [ ! -d "$DIR_CONFIG" ]; then 135 | echo "Path not found, try again:"; 136 | promptConfig; 137 | else 138 | setHostsPath; 139 | fi; 140 | } 141 | 142 | setHostsPath() { 143 | echo "2. Enter the path for virtual hosts folder (or leave empty for default value)" 144 | promptHosts 145 | } 146 | 147 | promptHosts() { 148 | read -p "Folder for hosts directory: " DIR_HOSTS 149 | if [ -z "$DIR_HOSTS" ]; then 150 | detectHostsPath; 151 | elif [ ! -d "$DIR_HOSTS" ]; then 152 | echo "Path not found, try again:"; 153 | promptHosts; 154 | else 155 | checkIfHostsEmpty; 156 | fi; 157 | } 158 | 159 | checkUserName() { 160 | grep "$USR_NAME" /etc/passwd 161 | if [ $? -ne 0 ]; 162 | then 163 | echo "- WARNING! Username $USR_NAME doesn't exists."; 164 | fi 165 | } 166 | 167 | setUser() { 168 | echo "3. Enter username for hosts folder ownership (or leave empty for current user):" 169 | read -p "Username: " USR_NAME 170 | if [ -z "$USR_NAME" ]; then 171 | USR_NAME="$USERNAME"; 172 | setGroup; 173 | else 174 | checkUserName; 175 | fi; 176 | } 177 | 178 | setGroup() { 179 | echo "4. Enter also group name for folder owner (or leave empty for the same as user name)." 180 | echo " TIP: We recommend to use 'wheel' group in case if you're sudo user."; 181 | echo ""; 182 | promptGrp; 183 | } 184 | 185 | promptGrp() { 186 | read -p 'Group name: ' USR_GROUP; 187 | if [ -z "$USR_GROUP" ]; then 188 | USR_GROUP="$USR_NAME"; 189 | fi; 190 | setEditor; 191 | } 192 | 193 | 194 | checkConfig() { 195 | clear; 196 | echo "Please check your configuration:"; 197 | echo ""; 198 | echo " ** LOCATION ** " 199 | echo " - Apache configuration path:"; 200 | echo " $DIR_CONFIG"; 201 | echo " - Path for virtual hosts folder:"; 202 | echo " $DIR_HOSTS"; 203 | echo " - Virtual hosts will be stored in:"; 204 | echo " $DIR_HOSTS/hosts"; 205 | echo ""; 206 | echo " ** FOLDERS OWNERSHIP ** "; 207 | echo " - Default user owner for hosts:"; 208 | echo " $USR_NAME"; 209 | echo " - Default group owner for hosts:"; 210 | echo " $USR_GROUP"; 211 | echo ""; 212 | echo "** ETC **"; 213 | echo " - Default .conf editor:"; 214 | echo " $DEF_EDITOR"; 215 | echo ""; 216 | echo ""; 217 | askCheckCfg; 218 | } 219 | 220 | askCheckCfg() { 221 | read -p 'Is it OK [y/n] ? ' rmhosts; 222 | if [ "$rmhosts" = "y" ]; then 223 | installNow; 224 | elif [ "$rmhosts" = "n" ]; then 225 | echo "- Setup will be restarted from the beginning..."; 226 | sleep 1; 227 | main; 228 | else 229 | echo "'y' or 'n' only allowed."; 230 | askCheckCfg; 231 | fi; 232 | } 233 | 234 | 235 | installNow() { 236 | clear; 237 | echo "**** Installing $APP_CLI_NAME ****"; 238 | echo ""; 239 | 240 | copyApp; 241 | 242 | chmodBins; 243 | 244 | smlink 'create-host'; 245 | smlink 'delete-host'; 246 | smlink 'edit-host'; 247 | smlink 'apache-cli-remove'; 248 | # smlink 'apache-cli-config.sh'; 249 | 250 | genConfig; 251 | 252 | sleep 1; 253 | echo ''; 254 | echo ''; 255 | install_finish_lol; 256 | 257 | } 258 | 259 | genConfig() { 260 | echo ' - Generating configuration...'; 261 | sudo printf "#!/bin/bash\n\n" > "$APP_CLI_PATH/$APP_CONF_NAME"; 262 | sudo printf "# $APP_CLI_NAME [$APP_CLI_VER] CONFIGURATION\n" >> "$APP_CLI_PATH/$APP_CONF_NAME"; 263 | 264 | conf_set 'APP_CLI_VER' "$APP_CLI_VER"; 265 | conf_set 'APP_CLI_NAME' "$APP_CLI_NAME"; 266 | conf_set 'DIR_CONF' "$DIR_CONFIG"; 267 | conf_set 'DIR_HOSTS' "$DIR_HOSTS"; 268 | conf_set 'USR_NAME' "$USR_NAME"; 269 | conf_set 'USR_GROUP' "$USR_GROUP"; 270 | conf_set 'CONF_EDITOR' "$DEF_EDITOR"; 271 | } 272 | 273 | function conf_set { 274 | sudo printf "$1=\"$2\"\n" >> "$APP_CLI_PATH/$APP_CONF_NAME"; 275 | } 276 | 277 | 278 | copyApp() { 279 | echo ' - Copying binaries...'; 280 | sudo cp -rf "$SCRIPTPATH/apache-cli" "$APP_CLI_PATH"; 281 | } 282 | 283 | 284 | 285 | chmodBins() { 286 | echo ' - Applying permissions...'; 287 | sudo chmod 777 "$APP_CLI_PATH"; 288 | } 289 | 290 | 291 | function smlink { 292 | echo " - Creating symlink: " 293 | echo " '$APP_CLI_PATH/$1' -> '$BIN_PATH/$1'"; 294 | sudo ln -s "$APP_CLI_PATH/$1" "$BIN_PATH/$1"; 295 | } 296 | 297 | 298 | 299 | 300 | 301 | checkIfInstalled() { 302 | if [ -d "$APP_CLI_PATH" ]; then 303 | echo "$APP_CLI_NAME is already installed in:"; 304 | echo "- $APP_CLI_PATH"; 305 | echo ""; 306 | echo "To reinstall application, run 'apache-cli-remove'"; 307 | exit; 308 | fi; 309 | } 310 | 311 | install_finish_lol() { 312 | clear; 313 | echo "$APP_CLI_NAME is installed successfuly!"; 314 | echo ""; 315 | echo "Here is available tools list:"; 316 | echo "'create-host' - Create a new virtual host"; 317 | echo "'delete-host' - Remove a virtual host"; 318 | echo "'edit-host' - Edit configuration for the host"; 319 | echo "'apache-cli-remove' - Uninstall $APP_CLI_NAME"; 320 | echo ""; 321 | } 322 | 323 | main() { 324 | clear 325 | checkBinDir; 326 | checkIfInstalled; 327 | echo "Wellcome to $APP_CLI_NAME Installer"; 328 | echo ""; 329 | setConfig; 330 | } 331 | 332 | main; 333 | -------------------------------------------------------------------------------- /linux-common/resources/act-loc-redirect: -------------------------------------------------------------------------------- 1 | address=/.loc/127.0.0.1 2 | address=/.dev/127.0.0.1 -------------------------------------------------------------------------------- /ubuntu/apache-cli/apache-cli-remove: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # absolute path to this script. Works for OSX, Linux and BSD 3 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 4 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 5 | UBUNTU_DNSMASQ_PATH='/etc/NetworkManager/dnsmasq.d'; 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | XAPPDIR="$SCRIPTPATH"; 11 | 12 | # Bin path (empty) 13 | BIN_PATH=''; 14 | 15 | checkBinDir() { 16 | if [ -d '/usr/local/bin' ]; then 17 | BIN_PATH='/usr/local/bin'; 18 | else 19 | BIN_PATH='/usr/bin'; 20 | fi 21 | } 22 | 23 | x_cli_uninstall() { 24 | rm_masq; 25 | 26 | x_rm_bin 'create-host'; 27 | x_rm_bin 'delete-host'; 28 | x_rm_bin 'edit-host'; 29 | x_rm_bin 'apache-cli-remove'; 30 | 31 | sudo rm -rf "$XAPPDIR"; 32 | } 33 | 34 | function x_rm_bin { 35 | sudo rm -f "$BIN_PATH/$1"; 36 | sudo rm -f "$XAPPDIR/$1"; 37 | } 38 | 39 | rm_masq() { 40 | if [ -f "$UBUNTU_DNSMASQ_PATH/act-loc-redirect" ]; then 41 | sudo rm -f "$UBUNTU_DNSMASQ_PATH/act-loc-redirect"; 42 | sudo service network-manager restart; 43 | fi; 44 | } 45 | 46 | checkBinDir; 47 | 48 | read -p "Remove $APP_CLI_NAME [y/n] ? " rmhosts; 49 | if [ "$rmhosts" = "y" ]; then 50 | x_cli_uninstall; 51 | else 52 | exit; 53 | fi; -------------------------------------------------------------------------------- /ubuntu/apache-cli/create-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | 11 | # Check args count 12 | if [ $# -eq 0 ] 13 | then 14 | echo "$APP_CLI_NAME v$APP_CLI_VER"; 15 | echo "Create a new virtual host"; 16 | echo " Usage: $0 'hostname'"; 17 | exit 1; 18 | fi 19 | 20 | # params 21 | conf_p="$DIR_CONF" 22 | conf_ext=".conf" 23 | conf_file="$conf_p/$1$conf_ext" 24 | 25 | # owner 26 | own_name="$USR_NAME"; 27 | own_grp="$USR_GROUP"; 28 | 29 | HOST_OWN="$USR_NAME:$USR_GROUP"; 30 | if [ "$USR_GROUP" = "root" ]; then 31 | HOST_OWN="$USR_NAME"; 32 | fi; 33 | 34 | # Sites path 35 | www_path="$DIR_HOSTS/hosts" 36 | 37 | # folder with html files 38 | public_html="public_html" 39 | 40 | host_path="$www_path/$1" 41 | 42 | # check hosts path 43 | if [ ! -d "$DIR_HOSTS" ]; then 44 | sudo mkdir -p "$DIR_HOSTS"; 45 | sudo chmod 777 "$DIR_HOSTS"; 46 | fi; 47 | 48 | # create host path 49 | sudo mkdir -p "$host_path"; 50 | sudo mkdir "$host_path/$public_html"; 51 | 52 | # permissions 53 | sudo chmod 777 "$host_path" 54 | sudo chmod 777 "$host_path/$public_html"; 55 | 56 | # ownership 57 | sudo chown "$HOST_OWN" "$host_path"; 58 | sudo chown "$HOST_OWN" "$host_path/$public_html"; 59 | 60 | echo "* Host directory: $host_path"; 61 | echo "* Documents root: '$host_path/$public_html'"; 62 | # Test index.php 63 | echo '' > "$host_path/$public_html/index.php"; 64 | 65 | # Create config 66 | sudo cp "$SCRIPTPATH/example.conf" "$conf_file"; 67 | 68 | function repl_args { 69 | sed -i -e "s#%$1%#$2#g" "$conf_file"; 70 | } 71 | 72 | # replace hostname 73 | # sed -i -e "s#%HOSTRING%#$1#g" "$conf_file"; 74 | repl_args "HOSTRING" "$1"; 75 | repl_args "HOSTPATH" "$DIR_HOSTS"; 76 | 77 | # Enable site 78 | sudo a2ensite "$1" >/dev/null 2>&1; 79 | 80 | echo "* Host config: $conf_file"; 81 | echo "Configuration and directory for host '$1' were created successfuly"; 82 | echo "To edit configuration, run 'edit-host $1'"; 83 | echo "To apply changes, run 'sudo apachectl restart'"; 84 | -------------------------------------------------------------------------------- /ubuntu/apache-cli/delete-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | # Check args count 11 | if [ $# -eq 0 ] 12 | then 13 | echo "$APP_CLI_NAME v$APP_CLI_VER"; 14 | echo "Delete a virtual host"; 15 | echo " Usage: $0 'hostname'"; 16 | exit 1; 17 | fi 18 | 19 | # params 20 | conf_p="$DIR_CONF" 21 | conf_ext=".conf" 22 | conf_file="$conf_p/$1$conf_ext" 23 | 24 | # Sites path 25 | www_path="$DIR_HOSTS/hosts" 26 | 27 | # folder with html files 28 | public_html="public_html" 29 | 30 | host_path="$www_path/$1" 31 | 32 | XSUCCESS='true'; 33 | if [ ! -f "$conf_file" ]; then 34 | echo "WARNING! Virtual host '$1' not exists. Configuration file '$conf_file' not found."; 35 | XSUCCESS='false'; 36 | else 37 | # Disable site 38 | sudo a2dissite "$1" >/dev/null 2>&1; 39 | # delete config 40 | sudo rm -f "$conf_file"; 41 | fi; 42 | 43 | 44 | if [ -d "$host_path" ]; then 45 | read -p "Delete host directory content? [y/n]: " rmdir; 46 | if [ "$rmdir" = "y" ]; then 47 | # delete host path 48 | sudo rm -rf "$host_path"; 49 | fi; 50 | else 51 | echo "WARNING! Virtual host directory not exists: '$host_path'."; 52 | XSUCCESS='false'; 53 | fi; 54 | 55 | 56 | if [ "$XSUCCESS" = 'true' ]; then 57 | echo "Configuration and directory for host '$1' were removed successfuly"; 58 | else 59 | echo "Virtual host '$1' was removed, but with errors."; 60 | fi; 61 | 62 | echo "To apply changes, run 'sudo apachectl restart'"; 63 | -------------------------------------------------------------------------------- /ubuntu/apache-cli/edit-host: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # absolute path to this script. Works for OSX, Linux and BSD 4 | SCRIPTPATH=$(perl -MCwd=realpath -e "print realpath '$0'") 5 | SCRIPTPATH=$(dirname "$SCRIPTPATH"); 6 | 7 | # Include config 8 | source "$SCRIPTPATH/config.sh"; 9 | 10 | 11 | conf_p="$DIR_CONF" 12 | conf_ext=".conf" 13 | sudo "$CONF_EDITOR" "$conf_p/$1$conf_ext"; 14 | -------------------------------------------------------------------------------- /ubuntu/apache-cli/example.conf: -------------------------------------------------------------------------------- 1 | # This file was generated by Apache CLI Tools 2 | # 2016 (c) Denis Sedchenko [http://github.com/odin3] 3 | # 4 | # Configuration for host '%HOSTRING%' 5 | 6 | 7 | # Host URL 8 | ServerName www.%HOSTRING% 9 | ServerAlias %HOSTRING% 10 | ServerAdmin info@%HOSTRING% 11 | 12 | # Path to document root 13 | DocumentRoot %HOSTPATH%/hosts/%HOSTRING%/public_html 14 | 15 | 16 | # Directory index 17 | DirectoryIndex index.html index.htm index.php 18 | # Allow .htaccess 19 | AllowOverride All 20 | # Access 21 | Order allow,deny 22 | Allow from all 23 | # New directive needed in Apache 2.4.3: 24 | Require all granted 25 | 26 | 27 | # Error logs 28 | ErrorLog %HOSTPATH%/hosts/%HOSTRING%/error.log 29 | CustomLog %HOSTPATH%/hosts/%HOSTRING%/requests.log combined 30 | -------------------------------------------------------------------------------- /ubuntu/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # OSX Document Root 4 | OSX_WWW='/Library/WebServer'; 5 | 6 | # Rest UNIX 7 | REST_WWW='/var/www'; 8 | 9 | 10 | # Debian's Apache conf dir 11 | DEB_CONF='/etc/apache2/sites-available'; 12 | 13 | # Rest 14 | REST_CONF='/etc/httpd'; 15 | 16 | # Default location 17 | APP_CLI_PATH='/etc/apache-cli'; 18 | 19 | # Product name 20 | APP_CLI_NAME='Apache Toolkit'; 21 | 22 | # App conf file name 23 | APP_CONF_NAME='config.sh'; 24 | 25 | # Bin path (empty) 26 | BIN_PATH=''; 27 | 28 | # Apache CLI version 29 | APP_CLI_VER='1.1-ubuntu'; 30 | 31 | UBUNTU_DNSMASQ_PATH='/etc/NetworkManager/dnsmasq.d'; 32 | 33 | SCRIPTPATH=$(cd "$(dirname "$0")"; pwd); 34 | 35 | USERNAME=$(whoami); 36 | 37 | 38 | setEditor() { 39 | echo '5. Enter name of default text editor for hosts ("vi" by default) or leave empty for default value.'; 40 | read -p "Edit .conf files with: " DEF_EDITOR; 41 | if [ -z "$DEF_EDITOR" ]; then 42 | DEF_EDITOR='vi'; 43 | echo "- Default editor used - 'vi'"; 44 | fi; 45 | echo ""; 46 | checkConfig; 47 | } 48 | 49 | checkBinDir() { 50 | if [ -d '/usr/local/bin' ]; then 51 | BIN_PATH='/usr/local/bin'; 52 | else 53 | BIN_PATH='/usr/bin'; 54 | fi; 55 | } 56 | 57 | setConfig() { 58 | echo "1. Enter the path to apache configs folder (usualy '/etc/apache2/sites-enabled' or '/etc/httpd') or leave empty for autodetect" 59 | echo ""; 60 | promptConfig; 61 | } 62 | 63 | detectConfPath() { 64 | echo '- Setup is trying to detect the path to config folder...'; 65 | if [ -d "$DEB_CONF" ]; then 66 | DIR_CONFIG="$DEB_CONF"; 67 | confDetected; 68 | elif [ -d "$REST_CONF" ]; then 69 | DIR_CONFIG="$REST_CONF"; 70 | confDetected; 71 | else 72 | echo "Cannot detect path, enter the path to Apache config folder:" 73 | promptConfig; 74 | fi; 75 | } 76 | 77 | 78 | 79 | 80 | 81 | confDetected() { 82 | echo "- Apache config path detected: $DIR_CONFIG"; 83 | setHostsPath; 84 | } 85 | 86 | detectHostsPath() { 87 | echo '- Setup is trying to detect the path to apache 'www' folder...'; 88 | if [ -d "$REST_WWW" ]; then 89 | DIR_HOSTS="$REST_WWW"; 90 | wwwDetectSuccess; 91 | elif [ -d "$OSX_WWW" ]; then 92 | DIR_HOSTS="$OSX_WWW"; 93 | wwwDetectSuccess; 94 | else 95 | echo "- Setup can't find Apache 'www' folder :("; 96 | promptHosts; 97 | fi; 98 | } 99 | 100 | wwwDetectSuccess() { 101 | echo "- Apache 'www' folder detected: $DIR_HOSTS"; 102 | checkIfHostsEmpty; 103 | } 104 | 105 | checkIfHostsEmpty() { 106 | if [ -d "$DIR_HOSTS/hosts" ]; then 107 | echo "- Selected folder already has 'hosts' folder: $DIR_HOSTS"; 108 | askRemoveHosts; 109 | else 110 | setUser; 111 | fi; 112 | } 113 | 114 | 115 | askRemoveHosts() { 116 | echo -n "Rename 'hosts' to 'hosts_old' [y/n] ? "; 117 | read -r rmhosts; 118 | if [ -z "$rmhosts" ]; then 119 | askRemoveHosts; 120 | elif [ "$rmhosts" = "y" ]; then 121 | sudo mv "$DIR_HOSTS/hosts" "$DIR_HOSTS/hosts_old"; 122 | DIR_HOSTS='/var/www'; 123 | setUser; 124 | elif [ "$rmhosts" = "n" ]; then 125 | setHostsPath; 126 | else 127 | echo "'y' or 'n' only allowed."; 128 | askRemoveHosts; 129 | fi; 130 | } 131 | 132 | promptConfig() { 133 | read -p 'Apache config path: ' DIR_CONFIG 134 | if [ -z "$DIR_CONFIG"]; then 135 | detectConfPath; 136 | elif [ ! -d "$DIR_CONFIG" ]; then 137 | echo "Path not found, try again:"; 138 | promptConfig; 139 | else 140 | setHostsPath; 141 | fi; 142 | } 143 | 144 | setHostsPath() { 145 | echo "2. Enter the path for virtual hosts folder (or leave empty for default value)" 146 | promptHosts 147 | } 148 | 149 | promptHosts() { 150 | read -p "Folder for hosts directory: " DIR_HOSTS 151 | if [ -z "$DIR_HOSTS" ]; then 152 | detectHostsPath; 153 | elif [ ! -d "$DIR_HOSTS" ]; then 154 | echo "Path not found, try again:"; 155 | promptHosts; 156 | else 157 | checkIfHostsEmpty; 158 | fi; 159 | } 160 | 161 | checkUserName() { 162 | grep "$USR_NAME" /etc/passwd 163 | if [ $? -ne 0 ]; 164 | then 165 | echo "- WARNING! Username $USR_NAME doesn't exists."; 166 | fi 167 | } 168 | 169 | setUser() { 170 | echo "3. Enter username for hosts folder ownership (or leave empty for current user):" 171 | read -p "Username: " USR_NAME 172 | if [ -z "$USR_NAME" ]; then 173 | USR_NAME="$USERNAME"; 174 | setGroup; 175 | else 176 | checkUserName; 177 | fi; 178 | } 179 | 180 | setGroup() { 181 | echo "4. Enter also group name for folder owner (or leave empty for the same as user name)." 182 | echo " TIP: We recommend to use 'wheel' group in case if you're sudo user."; 183 | echo ""; 184 | promptGrp; 185 | } 186 | 187 | promptGrp() { 188 | read -p 'Group name: ' USR_GROUP; 189 | if [ -z "$USR_GROUP" ]; then 190 | USR_GROUP="$USR_NAME"; 191 | fi; 192 | setEditor; 193 | } 194 | 195 | promptDnsMask() { 196 | clear; 197 | if [ -d "$UBUNTU_DNSMASQ_PATH" ]; then 198 | echo "- Found local dnsmasq on '$UBUNTU_DNSMASQ_PATH'"; 199 | echo "For development we recommend purposes can install DNS mask for '.loc' and '.dev' tld domains."; 200 | echo "All subdomains will be binded to 127.0.0.1"; 201 | askDnsMask; 202 | else 203 | installNow; 204 | fi; 205 | } 206 | 207 | applyDnsmasq() { 208 | if [ -f "$SCRIPTPATH/resources/act-loc-redirect" ]; then 209 | sudo cp "$SCRIPTPATH/resources/act-loc-redirect" "$UBUNTU_DNSMASQ_PATH"; 210 | echo "- Mask file installed: $UBUNTU_DNSMASQ_PATH/act-loc-redirect"; 211 | echo "- Restarting network-manager to apply changes..."; 212 | sudo service network-manager restart; 213 | sleep 1; 214 | installNow; 215 | else 216 | echo "WARNING: File not found - $SCRIPTPATH/resources/act-loc-redirect"; 217 | sleep 1; 218 | installNow; 219 | fi; 220 | } 221 | 222 | askDnsMask() { 223 | read -p 'Install DNS mask [y/n] ? ' usemasq; 224 | if [ -z "$usemasq" ]; then 225 | askDnsMask; 226 | elif [ "$usemasq" = "y" ]; then 227 | applyDnsmasq; 228 | else 229 | installNow; 230 | fi; 231 | } 232 | 233 | checkConfig() { 234 | clear; 235 | echo "Please check your configuration:"; 236 | echo ""; 237 | echo " ** LOCATION ** " 238 | echo " - Apache configuration path:"; 239 | echo " $DIR_CONFIG"; 240 | echo " - Path for virtual hosts folder:"; 241 | echo " $DIR_HOSTS"; 242 | echo " - Virtual hosts will be stored in:"; 243 | echo " $DIR_HOSTS/hosts"; 244 | echo ""; 245 | echo " ** FOLDERS OWNERSHIP ** "; 246 | echo " - Default user owner for hosts:"; 247 | echo " $USR_NAME"; 248 | echo " - Default group owner for hosts:"; 249 | echo " $USR_GROUP"; 250 | echo ""; 251 | echo "** ETC **"; 252 | echo " - Default .conf editor:"; 253 | echo " $DEF_EDITOR"; 254 | echo ""; 255 | echo ""; 256 | askCheckCfg; 257 | } 258 | 259 | askCheckCfg() { 260 | read -p 'Is it OK [y/n] ? ' rmhosts; 261 | if [ "$rmhosts" = "y" ]; then 262 | promptDnsMask; 263 | elif [ "$rmhosts" = "n" ]; then 264 | echo "- Setup will be restarted from the beginning..."; 265 | sleep 1; 266 | main; 267 | else 268 | echo "'y' or 'n' only allowed."; 269 | askCheckCfg; 270 | fi; 271 | } 272 | 273 | 274 | installNow() { 275 | clear; 276 | echo "**** Installing $APP_CLI_NAME ****"; 277 | echo ""; 278 | 279 | copyApp; 280 | 281 | chmodBins; 282 | 283 | smlink 'create-host'; 284 | smlink 'delete-host'; 285 | smlink 'edit-host'; 286 | smlink 'apache-cli-remove'; 287 | # smlink 'apache-cli-config.sh'; 288 | 289 | genConfig; 290 | 291 | sleep 1; 292 | echo ''; 293 | echo ''; 294 | install_finish_lol; 295 | 296 | } 297 | 298 | genConfig() { 299 | echo ' - Generating configuration...'; 300 | sudo printf "#!/bin/bash\n\n" > "$APP_CLI_PATH/$APP_CONF_NAME"; 301 | sudo printf "# $APP_CLI_NAME [$APP_CLI_VER] CONFIGURATION\n" >> "$APP_CLI_PATH/$APP_CONF_NAME"; 302 | 303 | conf_set 'APP_CLI_VER' "$APP_CLI_VER"; 304 | conf_set 'APP_CLI_NAME' "$APP_CLI_NAME"; 305 | conf_set 'DIR_CONF' "$DIR_CONFIG"; 306 | conf_set 'DIR_HOSTS' "$DIR_HOSTS"; 307 | conf_set 'USR_NAME' "$USR_NAME"; 308 | conf_set 'USR_GROUP' "$USR_GROUP"; 309 | conf_set 'CONF_EDITOR' "$DEF_EDITOR"; 310 | } 311 | 312 | function conf_set { 313 | sudo printf "$1=\"$2\"\n" >> "$APP_CLI_PATH/$APP_CONF_NAME"; 314 | } 315 | 316 | 317 | copyApp() { 318 | echo ' - Copying binaries...'; 319 | sudo cp -rf "$SCRIPTPATH/apache-cli" "$APP_CLI_PATH"; 320 | } 321 | 322 | 323 | 324 | chmodBins() { 325 | echo ' - Applying permissions...'; 326 | sudo chmod 777 "$APP_CLI_PATH"; 327 | } 328 | 329 | 330 | function smlink { 331 | echo " - Creating symlink: " 332 | echo " '$APP_CLI_PATH/$1' -> '$BIN_PATH/$1'"; 333 | sudo ln -s "$APP_CLI_PATH/$1" "$BIN_PATH/$1"; 334 | } 335 | 336 | 337 | 338 | 339 | 340 | checkIfInstalled() { 341 | if [ -d "$APP_CLI_PATH" ]; then 342 | echo "$APP_CLI_NAME is already installed in:"; 343 | echo "- $APP_CLI_PATH"; 344 | echo ""; 345 | echo "To reinstall application, run 'apache-cli-remove'"; 346 | exit; 347 | fi; 348 | } 349 | 350 | install_finish_lol() { 351 | clear; 352 | echo "$APP_CLI_NAME is installed successfuly!"; 353 | echo ""; 354 | echo "Here is available tools list:"; 355 | echo "'create-host' - Create a new virtual host"; 356 | echo "'delete-host' - Remove a virtual host"; 357 | echo "'edit-host' - Edit configuration for the host"; 358 | echo "'apache-cli-remove' - Uninstall $APP_CLI_NAME"; 359 | echo ""; 360 | } 361 | 362 | main() { 363 | clear 364 | checkBinDir; 365 | checkIfInstalled; 366 | echo "Wellcome to $APP_CLI_NAME Installer"; 367 | echo ""; 368 | setConfig; 369 | } 370 | 371 | main; 372 | -------------------------------------------------------------------------------- /ubuntu/resources/act-loc-redirect: -------------------------------------------------------------------------------- 1 | address=/.loc/127.0.0.1 2 | address=/.dev/127.0.0.1 --------------------------------------------------------------------------------