diff --git a/setup/owncloud.sh b/setup/owncloud.sh index 65903220..5753a7da 100755 --- a/setup/owncloud.sh +++ b/setup/owncloud.sh @@ -5,6 +5,8 @@ source setup/functions.sh # load our functions source /etc/mailinabox.conf # load global vars +# ### Installing ownCloud + apt_install \ dbconfig-common \ php5-cli php5-sqlite php5-gd php5-imap php5-curl php-pear php-apc curl libapr1 libtool libcurl4-openssl-dev php-xml-parser \ @@ -12,7 +14,7 @@ apt_install \ apt-get purge -qq -y owncloud* -# Install ownCloud from source +# Install ownCloud from source of this version: owncloud_ver=7.0.2 # Check if ownCloud dir exist, and check if version matches owncloud_ver (if either doesn't - install/upgrade) @@ -27,13 +29,15 @@ if [ ! -d /usr/local/lib/owncloud/ ] \ rm -f /tmp/owncloud.zip fi +# ### Configuring ownCloud + # Setup ownCloud if the ownCloud database does not yet exist. Running setup when # the database does exist wipes the database and user data. if [ ! -f $STORAGE_ROOT/owncloud/owncloud.db ]; then # Create a configuration file. - TIMEZONE=`cat /etc/timezone` + TIMEZONE=$(cat /etc/timezone) instanceid=oc$(echo $PRIMARY_HOSTNAME | sha1sum | fold -w 10 | head -n 1) - cat - > /usr/local/lib/owncloud/config/config.php < /usr/local/lib/owncloud/config/config.php < '$STORAGE_ROOT/owncloud', @@ -75,7 +79,7 @@ EOF # when the install script is run. Make an administrator account # here or else the install can't finish. adminpassword=$(dd if=/dev/random bs=1 count=40 2>/dev/null | sha1sum | fold -w 30 | head -n 1) - cat - > /usr/local/lib/owncloud/config/autoconfig.php < /usr/local/lib/owncloud/config/autoconfig.php </dev/null | base64 | fold -w 24 | head -n 1) @@ -43,7 +48,7 @@ SECRET_KEY=$(dd if=/dev/random bs=1 count=18 2>/dev/null | base64 | fold -w 24 | # For security, temp and log files are not stored in the default locations # which are inside the roundcube sources directory. We put them instead # in normal places. -cat - > /usr/local/lib/roundcubemail/config/config.inc.php < /usr/local/lib/roundcubemail/config/config.inc.php < div:before { + content: "$ "; + color: #666; + } @@ -123,7 +128,9 @@ class Source(Grammar): class CatEOF(Grammar): grammar = (ZERO_OR_MORE(SPACE), L('cat > '), ANY_EXCEPT(WHITESPACE), L(" <<"), OPTIONAL(SPACE), L("EOF;"), EOL, REPEAT(ANY, greedy=False), EOL, L("EOF"), EOL) def value(self): - return "
" + self[2].string + "
" + cgi.escape(self[7].string) + "
\n" + content = self[7].string + content = re.sub(r"\\([$])", r"\1", content) # un-escape bash-escaped characters + return "
overwrite
" + self[2].string + "
" + cgi.escape(content) + "
\n" class HideOutput(Grammar): grammar = (L("hide_output "), REF("BashElement")) @@ -134,7 +141,7 @@ class SuppressedLine(Grammar): grammar = (OPTIONAL(SPACE), L("echo "), REST_OF_LINE, EOL) def value(self): if "|" in self.string or ">" in self.string: - return "
" + cgi.escape(self.string) + "
\n" + return "
" + cgi.escape(self.string.strip()) + "
\n" return "" class EditConf(Grammar): @@ -143,7 +150,7 @@ class EditConf(Grammar): FILENAME, SPACE, OPTIONAL((LIST_OF( - L("-w") | L("-s"), + L("-w") | L("-s") | L("-c ';'"), sep=SPACE, ), SPACE)), REST_OF_LINE, @@ -172,7 +179,7 @@ class EditConf(Grammar): else: options[-1] += c if options[-1] == "": options.pop(-1) - return "
" + self[1].string + "
" + "\n".join(cgi.escape(s) for s in options) + "
\n" + return "
additional settings for
" + self[1].string + "
" + "\n".join(cgi.escape(s) for s in options) + "
\n" class CaptureOutput(Grammar): grammar = OPTIONAL(SPACE), WORD("A-Za-z_"), L('=$('), REST_OF_LINE, L(")"), OPTIONAL(L(';')), EOL @@ -184,25 +191,32 @@ class CaptureOutput(Grammar): class SedReplace(Grammar): grammar = OPTIONAL(SPACE), L('sed -i "s/'), OPTIONAL(L('^')), ONE_OR_MORE(WORD("-A-Za-z0-9 #=\\{};.*$_!()")), L('/'), ONE_OR_MORE(WORD("-A-Za-z0-9 #=\\{};.*$_!()")), L('/"'), SPACE, FILENAME, EOL def value(self): - return "
" + self[8].string + "

replace

" + cgi.escape(self[3].string.replace(".*", ". . .")) + "

with

" + cgi.escape(self[5].string.replace("\\n", "\n").replace("\\t", "\t")) + "
\n" + return "
edit
" + self[8].string + "

replace

" + cgi.escape(self[3].string.replace(".*", ". . .")) + "

with

" + cgi.escape(self[5].string.replace("\\n", "\n").replace("\\t", "\t")) + "
\n" + +def shell_line(bash): + return "
" + cgi.escape(wrap_lines(bash.strip())) + "
\n" class AptGet(Grammar): grammar = (ZERO_OR_MORE(SPACE), L("apt_install "), REST_OF_LINE, EOL) def value(self): - return "
" + self[0].string + "apt-get install -y " + cgi.escape(re.sub(r"\s+", " ", self[2].string)) + "
\n" + return shell_line("apt-get install -y " + re.sub(r"\s+", " ", self[2].string)) class UfwAllow(Grammar): grammar = (ZERO_OR_MORE(SPACE), L("ufw_allow "), REST_OF_LINE, EOL) def value(self): - return "
" + self[0].string + "ufw allow " + cgi.escape(self[2].string) + "
\n" + return shell_line("ufw allow " + self[2].string) +class RestartService(Grammar): + grammar = (ZERO_OR_MORE(SPACE), L("restart_service "), REST_OF_LINE, EOL) + def value(self): + return shell_line("service " + self[2].string + " restart") class OtherLine(Grammar): grammar = (REST_OF_LINE, EOL) def value(self): if self.string.strip() == "": return "" - return "
" + cgi.escape(self.string.rstrip()) + "
\n" + return "
" + cgi.escape(self.string.rstrip()) + "
\n" class BashElement(Grammar): - grammar = Comment | Source | CatEOF | SuppressedLine | HideOutput | EditConf | CaptureOutput | SedReplace | AptGet | UfwAllow | OtherLine + grammar = Comment | Source | CatEOF | SuppressedLine | HideOutput | EditConf | CaptureOutput | SedReplace | AptGet | UfwAllow | RestartService | OtherLine def value(self): return self[0].value() @@ -218,14 +232,14 @@ class BashScript(Grammar): string = open(fn).read() string = re.sub(r"\s*\\\n\s*", " ", string) string = re.sub(".* #NODOC\n", "", string) - string = re.sub("\n\s*if .*|\n\s*fi|\n\s*else", "", string) + string = re.sub("\n\s*if .*|\n\s*fi|\n\s*else|\n\s*elif .*", "", string) string = re.sub("hide_output ", "", string) result = parser.parse_string(string) v = "\n" % ("https://github.com/mail-in-a-box/mailinabox/tree/master/" + fn, fn) v += "".join(result.value()) - v = v.replace("\n
", "\n")
+		v = v.replace("
\n
", "")
 		v = re.sub("
([\w\W]*?)
", lambda m : "
" + strip_indent(m.group(1)) + "
", v) v = re.sub(r"\$?PRIMARY_HOSTNAME", "box.yourdomain.com", v) @@ -234,5 +248,19 @@ class BashScript(Grammar): return v +def wrap_lines(text, cols=60): + ret = "" + words = re.split("(\s+)", text) + linelen = 0 + for w in words: + if linelen + len(w) > cols-1: + ret += " \\\n" + ret += " " + linelen = 0 + if linelen == 0 and w.strip() == "": continue + ret += w + linelen += len(w) + return ret + if __name__ == '__main__': generate_documentation()