2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3, or later.
8 # For more information see license.txt.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Exports fossil image
16 __exedir
="$(dirname -- "$0")"
17 __tmpdir
="$("$__exedir/tmpdir.sh
")"
24 TARGET
="$__tmpdir/squirreljme.fossil"
27 # Kill previous fossil repo, if it exists
28 if [ -f "$__tmpdir/squirreljme-fossil-pid" ]
30 kill $
(cat "$__tmpdir/squirreljme-fossil-pid")
31 rm -f "$__tmpdir/squirreljme-fossil-pid"
35 INFOLINE
="$(fossil info | grep 'checkout:' | head -n 1)"
36 NOW
="$(echo "$INFOLINE" | sed 's/.*\([0-9a-fA-F]\{40\}\).*/\1/g')"
38 # Generate random port to use
39 PORT
="$(expr $(expr $$ % 32765) + 32765)"
41 # Sadfully, a local repo cannot be cloned to a new one (it is treated as
43 echo "Serving local copy to clone it..." 1>&2
44 fossil serve
-P $PORT &
46 echo $FOSSILPID > "$__tmpdir/squirreljme-fossil-pid"
47 fossil clone
-A squirreljme
"http://127.0.0.1:$PORT" \
51 rm -f -- "$__tmpdir/squirreljme-fossil-pid"
53 # If target exists, Do a compressed rebuild
54 if [ -f "$__tmpdir/$$.fsl" ]
56 # Sync unversioned files
57 fossil unversioned sync
"$__tmpdir/$$.fsl" --once
59 # Set difficult to use password to discourage people
60 echo "Setting a random password..." 1>&2
61 RPASS
="$("$__exedir/random.sh
" 24)"
62 echo "which is: '$RPASS'" 1>&2
63 fossil user password squirreljme
"$RPASS" -R "$__tmpdir/$$.fsl"
64 fossil user default squirreljme
-R "$__tmpdir/$$.fsl"
66 # Modify default permissions to make them a bit strong a bit
67 # Anonymous logins can spam the ticket or wiki system, which is an exploit
68 # provided they know how to cut and paste a password.
69 echo "Changing permissions..." 1>&2
70 CAPANON
="$(fossil user capabilities anonymous -R "$__tmpdir/$$.fsl
")"
71 CAPDEVE
="$(fossil user capabilities developer -R "$__tmpdir/$$.fsl
")"
72 CAPNOBO
="$(fossil user capabilities nobody -R "$__tmpdir/$$.fsl
")"
73 CAPREAD
="$(fossil user capabilities reader -R "$__tmpdir/$$.fsl
")"
77 echo "nobody was: $CAPNOBO" 1>&2
79 fossil user capabilities nobody
$CAPNOBO -R "$__tmpdir/$$.fsl"
80 echo "Now: $CAPNOBO" 1>&2
82 # Anon (same as nobody)
83 echo "anonymous was: $CAPANON" 1>&2
85 fossil user capabilities anonymous
$CAPANON -R "$__tmpdir/$$.fsl"
86 echo "Now: $CAPANON" 1>&2
89 echo "reader was: $CAPREAD" 1>&2
90 CAPREAD
="kptwhmnczgjor"
91 fossil user capabilities reader
$CAPREAD -R "$__tmpdir/$$.fsl"
92 echo "Now: $CAPREAD" 1>&2
95 echo "developer was: $CAPDEVE" 1>&2
96 CAPDEVE
="deihmnczgjor"
97 fossil user capabilities developer
$CAPDEVE -R "$__tmpdir/$$.fsl"
98 echo "Now: $CAPDEVE" 1>&2
100 # Change some settings
101 echo "Changing a few settings..." 1>&2
102 # URL being set to the local clone is bad by default
103 fossil remote-url
-R "$__tmpdir/$$.fsl" off
104 fossil remote-url
-R "$__tmpdir/$$.fsl" \
105 http
://multiphasicapps.net
/
106 # Autosync to a 127.0.0.1 == Very annoying
107 fossil settings
-R "$__tmpdir/$$.fsl" autosync
0
108 # Case sensitivity (for Windows/DOS)
109 fossil settings
-R "$__tmpdir/$$.fsl" case-sensitive
1
110 # Enable the manifest so it appears in the ZIPs and such
111 fossil settings
-R "$__tmpdir/$$.fsl" manifest
1
113 # Add all of these settings
114 for __conf
in project skin shun ticket
116 fossil config push
"$__conf" "$__tmpdir/$$.fsl"
120 fossil scrub
--force --verily "$__tmpdir/$$.fsl"
123 #echo "Rebuilding..." 1>&2
124 #fossil rebuild --force --vacuum --pagesize 4096 --compress \
125 # --stats "$__tmpdir/$$.fsl"
127 # Create a ZIP file to append to the repository (note that any changes made
128 # to the repository will damage it). Although this wastes a bit of space,
129 # it is rather cool so that way you can still extract and compile the OS
130 # from the appended ZIP without needing a fossil installation.
131 echo "Exporting a ZIP of current code..." 1>&2
132 fossil
zip "$NOW" "$__tmpdir/$$.zip" --name "squirreljme" -R "$__tmpdir/$$.fsl"
134 # Compress using some algorithms
135 # Just used as a test to see how well things compress, not really that
139 # Base tar to recompress
140 fossil
tar tip
- --name "squirreljme" -R "$__tmpdir/$$.fsl" \
141 | gunzip
-c - > "$__tmpdir/$$.tar"
144 if which gzip 2> /dev
/null
> /dev
/null
146 if ! gzip -9 -v -c - < "$__tmpdir/$$.tar" > "$__tmpdir/$$.tgz"
148 rm -f "$__tmpdir/$$.tgz"
153 if which bzip2 2> /dev
/null
> /dev
/null
155 if ! bzip2 -9 -v -c - < "$__tmpdir/$$.tar" > "$__tmpdir/$$.tb2"
157 rm -f "$__tmpdir/$$.tb2"
162 if which xz
2> /dev
/null
> /dev
/null
164 if ! xz
-9 -v -c - < "$__tmpdir/$$.tar" > "$__tmpdir/$$.txz"
166 rm -f "$__tmpdir/$$.txz"
171 # Join the repository and the zip as one
172 echo "Merging the files..." 1>&2
173 cat "$__tmpdir/$$.fsl" "$__tmpdir/$$.zip" > "$TARGET"
174 ls -sh "$__tmpdir/$$."???
"$TARGET" |
sort -h
177 echo "Cleaning up..." 1>&2
178 rm -f "$__tmpdir/$$.fsl" "$__tmpdir/$$.zip" "$__tmpdir/$$.tar" "$__tmpdir/$$.tgz" \
179 "$__tmpdir/$$.txz" "$__tmpdir/$$.tb2"