12.03
I just came across a script I have totally forgotten about, which I wrote quite a while ago.
I haven’t managed to write a real documentation so far… anyway… feel free to try it.
All you need to do, is to install php in case you haven’t done it already!
SRCD/HTTP Synchronizer (1.9 KiB, 259 hits)
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | #! /bin/php <?PHP /* SRCDS FastDownload Syncronizer Version: 1.0 Author: Andreas Glaser (JaZz) www.andreas-glaser.com */ ############################* # Variables (DO NOT TOUCH): # $Config = array(); $Files = array(); ############################* # Configuration (Required): # // :: CONFIG // :: CONFIG ~ BZIP2 $Config['Bzip2']['Enabled'] = true; // Enable or diable bzip2 compression $Config['Bzip2']['Path'] = '/bin/bzip2'; // Path to Bzip2 (default: /bin/bzip2) $Config['Htdocs']['Delete'] = false; // Determines whether obsolete files in the webdirectory beeing deleted $Config['Htdocs']['Override'] = false; // Determines if every time you synchonize your directories the file gonna be overriden $Config['Chmod']['Enabled'] = true; // Enable or disable to set new RWX rights $Config['Chmod']['Access'] = '755'; // Sets the new $Config['Chmod']['Path'] = '/bin/chmod'; // Path of Chmod $Config['Chown']['Enabled'] = true; // Determines if you like to set a new user for the synchonizes web files $Config['Chown']['User'] = 'web001'; // Owner of the synchronized files $Config['Chown']['Group'] = 'web'; // Group of the synchronized files $Config['Chown']['Path'] = '/bin/chown'; // Path to Chown // :: CONFIG ~ PATHS $Config['Paths']['cstrike'] = '/path/to/your/srcds/'; // Path to your CounterStrike Server $Config['Paths']['htdocs'] = '/path/to/your/htcods/fastdl/'; // Path to your web directory $Config['Paths']['syn_dirs'][] = 'maps'; // Directoriyto synchronize $Config['Paths']['syn_dirs'][] = 'materials'; // Directory to synchronize $Config['Paths']['syn_dirs'][] = 'models'; // Directory to synchronize $Config['Paths']['syn_dirs'][] = 'resource'; // Directory to synchronize $Config['Paths']['syn_dirs'][] = 'sound'; // Directory to synchronize // :: Config Check (DO NOT TOUCH) @exec('whoami', $Output); if ($Output[0] !== 'root') { exit('Error: You must be logged in as root'."\n"); } file_exists($Config['Paths']['cstrike']) && is_dir($Config['Paths']['cstrike']) or exit('Error: The selected cstrike directory does not exist'."\n"); file_exists($Config['Paths']['htdocs']) && is_dir($Config['Paths']['htdocs']) or exit('Error: The selected htdocs directory does not exist'."\n"); if ($Config['Bzip2']['Enabled'] === true) { file_exists($Config['Bzip2']['Path']) or exit('Error: Bzip2 was not found on your system'."\n"); } if ($Config['Chmod']['Enabled'] === true) { file_exists($Config['Chmod']['Path']) or exit('Error: Chmod was not found on your system'."\n"); } if ($Config['Chown']['Enabled'] === true) { file_exists($Config['Chown']['Path']) or exit('Error: Chown was not found on your system'."\n"); } foreach ($Config['Paths']['syn_dirs'] AS $Key => $Val) { file_exists($Config['Paths']['cstrike'].$Val.'/') or exit("\n".$Val.' does not exist'."\n"); } foreach ($Config['Paths']['htdocs'] AS $Key => $Val) { file_exists($Config['Paths']['cstrike'].$Val.'/') or exit("\n".$Val.' does not exist'."\n"); } // :: Do it (DO NOT TOUCH) echo "\n".'<<< START SYNCHRONIZATION >>>'."\n"; foreach ($Config['Paths']['syn_dirs'] AS $Key => $Val) { indexCstrike($Config['Paths']['cstrike'], $Val); } if ($Config['Htdocs']['Delete'] === true) { indexHtdocs($Config['Paths']['htdocs']); // :: Delete needless files in htdocs foreach ($Files['HTDOCS']['FILES'] AS $Key => $Val) { $SubDir = substr($Key, strlen($Config['Paths']['htdocs'])); if ($Config['Bzip2']['Enabled'] === true) { if (substr($SubDir, - 4) == '.bz2') { $SubDir = substr($SubDir, 0, - 4); } } if (!isset($Files['CSTRIKE']['FILES'][$Config['Paths']['cstrike'].$SubDir])) { unlink($Config['Paths']['htdocs'].$SubDir); } } // :: Delete needless directories in htdocs foreach ($Files['HTDOCS']['DIRS'] AS $Key => $Val) { $SubDir = substr($Key, strlen($Config['Paths']['htdocs'])); if ($Config['Paths']['htdocs'].$SubDir !== $Config['Paths']['htdocs']) { if (!isset($Files['CSTRIKE']['DIRS'][$Config['Paths']['cstrike'].$SubDir])) { rmdir($Config['Paths']['htdocs'].$SubDir); } } } } // :: Sync Directories foreach ($Files['CSTRIKE']['DIRS'] AS $Key => $Val) { $SubDir = substr($Val, strlen($Config['Paths']['cstrike']), - 1); if (!file_exists($Config['Paths']['htdocs'].$SubDir)) { mkdir($Config['Paths']['htdocs'].$SubDir, 0777); } } // :: Sync Files $tmp_Counter = 0; foreach ($Files['CSTRIKE']['FILES'] AS $Key => $Val) { if ($tmp_Counter !== 0 && ($tmp_Counter % 4) === 0) { echo '.'; } $tmp_Counter++; $SubDir = substr($Key, strlen($Config['Paths']['cstrike'])); if (!file_exists($Config['Paths']['htdocs'].$SubDir.'.bz2')) { if (!file_exists($Config['Paths']['htdocs'].$SubDir)) { copy($Key, $Config['Paths']['htdocs'].$SubDir); if ($Config['Bzip2']['Enabled'] === true) { $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal); } } else { if ($Config['Htdocs']['Override'] === true || $Val['Size'] !== filesize($Config['Paths']['htdocs'].$SubDir)) { unlink($Config['Paths']['htdocs'].$SubDir); copy($Key, $Config['Paths']['htdocs'].$SubDir); if ($Config['Bzip2']['Enabled'] === true) { $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal); } } else { if ($Config['Bzip2']['Enabled'] === true) { $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal); } } } } else { if ($Config['Htdocs']['Override'] === true && $Config['Bzip2']['Enabled'] === true) { unlink($Config['Paths']['htdocs'].$SubDir.'.bz2'); copy($Key, $Config['Paths']['htdocs'].$SubDir); $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal); } } } unset($tmp_Counter); if ($Config['Chmod']['Enabled'] === true) { system('chmod -R '.$Config['Chmod']['Access'].' '.$Config['Paths']['htdocs'], $RetVal); } if ($Config['Chown']['Enabled'] === true) { system('chown -R '.$Config['Chown']['User'].':'.$Config['Chown']['Group'].' '.$Config['Paths']['htdocs'], $RetVal); } echo "\n".'<<< DONE >>>'."\n"; echo "\n".'| INFORMATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|'; echo "\n".'| Script: SRCDS FastDownload Syncronizer |'; echo "\n".'| Version: 1.0 |'; echo "\n".'| Author: Andreas Glaser |'; echo "\n".'| Website: www.andreas-glaser.com |'; echo "\n".'| Creation Date: 2009-01-14 |'; echo "\n".'| Last Update: 2009-01-14 |'; echo "\n".'|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|'."\n"; function indexCstrike($Dir = NULL, $SubDir = 'subdir') { global $Files; $Dir = $Dir.$SubDir.'/'; $Files['CSTRIKE']['DIRS'][$Dir] = $Dir; if (file_exists($Dir)) { $handler = opendir($Dir); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { if (!is_dir($Dir.$file)) { $Files['CSTRIKE']['FILES'][$Dir.$file]['Size'] = filesize($Dir.$file); } else { indexCstrike($Dir, $file); } } } closedir($handler); } } function indexHtdocs($Dir = NULL, $SubDir = 'subdir') { global $Files; if ($SubDir !== 'subdir') { $Dir = $Dir.$SubDir.'/'; } $Files['HTDOCS']['DIRS'][$Dir] = $Dir; if (file_exists($Dir)) { $handler = opendir($Dir); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { if (!is_dir($Dir.$file)) { $Files['HTDOCS']['FILES'][$Dir.$file]['Size'] = filesize($Dir.$file); } else { indexHtdocs($Dir, $file); } } } closedir($handler); } } ?> |
SRCD/HTTP Synchronizer (1.9 KiB, 259 hits)
JaZz
No Comment.
Add Your Comment