-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqemu2deb.sh
executable file
·716 lines (691 loc) · 30.6 KB
/
qemu2deb.sh
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/bin/bash
######LICENSE######
# qemu2deb.sh - compile and package QEMU into a .deb
# =======================================================
# Copyright (C) 2021 Itai-Nelken <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
######VARIABLES######
# DIRECTORY - where to package deb
# QBUILD - where to build QEMU/where qemu was built
# QBUILDV - 1 or 0, compile qemu or not?
# PROG - (progress) 1,2,3,4,5,6,7,8,9,10,11 in what stage the script is? used for the ctrl_c function.
#####PROG variable values######
# 0 - before flags.
# 1 - after asking for DIRECTORY.
# 2 - after asking if QEMU is compiled or no (QBUILD, QBUILDV).
# 3 - after asking for directory to compile QEMU.
# 4 - after installing QEMU build dependencies.
# 5 - after running the compile-qemu function.
# 6 - after running 'sudo ninja install -C build' and QEMU wasn't compiled by the script (probably isn't run).
# 7 - after running 'cp-files' function.
# 8 - after creating the DEBIAN folder and entering it.
# 9 - after asking for maintainer or using pre-given one (using the flag).
# 10 - after creating the control file and giving it 775 permissions.
###11 - after building the deb.###
# 11 - after running the 'clean-up' function.
#variables
#CORES="$(nproc)"
#name the script is called by (for the help function)
CALLCOMMAND="./qemu2deb.sh"
#script version
APPVER="0.7.2"
#QEMU build dependencies
DEPENDS="build-essential ninja-build libepoxy-dev libdrm-dev libgbm-dev libx11-dev libvirglrenderer-dev libpulse-dev libsdl2-dev git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libepoxy-dev libdrm-dev libgbm-dev libx11-dev libvirglrenderer-dev libpulse-dev libsdl2-dev"
#text formatting
bold="\e[1m"
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
light_cyan="\e[96m"
normal="\e[0m"
function ctrl_c() {
case $PROG in
0|1|2|3|11)
echo -e "\e[1m\e[31m[CTRL+C] detected! exiting...\e[0m"
exit 1
;;
4)
echo -e "\e[1m\e[31m[CTRL+C] detected! cleaning up...\e[0m"
pkg-manage uninstall "$TOINSTALL"
exit 1
;;
5)
echo -e "\e[1m\e[31m[CTRL+C] detected! cleaning up...\e[0m"
while true; do
echo -ne "\e[1mdo you want to uninstall QEMU (run 'sudo ninja uninstall -C build') [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
cd "$QBUILD/qemu" || error warn "Failed to enter qemu build folder!" 2
sudo ninja uninstall -C builds || error warn "Failed to uninstall QEMU with ninja!" 2
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
while true; do
echo -ne "\e[1mdo you want to delete the QEMU build folder [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
cd "$QBUILD/" || error warn "Failed to enter the folder where the QEMU build folder is located!" 2
rm -rf qemu/ || sudo rm -rf qemu/
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
while true; do
echo -ne "\e[1mdo you want to uninstall the QEMU build dependencies [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
pkg-manage uninstall "$TOINSTALL"
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
exit 1
;;
6)
echo -e "\e[1m\e[31m[CTRL+C] detected!\e[0m"
echo "won't delete anything."
exit 1
;;
7|8|9|10)
echo -e "\e[1m\e[31m[CTRL+C] detected!\e[0m"
sleep 0.2
while true; do
echo -ne "\e[1mdo you want to uninstall QEMU (run 'sudo ninja uninstall -C build') [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
cd "$QBUILD/qemu" || error warn "Failed to enter the QEMU build folder!" 2
sudo ninja uninstall -C builds
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
while true; do
echo -ne "\e[1mdo you want to delete the QEMU build folder [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
cd "$QBUILD/" || error warn "Failed to enter the folder where the QEMU build folder is located!" 2
rm -rf qemu/ || sudo rm -rf qemu/ || error warn "failed to delete the QEMU build folder!" 2
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
while true; do
echo -ne "\e[1mdo you want to uninstall the QEMU build dependencies [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
pkg-manage uninstall "$TOINSTALL"
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
while true; do
echo -ne "\e[1mdo you want to delete the unpacked deb [y/n]?"
read -r answer
case $answer in
y|Y|yes|YES|Yes|yEs|yeS)
cd "$DIRECTORY" || error warn "Failed to enter folder where the deb was created!"
sudo rm -rf "qemu-$QVER-$ARCH/"
break
;;
n|N|no|No|nO)
echo "OK"
sleep 0.3
break
;;
*)
echo -e "\e[1m\e[33minvalid answer '$answer'! please try again\e[0m"
;;
esac
done
exit 1
;;
esac
}
#make the ctr_c function run if ctrl+c is pressed
trap "ctrl_c" 2
#check that script isn't being run as root.
if [ "$EUID" = 0 ]; then
echo "You cannot run this script as root!"
exit 1
fi
#check that OS arch is armhf
ARCH="$(uname -m)"
if [[ "$ARCH" == "x86_64" ]] || [[ "$ARCH" == "amd64" ]] || [[ "$ARCH" == "x86" ]] || [[ "$ARCH" == "i386" ]]; then
if [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 64)" ];then
ARCH="amd64"
elif [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 32)" ];then
ARCH="i386"
else
echo -e "${red}${bold}Can't detect OS architecture! something is very wrong!${normal}"
exit 1
fi
elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]] || [[ "$ARCH" == "armv7l" ]] || [[ "$ARCH" == "armhf" ]]; then
if [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 64)" ];then
ARCH="arm64"
elif [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 32)" ];then
ARCH="armhf"
else
echo -e "${red}${bold}Can't detect OS architecture! something is very wrong!${normal}"
exit 1
fi
else
echo -e "${red}${bold}ERROR: '$ARCH' isn't a supported architecture!${normal}"
exit 1
fi
#get machine name (aka Raspberry Pi detection)
RPI=$(grep ^Model /proc/cpuinfo | cut -d':' -f2- | sed 's/ R/R/')
if [[ "$RPI" == *"Raspberry Pi"* ]]; then
DEVICE="the Raspberry Pi and other $ARCH devices"
else
DEVICE="Linux $ARCH devices."
fi
#functions
function intro() {
#added extra 5 "spaces" for '-beta'
echo -e "
###########################################
# QEMU2DEB $APPVER by Itai-Nelken | 2021 #
# --------------------------------------- #
# compile/package/install QEMU #
###########################################
"
}
function error() {
######USAGE:######
# 1) error "text" - will print the text in red and bold and exit.
# 2) error exit "text" - same as above.
# 3) error sleep "text" 2 - will print the text in red and bold and sleep for the amount of seconds in $3, '2' in this example.
# 4) error sleep-exit "text" 2 - same as above but will exit.
# 5) error warn "text" 2 - print the text in yellow and bold and sleep for the amount of time passed to it in $3 (2 in this example).
if [[ "$1" == "exit" ]]; then
>&2 echo -e "${red}${bold}$2${normal}"
exit 1
elif [[ "$1" == "sleep" ]]; then
>&2 echo -e "${red}${bold}$2${normal}"
sleep "$3"
elif [[ "$1" == "sleep-exit" ]]; then
>&2 echo -e "${red}${bold}$2${normal}"
sleep "$3"
exit 1
elif [[ "$1" == "warn" ]]; then
>&2 echo -e "${yellow}${bold}$2${normal}"
sleep "$3" 2>/dev/null
else
>&2 echo -e "${red}${bold}$1${normal}"
exit 1
fi
}
function help() {
#usage
echo -e "${light_cyan}${bold}usage:${normal}"
echo "$CALLCOMMAND [flags]"
#new line
echo " "
#available flags
echo -e "${light_cyan}available flags:${normal}"
echo "--version - display version and exit."
echo "--help - display this help."
echo "--maintainer=<string> - enter maintainer name. ${bold}EXAMPLE USAGE:${normal} --maintainer=\"maintainer name <[email protected]>\""
#short flags
echo -e "${bold}You can also use shorter versions of the flags:${normal}"
echo "-h = --help"
echo "-v = --version"
#about architectures
echo -e "${bold}Compatibility:${normal}"
echo -e "this script only works on ${bold}armhf (arm32), arm64 (aarch64), x86 (i386), x86_64 (amd64)${normal} OS's,"
}
function clean-up() {
echo -e "${yellow}${bold}cleaning up...${normal}"
sleep 0.1
#error warn "The clean-up function isn't finished yet!" 5
#answer = empty string so if something happens and no user input comes, it will give the error that its incorrect answer.
answer=''
#uninstall QEMU
while true; do
echo -ne "Do you want to uninstall QEMU ${bold}(recommended)${normal} [y/n]?"
read -r answer
if [[ "$answer" =~ [yY] ]]; then
if [[ "$QBUILDV" == "1" ]]; then
cd "$QBUILD/qemu" || error sleep "Failed to enter the QEMU build folder!" 2
sudo ninja uninstall -C build || error sleep "Failed to uninstall QEMU with ninja!" 2
else
cd "$QBUILD" || error sleep "Failed to enter the QEMU build folder!" 2
sudo ninja uninstall -C build || error sleep "Failed to uninstall QEMU with ninja!" 2
fi
break
elif [[ "$answer" =~ [nn] ]]; then
echo "OK"
sleep 0.2
break
else
echo -e "${bold}invalid answer '$answer', please try again.${normal}"
fi
done
#answer = empty string so if something happens and no user input comes, it will give the error that its incorrect answer.
answer=''
#install QEMU from the deb
while true; do
echo -ne "Do you want to install QEMU from the deb? [y/n]?"
read -r answer
if [[ "$answer" =~ [yY] ]]; then
cd "$DIRECTORY" || error "Failed to change directory to \"$DIRECTORY\""
sudo apt -fy install ./qemu-$QVER-$ARCH.deb || error "Failed to install QEMU from the deb!"
break
elif [[ "$answer" =~ [nn] ]]; then
echo "OK"
sleep 0.2
break
else
echo -e "${bold}invalid answer '$answer', please try again.${normal}"
fi
done
#answer = empty string so if something happens and no user input comes, it will give the error that its incorrect answer.
answer=''
#remove QEMU build folder
while true; do
echo -ne "Do you want to delete the QEMU build folder [y/n]?"
read -r answer
if [[ "$answer" =~ [yY] ]]; then
if [[ "$QBUILDV" == "1" ]]; then
cd "$QBUILD" || error sleep "Failed to enter the folder where the QEMU build folder is located!" 2
rm -r qemu/ || sudo rm -rf qemu/
else
cd "$QBUILD" || error sleep ""
cd ../
rm -r qemu || sudo rm -rf qemu/
fi
break
elif [[ "$answer" =~ [nn] ]]; then
echo "OK"
sleep 0.2
break
else
echo -e "${bold}invalid answer '$answer', please try again.${normal}"
fi
done
#answer = empty string so if something happens and no user input comes, it will give the error that its incorrect answer.
answer=''
#remove unpacked deb folder
while true; do
echo -ne "Do you want to delete the unpacked deb folder [y/n]?"
read -r answer
if [[ "$answer" =~ [yY] ]]; then
cd "$DIRECTORY" || error sleep "Failed to enter folder where the deb was created!"
rm -rf qemu-$QVER-$ARCH/ || sudo rm -rf qemu-$QVER-$ARCH/
break
elif [[ "$answer" =~ [nn] ]]; then
echo "OK"
sleep 0.2
break
else
echo -e "${bold}invalid answer '$answer', please try again.${normal}"
fi
done
#answer = empty string so if something happens and no user input comes, it will give the error that its incorrect answer.
answer=''
#remove QEMU build dependencies
if [[ "$QBUILD" == "1" ]]; then
while true; do
echo -e "\e[1mThe following dependencies where installed to compile QEMU: \"\e[34m$TOINSTALL\e[0m\e[1m\"\e[0m"
echo -ne "Do you want to uninstall them [y/n]?"
read -r answer
if [[ "$answer" =~ [yY] ]]; then
pkg-manage remove "$TOINSTALL"
break
elif [[ "$answer" =~ [nn] ]]; then
echo "OK"
sleep 0.2
break
else
echo -e "${bold}invalid answer '$answer', please try again.${normal}"
fi
done
fi
}
function pkg-manage() {
#usage: pkg-manage install "package1 package2 package3"
#pkg-manage uninstall "package1 package2 package3" OR pkg-manage remove "package1 package2 package3"
#pkg-manage check "packag1 package2 package3"
#pkg-manage clean
#
#$1 is the operation: install or uninstall
#$2 is the packages to operate on.
if [[ "$1" == "install" ]]; then
TOINSTALL="$(dpkg -l $2 2>&1 | awk '{if (/^D|^\||^\+/) {next} else if(/^dpkg-query:/) { print $6} else if(!/^[hi]i/) {print $2}}' | tr '\n' ' ')"
sudo apt -f -y install $TOINSTALL || sudo apt -f -y install "$TOINSTALL"
elif [[ "$1" == "uninstall" ]] || [[ "$1" == "remove" ]]; then
sudo apt purge $2 -y
elif [[ "$1" == "check" ]]; then
TOINSTALL="$(dpkg -l $2 2>&1 | awk '{if (/^D|^\||^\+/) {next} else if(/^dpkg-query:/) { print $6} else if(!/^[hi]i/) {print $2}}' | tr '\n' ' ')"
elif [[ "$1" == "clean" ]]; then
sudo apt clean
sudo apt autoremove -y
sudo apt autoclean
else
error sleep "operation not specified!" 1
fi
}
function compile-qemu() {
cd "$QBUILD" || error "Failed to change directory!"
while true; do
break
done
echo -e "$(tput setaf 6)cloning QEMU git repo...$(tput sgr 0)"
git clone https://git.qemu.org/git/qemu.git || error "Failed to clone QEMU git repo!"
cd qemu || error "Failed to change Directory!"
git submodule init || error "Failed to run 'git submodule init'"
git submodule update --recursive || error "Failed to run 'git submodule update --recursive'!"
echo "$(tput setaf 6)running ./configure...$(tput sgr 0)"
./configure --enable-sdl --enable-opengl --enable-virglrenderer --enable-system --enable-modules --audio-drv-list=pa --enable-kvm || error "Failed to run './configure'!"
echo "$(tput setaf 6)compiling QEMU...$(tput sgr 0)"
#make -j$CORES || error "Failed to run make -j$CORES!"
#sudo make install || error "Failed to run 'sudo make install'!"
ninja -C build || error "Failed to run ninja -C build'!"
echo -e "$(tput setaf 6)nstalling QEMU...$(tput sgr 0)"
sudo ninja install -C build || error "Failed to install QEMU with 'sudo ninja install -C build'!"
}
function cp-files() {
#get QEMU version
QVER="$(qemu-system-ppc --version | grep version | cut -c23-28)" || QVER="$(qemu-system-i386 --version | grep version | cut -c23-28)" || QVER="$(qemu-system-arm --version | grep version | cut -c23-28)" || error "Failed to get QEMU version! is the full version installed?"
#get all files inside a folder before building deb
clear -x
echo "copying files..."
echo -ne '(0%)[# ](100%)\r'
sleep 0.1
cd "$DIRECTORY" || error "Failed to change directory to $DIRECTORY!"
mkdir qemu-$QVER-$ARCH || error "Failed to create unpacked deb folder!"
echo -ne '(0%)[## ](100%)\r'
sleep 0.1
cd qemu-$QVER-$ARCH || error "Failed to change Directory to $DIRECTORY/qemu-$QVER-$ARCH!"
#mkdir -p usr/include/linux/ || error "Failed to create $DIRECTORY/qemu-$QVER-$ARCH/usr/include/linux/!"
#cp /usr/include/linux/qemu_fw_cfg.h qemu-$QVER-$ARCH/usr/include/linux/
sleep 0.1
echo -ne '(0%)[### ](100%)\r'
mkdir -p usr/bin || error "Failed to create 'usr/bin' folder for deb!"
cp /usr/local/bin/qemu* $DIRECTORY/qemu-$QVER-$ARCH/usr/bin || error "Failed to copy the qemu files to 'usr/bin' folder for deb!"
mkdir -p usr/lib/ || error "Failed to create 'usr/lib' folder for deb!"
sudo cp -r /usr/local/lib/qemu/ $DIRECTORY/qemu-$QVER-$ARCH/usr/lib || error "Failed to copy the qemu files to 'usr/lib' folder for deb!"
mkdir -p usr/libexec || error "Failed to create 'usr/libexec' folder for deb!"
cp /usr/local/libexec/qemu-bridge-helper $DIRECTORY/qemu-$QVER-$ARCH/usr/libexec || error "Failed to copy the qemu files to 'usr/libexec' folder for deb!"
sleep 0.1
echo -ne '(0%)[######## ](100%)\r'
mkdir -p usr/share/ || error "Failed to create 'usr/share' folder for deb!"
cp -r /usr/local/share/qemu/ $DIRECTORY/qemu-$QVER-$ARCH/usr/share || error "Failed to copy the qemu files to 'usr/share' folder for deb!"
mkdir -p usr/share/applications || error "Failed to create 'usr/share/applications' folder for deb!"
cp /usr/local/share/applications/qemu.desktop $DIRECTORY/qemu-$QVER-$ARCH/usr/share/applications/ || error "Failed to copy the qemu files to 'usr/share/applications' folder for deb!"
sleep 0.1
echo -ne '(0%)[########## ](100%)\r'
mkdir -p usr/share/icons/hicolor/16x16/apps || error "Failed to create 'usr/share/icons/hicolor/16x16/apps' folder for deb!"
mkdir -p usr/share/icons/hicolor/24x24/apps || error "Failed to create 'usr/share/icons/hicolor/24x24/apps' folder for deb!"
sleep 0.05
echo -ne '(0%)[############# ](100%)\r'
sleep 0.1
mkdir -p usr/share/icons/hicolor/32x32/apps || error "Failed to create 'usr/share/icons/hicolor/32x32/apps' folder for deb!"
mkdir -p usr/share/icons/hicolor/48x48/apps || error "Failed to create 'usr/share/icons/hicolor/48x48/apps' folder for deb!"
sleep 0.01
echo -ne '(0%)[############## ](100%)\r'
mkdir -p usr/share/icons/hicolor/64x64/apps || error "Failed to create 'usr/share/icons/hicolor/64x64/apps' folder for deb!"
mkdir -p usr/share/icons/hicolor/128x128/apps || error "Failed to create 'usr/share/icons/hicolor/128x128/apps' folder for deb!"
echo -ne '(0%)[############### ](100%)\r'
mkdir -p usr/share/icons/hicolor/256x256/apps || error "Failed to create 'usr/share/icons/hicolor/256x256/apps' folder for deb!"
mkdir -p usr/share/icons/hicolor/512x512/apps || error "Failed to create 'usr/share/icons/hicolor/512x512/apps' folder for deb!"
sleep 0.1
echo -ne '(0%)[################ ](100%)\r'
mkdir -p usr/share/icons/hicolor/scalable/apps || error "Failed to create 'usr/share/icons/hicolor/scalable/apps' folder for deb!"
cp /usr/local/share/icons/hicolor/16x16/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/16x16/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/16x16/apps' folder for deb!"
cp /usr/local/share/icons/hicolor/24x24/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/24x24/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/24x24/apps' folder for deb!"
echo -ne '(0%)[################### ](100%)\r'
cp /usr/local/share/icons/hicolor/32x32/apps/qemu.bmp $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/32x32/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/32x32/apps' (.bmp) folder for deb!"
cp /usr/local/share/icons/hicolor/32x32/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/32x32/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/32x32/apps' (.png) folder for deb!"
cp /usr/local/share/icons/hicolor/48x48/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/48x48/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/48x48/apps' folder for deb!"
cp /usr/local/share/icons/hicolor/64x64/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/64x64/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/64x64/apps' folder for deb!"
sleep 0.2
echo -ne '(0%)[##################### ](100%)\r'
cp /usr/local/share/icons/hicolor/128x128/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/128x128/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/128x128/apps' folder for deb!"
cp /usr/local/share/icons/hicolor/256x256/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/256x256/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/256x256/apps' folder for deb!"
sleep 0.001
echo -ne '(0%)[######################## ](100%)\r'
cp /usr/local/share/icons/hicolor/512x512/apps/qemu.png $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/512x512/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/512x512/apps' folder for deb!"
sleep 0.1
echo -ne '(0%)[######################### ](100%)\r'
cp /usr/local/share/icons/hicolor/scalable/apps/qemu.svg $DIRECTORY/qemu-$QVER-$ARCH/usr/share/icons/hicolor/scalable/apps || error "Failed to copy the qemu files to 'usr/share/icons/hicolor/scalable/apps' folder for deb!"
sleep 0.1
echo -ne '(0%)[##########################](100%)\r'
sleep 0.5
}
##################################################################
##################################################################
##########The part where things actually start to happen##########
##################################################################
##################################################################
#set the progress variable to 0
PROG=0
##########flags##########
while [[ $# != 0 ]]; do
case "$1" in
-h|--help)
help
exit 0
;;
--maintainer*)
MAINTAINER=$(echo $1 | sed -e 's/^[^=]*=//g')
export MAINTAINER
shift
;;
--version | -v)
intro
exit 0
;;
*)
error "invalid option '$1'!"
;;
esac
done
#clear -x the screen
clear -x
#run the "intro" function
intro
#print a blank line
echo ' '
#ask for directory path, if doesn't exist ask again. if exists exit loop.
while true; do
read -rp "Enter full path to directory where you want to make the deb: " DIRECTORY
if [ ! -d "$DIRECTORY" ]; then
echo -e "\e[1mdirectory does not exist, please try again\e[0m"
else
echo -e "\e[1mqemu will be built and packaged here: $DIRECTORY\e[0m"
break
fi
done
PROG=1
echo " "
#ask if you already compiled QEMU, if yes enter full path (same as other loop), if you press s, the loop exits.
while true; do
read -rp "If you already compiled and installed QEMU, enter the path to its folder. otherwise press s: " QBUILD
if [[ "$QBUILD" == s ]]; then
echo "QEMU will be compiled..."
QBUILDV=1
break
fi
if [[ ! -d $QBUILD ]]; then
echo -e "\e[1mdirectory does not exist, please try again\e[0m"
else
echo -e "\e[1mqemu is already built here: $QBUILD\e[0m"
QBUILDV=0
break
fi
done
PROG=2
if [[ "$QBUILDV" == "1" ]] && [[ "$QBUILD" == "s" ]]; then
while true; do
read -rp "Enter full path directory where you want to compile QEMU, you can use the same one as before: " QBUILD
if [[ ! -d $QBUILD ]]; then
echo -e "\e[1mdirectory does not exist, please try again\e[0m"
else
echo -e "\e[1mQEMU will be compiled here: $QBUILD\e[0m"
break
fi
done
PROG=3
#check what dependencies aren't installed and install them
pkg-manage install "$DEPENDS" || error "Failed to install dependencies"
echo ' '
PROG=4
#compile qemu
compile-qemu || error "Failed to run compile-qemu function"
PROG=5
elif [[ "$QBUILDV" == 0 ]]; then
read -rp "do you want to install QEMU (run 'sudo ninja install -C build') (y/n)?" choice
case "$choice" in
y|Y ) CONTINUE=1 ;;
n|N ) CONTINUE=0 ;;
* ) echo "invalid" ;;
esac
if [[ "$CONTINUE" == 1 ]]; then
cd $QBUILD || error "Failed to change directory to \"$QBUILD\""
sudo ninja install -C build || error "Failed to run 'sudo ninja install -C build'"
elif [[ "$CONTINUE" == 0 ]]; then
if ! command -v qemu-img >/dev/null || ! command -v qemu-system-ppc >/dev/null || ! command -v qemu-system-i386 >/dev/null ;then
error "QEMU isn't installed! can't continue!"
else
echo "assuming QEMU is installed..."
fi
fi
fi
PROG=6
sleep 0.5
#clear the screen again
clear -x
#print the summary so far and ask to continue
printf "\e[1m\\e[3;4;37mSummary:\\n\\e[0m"
echo "the DEB will be built here: $DIRECTORY"
if [[ "$QBUILDV" == 1 ]]; then
echo "QEMU was compiled here: $QBUILD/qemu"
elif [[ "$QBUILDV" == 0 ]]; then
echo "QEMU is already compiled here: $QBUILD"
fi
read -rp "Press [ENTER] to continue or [CTRL+C] to cancel"
#start making the deb folder (unpacked deb)
echo -e "\e[96m\e[1mQEMU will now be packaged into a DEB, this will take a few minutes and consume all CPU.\e[0m"
echo -e "\e[96m\e[1mcooling is recommended.\e[0m"
read -rp "Press [ENTER] to continue"
#copy all files using the 'cp-files' function
cp-files || error "Failed to run cp-files function!"
PROG=7
echo -e "\ncreating DEBIAN folder..."
mkdir DEBIAN || error "Failed to create DEBIAN folder!"
cd DEBIAN || error "Failed to change to DEBIAN folder!"
sleep 0.5
clear -x
PROG=8
echo -e "${light_cyan}creating control file...${normal}"
#ask for maintainer info only if the variable 'MAINTAINER' does not exist.
if [[ -z $MAINTAINER ]]; then
echo -e "$(tput setaf 3)$(tput bold)enter maintainer info:$(tput sgr 0)"
read -r MAINTAINER
clear -x
else
echo "maintainer is already set to '$MAINTAINER'..."
fi
PROG=9
#create DEBIAN/control
cd "$DIRECTORY/qemu-$QVER-$ARCH/DEBIAN" || error "Failed to change directory to \"$DIRECTORY/qemu-$QVER-$ARCH/DEBIAN\""
echo "Maintainer: $MAINTAINER
Summary: QEMU $QVER $ARCH for $DEVICE built using qemu2deb.
Name: qemu
Description: QEMU $QVER $ARCH built using QEMU2DEB for $DEVICE.
Version: 1:$QVER
Release: 1
License: GPL
Architecture: $ARCH
Provides: qemu
Priority: optional
Section: custom
Recommends: bash-completion
Conflicts: qemu-utils, qemu-system-common, qemu-system-gui, qemu-system-ppc, qemu-block-extra, qemu-guest-agent, qemu-kvm, qemu-system-arm, qemu-system-common, qemu-system-mips, qemu-system-misc, qemu-system-sparc, qemu-system-x86, qemu-system, qemu-user-binfmt, qemu-user-static, qemu-user, qemu, openbios-sparc, openbios-ppc, openbios-sparc, seabios, openhackware, qemu-slof, ovmf
Package: qemu" > control || error "Failed to create control file!"
#give it the necessary permissions
sudo chmod 775 control || error "Failed to change control file permissions!"
PROG=10
cd "../.." || error "Failed to go 2 directories up!"
#build the DEB
sudo dpkg-deb --build qemu-$QVER-$ARCH/ || error "Failed to build the deb using dpkg-deb!"
sudo chmod 606 qemu-$QVER-$ARCH.deb || error warn "WARNING: Failed to give the deb '606' permissions!"
echo -e "${light_cyan}${bold}DONE...${normal}"
echo "The QEMU deb will be in $DIRECTORY/qemu-$QVER-$ARCH.deb"
read -rp "Press [ENTER] to continue"
clear -x
#clean up
clean-up || error "Failed to run clean-up function!"
PROG=11
echo -e "${green}${bold}DONE!${normal}"
sleep 0.5
exit 0