-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdofile
More file actions
306 lines (268 loc) · 9.6 KB
/
dofile
File metadata and controls
306 lines (268 loc) · 9.6 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
!main install
!require python3 tar xz sed grep
!def install
ED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
FILEREGFILE="$HOME/.config/mimeapps.list"
MIMEDIR="$HOME/.local/share/mime/packages"
echo "INFO: Verifying system"
#Check program requirements
set -e
if ! command -v java &> /dev/null
then
echo "WARNING: You should probably have java if you want to set up a Minecraft server"
fi
#Set up folders
if [ "$EUID" -ne 0 ]; then
echo "WARNING: You are not running as root. Program will be installed locally."
INSTALLDIR="$HOME/.local/bin"
LIBDIR="$HOME/.local/lib/craftserversetup"
ICONDIR="$HOME/.local/share/icons"
SHORTCUTDIR="$HOME/.local/share/applications"
else
INSTALLDIR="/usr/bin"
LIBDIR="/usr/lib/craftserversetup"
ICONDIR="/usr/share/pixmaps"
SHORTCUTDIR="/usr/share/applications"
fi
APPDATADIR="$HOME/.local/share/mcserver"
ASSETSDIR="$APPDATADIR/assets"
echo "INFO: Setting up"
if [ ! -d "$APPDATADIR" ]; then
mkdir -p "$APPDATADIR"
fi
if [ ! -d "$LIBDIR" ]; then
mkdir -p "$LIBDIR"
fi
if [ ! -d "$INSTALLDIR" ]; then
mkdir -p "$INSTALLDIR"
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
echo ""
else
echo "WARNING: Local bin directory is not on PATH"
fi
fi
if [ ! -d $ASSETSDIR ]; then
mkdir $ASSETSDIR
fi
echo "INFO: Installing (Stage 1)"
cp -r doc/* $ASSETSDIR # Copy assets
cp assets/defaulticon.png $ASSETSDIR
cp LICENSE $ASSETSDIR
if [ -d "dist" ]; then
echo "WARNING: dist directory found. Deleting now."
rm -rf dist # Clean dist directory
fi
echo "INFO: Shortening source file"
mkdir dist
#Copy code and add exec permissions
cp src/main.py dist/craftserversetup.py
chmod +x dist/craftserversetup.py
mv dist/craftserversetup.py dist/craftserversetup
cp dist/craftserversetup "$INSTALLDIR/craftserversetup"
ln -sf "$INSTALLDIR/craftserversetup" "$INSTALLDIR/mcserver"
ln -sf "$INSTALLDIR/craftserversetup" "$INSTALLDIR/crss"
pushd lib >/dev/null
echo "INFO: Installing libraries"
cp -r ./* $LIBDIR
cp ../src/*.py $LIBDIR
rm $LIBDIR/main.py
#Do not copy executable to library dir
popd >/dev/null
if [ ! -d $ICONDIR ]; then
mkdir -p $ICONDIR
fi
if [ ! -d $SHORTCUTDIR ]; then
mkdir -p $SHORTCUTDIR
fi
echo "INFO: Installing (Stage 3)"
cp assets/mc.png $ICONDIR/craftserversetup.png
cp assets/craftserversetup.desktop "${SHORTCUTDIR}/craftserversetup.desktop"
sed -i "s@}@${ICONDIR}@g" "${SHORTCUTDIR}/craftserversetup.desktop"
#Replace home path in shortcut file
#Register mime type
if [ ! -d $MIMEDIR ]; then
mkdir -p $MIMEDIR
fi
if [ ! -f $MIMEDIR/craftserversetup.xml ]; then
cp assets/mime.xml $MIMEDIR/craftserversetup.xml
fi
#Create file association
if [ -f $FILEREGFILE ]; then
if ! grep -q "minecraft-server" "$FILEREGFILE"; then
echo "application/minecraft-server=craftserversetup.desktop" >> $FILEREGFILE
fi
fi
cp doc/craftserversetup.epdoc $LIBDIR
cp src/translations.toml $APPDATADIR
rm -rf dist
printf "${GREEN}CraftServerSetup installed successfully!${NC}\n"
!def uninstall
#!/usr/bin/bash
#This program will be fixed, eventually
if [ "$EUID" -ne 0 ]; then
echo "WARNING: You are not running as root. You are only uninstalling locally"
INSTALLDIR="$HOME/.local/bin"
LIBDIR="$HOME/.local/lib/craftserversetup"
ICONDIR="$HOME/.local/share/icons"
SHORTCUTDIR="$HOME/.local/share/applications"
else
INSTALLDIR="/usr/bin"
LIBDIR="/usr/lib/craftserversetup"
ICONDIR="/usr/share/pixmaps"
SHORTCUTDIR="/usr/share/applications"
fi
rm "$INSTALLDIR/craftserversetup"
rm "$INSTALLDIR/mcserver"
rm "$INSTALLDIR/crss"
rm -rf "$LIBDIR"
rm $ICONDIR/craftserversetup.png
rm $SHORTCUTDIR/craftserversetup.desktop
echo "craftserversetup is deleted"
!def reset
rm -rf ~/.local/share/mcserver
!def package:private
echo " ===> DANGER! This is not meant to be used by normal users. If you are not a developer, expect a lot of errors"
echo " ===> Portabilizing dofile"
sbuild %package installer
echo " ===> Creating standard package"
rm -rf deb
rm -rf *.xz *.amc dist *.log *.deb *.zst *.rpm >/dev/null
tar --exclude='./analytics' --exclude='./assets/mc.ico' --exclude='./changelog' --exclude='./dofile' --exclude '*.iss' --exclude='./deb' --exclude='./dev' --exclude './output' -cJf craftserversetup.tar.xz ./*
echo " ===> Creating Debian Package"
#Create deb directories. Ignore if they don't exist
rm craftserversetup.deb
mkdir deb
mkdir deb/DEBIAN
mkdir deb/usr
mkdir deb/usr/bin
mkdir -p deb/usr/lib/craftserversetup/tempdeb
mkdir -p deb/usr/share/applications
mkdir -p deb/usr/share/pixmaps
set -e
#From now on, errors should halt build
#Declare vars
DEBBINFOLDER="deb/usr/bin"
DEBLIBFOLDER="deb/usr/lib/craftserversetup"
DEBTEMPFOLDER="$DEBLIBFOLDER/tempdeb"
cp assets/control deb/DEBIAN
#Move control
mkdir dist
#Copy code and add exec permissions
cp src/main.py dist/craftserversetup.py
chmod +x dist/craftserversetup.py
mv dist/craftserversetup.py deb/usr/bin/craftserversetup
chmod +x deb/usr/bin/craftserversetup
#Extract libraries
pushd lib >/dev/null
#Copy prebuilt python library
cp -r ./* ../$DEBLIBFOLDER
cp ../src/*.py "../$DEBLIBFOLDER" #Copy remaining custom librariespa
rm ../$DEBLIBFOLDER/main.py
popd >/dev/null
#Move desktop and icon files
cp assets/mc.png deb/usr/share/pixmaps/craftserversetup.png
cp assets/craftserversetup.desktop deb/usr/share/applications
sed -i "s@}@/usr/share/pixmaps@g" "deb/usr/share/applications/craftserversetup.desktop"
touch $DEBLIBFOLDER/deb
#Move MIME into temporary directory
cp assets/mime.xml $DEBTEMPFOLDER
cp assets/defaulticon.png $DEBTEMPFOLDER
cp doc/* $DEBTEMPFOLDER
cp LICENSE $DEBTEMPFOLDER
cp src/translations.toml $DEBTEMPFOLDER
#Copy postinstall
cp scripts/debian/postinstall.sh deb/DEBIAN/postinst
chmod +x deb/DEBIAN/postinst
dpkg-deb --build deb craftserversetup.deb
if [ -d output ]; then
rm -rf output
fi
mkdir output
cp scripts/linux_quick_installer.sh output
mv craftserversetup.tar.xz output
mv craftserversetup.deb output
cp universalwindowsinstaller/bin/Debug/CraftServerSetup-Universal-Installer.exe.exe output/WindowsUniversalInstaller.exe
!execute wbuild
!def run:private
!execute install
crss -d
!def commit:private
set -e
git pull
git add .
read -p "Commit message: " message
git commit -m "$message"
git push --force
!def sumsize:private
!execute install
set -e
mkdir -p ~/.local/bin/crsssum
cp ~/.local/bin/crss ~/.local/bin/crsssum
du -cs --exclude=~/.local/share/mcserver/temp --exclude=~/.local/share/mcserver/servers ~/.local/bin/crsssum ~/.local/lib/craftserversetup ~/.local/share/mcserver/assets
rm -rf ~/.local/bin/crsssum
!def wbuild:private
#This script builds for windows
#Before, you must install Python 3.12 and Inno Setup into wine
set -e
if ! command -v wine &> /dev/null
then
echo "ERROR: You must have wine installed to execute a Windows build."
exit 1
fi
WINEDIR="$HOME/.wine/drive_c"
ISSPATH="C:\\Program Files (x86)\\Inno Setup 6\\Compil32.exe"
PIPPATH="$WINEDIR/python/Scripts/pip.exe"
FDIR="$WINEDIR/python/crss"
PYINSTALLER="$WINEDIR/python/Scripts/pyinstaller.exe"
OUTPUTDIR="$PWD/output"
echo "Installing Dependencies"
wine $PIPPATH install --upgrade pyinstaller windows-curses cursesplus requests pyyaml
#Install deps
if [ -d $FDIR ]; then
rm -rf $FDIR
fi
echo "Copying Files"
mkdir -p $FDIR
mkdir $FDIR/installer
cp src/*.py $FDIR
cp assets/mc.ico $FDIR
cp assets/*.bmp $FDIR
cp src/translations.toml $FDIR
cp assets/defaulticon.png $FDIR
cp LICENSE $FDIR
read -p "Write app version: " version
cd scripts
#PARANV="${version//./,}"
PARANV="$(python3 version_fixer.py $version)"
#echo "--> SAFE V IS $PARANV"
#Replace x.y.z to x,y,z
sed -i -e '10d' vf.txt;sed -i "10i\ \ \ \ filevers=($PARANV)," vf.txt
sed -i -e '11d' vf.txt;sed -i "11i\ \ \ \ prodvers=($PARANV)," vf.txt
sed -i -e '35d' vf.txt;sed -i "35i\ \ \ \ \ \ \ \ StringStruct(u'FileVersion', u'$version')," vf.txt
sed -i -e '40d' vf.txt;sed -i "40i\ \ \ \ \ \ \ \ StringStruct(u'ProductVersion', u'$version')])" vf.txt
#Parse version file
#Parse ISS file
sed -i -e '5d' crss-wine.iss
sed -i "5i#define MyAppVersion \"$version\"" crss-wine.iss
sed -i -e '42d' crss-wine.iss
sed -i "42iOutputBaseFilename=CraftServerSetup-$version-installer" crss-wine.iss
cp vf.txt $FDIR
cp crss-wine.iss $FDIR
cd ..
echo "Compiling stage 1"
pushd $FDIR
mv main.py craftserversetup.py #Dodgy workaround
wine $PYINSTALLER --icon=mc.ico --version-file=vf.txt -y craftserversetup.py
echo "Waiting 5 seconds..."
sleep 5
echo "Compiling stage 2"
wine "$ISSPATH" /cc C:\\python\\crss\\crss-wine.iss
popd
echo "Packaging and moving"
cp $FDIR/installer/* $OUTPUTDIR
pushd $FDIR/dist/craftserversetup
echo "PORTABLE" >startupflags.txt
zip -9 -r $OUTPUTDIR/craftserversetup-portable.zip .
echo "COMPLETED"