summaryrefslogtreecommitdiff
path: root/backend/update.py
blob: ebf82bfab8c17df958072c9e6d76f7516560838c (plain)
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
#!/usr/bin/env python2

import os
import sys


############### Enumerate dependencies

found_git = (os.system("git status --porcelain") == 0)

if not found_git:
  print("ERROR: git not found")
  exit(1)

found_ikiwiki = (os.system("ikiwiki --version") == 0)
found_gitocalypse = (os.system("git-remote-freenet") == 256)
found_freesitemgr = (os.system("freesitemgr --version") == 0)
found_zeronet = 'ZERONETDIR' in os.environ
if found_zeronet:
  zn_datadir = os.path.join(os.environ['ZERONETDIR'], 'ZeroNet/data')
  zn_script = os.path.join(os.environ['ZERONETDIR'], 'ZeroNet.sh')
  found_zeronet = (os.system("'%s' --version" % zn_script) == 0)

if not found_ikiwiki:
  print("WARNING: ikiwiki not found, pages will not be built")
if not found_gitocalypse:
  print("WARNING: gitocalypse not found, changes won't be synced with freenet")
if not found_freesitemgr:
  print("WARNING: freesitemgr/pyFreenet not found, public freesite won't be updated")
if not found_zeronet:
  print("WARNING: ZeroNet not found in ZERONETDIR, public zeronet site won't be updated")

if not (found_ikiwiki or found_gitocalypse or found_freesitemgr):
  print("Changes will still be propagated if branchable is working.")


####################### Download from all

print(":: Pulling from simple repos ...")
os.environ["GIT_SSH_COMMAND"] = "ssh -F backend/auth/ssh-config"

status = 0
status += os.system("git pull git://standingwithresilience.branchable.com/ master")

if status != 0:
  print("WARNING: failed to pull changes from branchable")
  #exit(status)

status += os.system("git pull fairlystable-guest:/srv/git/standingwithresilience master")

if status != 0:
  print("WARNING: failed to pull changes from fairlystable")
  #exit(status)

del os.environ["GIT_SSH_COMMAND"]


# Pull from zeronet repos
print(":: Pulling from zeronet repos ...")
# public zeronet
os.system("git pull http://127.0.0.1:43110/1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4/.git master")
# private zeronet
os.system("git pull http://127.0.0.1:43110/1L363bqJnCG63SnV83kfV7izZXbmentctD/.git master")


# Pull from freenet repos
if found_gitocalypse:
  print(":: Pulling from freenet repos ...")
  # public freenet
  os.system("git pull freenet://USK@hCLgfaINNSNAl4do-PapEincQP5Lxa72d8mFrzHqzqU,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQACAAE/Standing%20With%20Resilience%20Public.git.R1/0 master")
  # private freenet
  os.system("git pull freenet://USK@PSY0YngeDtGbj60hjEoilQiY9oKzVrptRC0rG4BEVPg,e6ZEjT4KvbsltPBJOeKNpIdty2oGzbLCdk4fsDA5Vdk,AQACAAE/Standing%20With%20Resilience.git.R1/0 master")



######################### Upload to all

print(":: Pushing to simple repos ...")
os.environ["GIT_SSH_COMMAND"] = "ssh -F backend/auth/ssh-config"

status += os.system("git push git://standingwithresilience.branchable.com/")
status += os.system("git push fairlystable-guest:/srv/git/standingwithresilience")

del os.environ["GIT_SSH_COMMAND"]


# Push to freenet repos
if found_gitocalypse:
  print (":: Pushing to freenet repos ...")
  # public freenet
  os.system("git push freenet://USK@AKL0griFs7T25yw6-JR3Wk7vocvNBelOLg3RwtIL6aTp,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQECAAE/Standing%20With%20Resilience%20Public.git.R1/0")


# Build wiki

if status != 0:
  print (":: Exiting due to failure")
  exit(status)

if not found_ikiwiki:
  print (":: Not building wiki; missing ikiwiki")
  exit(0)

print (":: Building wiki ...")

status += os.system("ikiwiki --wikiname 'A Wiki for Targeted Individuals' --rebuild ../wiki ../html")

if status != 0:
  print (":: Exiting due to failure")
  exit(status)

if found_zeronet:
  os.system('git update-server-info')
  print (":: Publishing ZeroNet site ...")
  zn_datadir = os.path.join(zn_datadir, '1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4')
  os.system('cp -r ../html/. %s/.' % zn_datadir)
  os.system('mkdir -p %s/.git' % zn_datadir)
  for file in ('objects', 'refs', 'HEAD', 'info', 'packed-refs'):
    os.system('cp -a ../.git/%s %s/.git' % (file, zn_datadir))
  os.system('%s siteSign 1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4 5JzZACCELsT4bx66qmV9JDaWhEQ6Sx6j7LzeucsxJGA9H7nuoRr' % zn_script)

if found_freesitemgr:
  print (":: Publishing freesite ...")
  status += os.system("freesitemgr -c freesitemgr -v -l freesitemgr.log -r 1 update")

print "Done."

exit(status)