tiny-slitaz view step1.php @ rev 32

Do not suggest packages twice
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Sep 26 13:55:40 2019 +0200 (2019-09-26)
parents 3caae5e3e0f7
children 49e3141e5899
line source
1 <?php
3 shell_exec("sudo ./helper --chkdist");
4 $usedvars = array( "kernel", "modules", "packages", "toconfigure",
5 "continue", "configuring", "already_suggested", "tmp_dir" );
7 function set_tmp_dir()
8 {
9 $dir = opendir("/tmp");
10 $i = 0;
11 while (($name = readdir($dir)) !== false) {
12 if (preg_match('/^tiny_webgen/',$name) == 0) continue;
13 if (filemtime("/tmp/$name") < strtotime("-1 hour"))
14 shell_exec("sudo ./helper --remove /tmp/$name");
15 else if ($i++ > 100) {
16 echo "<h1>Too many users, retry later</h1>";
17 exit;
18 }
19 }
20 closedir($dir);
21 if (isset($_POST["tmp_dir"])) return;
22 $_POST["tmp_dir"] = tempnam('','tiny_webgen');
23 if (file_exists($_POST["tmp_dir"])) unlink($_POST["tmp_dir"]);
24 mkdir($_POST["tmp_dir"]);
25 $_POST["tmp_dir"] .= '/';
26 }
28 set_tmp_dir();
30 function post_hidden()
31 {
32 global $usedvars;
33 foreach ($usedvars as $var) {
34 if (isset($_POST[$var]) && $var != "continue" &&
35 $var != "configuring") {
36 ?>
37 <input name="<?php echo $var; ?>" value="<?php echo $_POST[$var]; ?>" type="hidden" />
38 <?php
39 }
40 }
41 }
43 function upload($var, $file = "")
44 {
45 if ($file == "") $file = $var;
46 if (isset($_FILES[$var])) {
47 $tmp_name = $_FILES[$var]['tmp_name'];
48 if (is_uploaded_file($tmp_name)) {
49 move_uploaded_file($tmp_name, $_POST["tmp_dir"].$file);
50 }
51 }
52 }
54 if (isset($_POST['EXTRA_SUGGESTED'])) {
55 $_POST['already_suggested'] .= " ".$_POST['EXTRA_SUGGESTED'];
56 }
58 if (isset($_POST['mykernel']) && !isset($_POST['packages'])) {
59 $_POST['kernel'] = "custom";
60 upload("uploadkernel","kernel");
61 }
63 if (!isset($_POST['kernel'])) {
64 shell_exec("sudo ./helper --init");
65 if (isset($_POST['config'])) {
66 upload("uploadconf");
67 }
68 if (!file_exists($_POST["tmp_dir"]."uploadconf")) {
69 ?>
71 <div class="box">
72 <h3>[Step 1/5] Packages and Kernel</h3>
74 <p>The file <tt>/etc/packages.conf</tt> in the initramfs holds all information
75 to rebuild your Tiny SliTaz system. You should upload your
76 <tt>/etc/packages.conf</tt> first if you only want to upgrade your system.</p>
78 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
79 Packages configuration:
80 <input type="file" name="uploadconf" />
81 <input name="config" value="Get config" type="submit" />
82 <?php post_hidden(); ?>
83 </form>
84 <?php
85 }
86 if (isset($_POST['mypackages'])) {
87 upload("uploadpkgs");
88 shell_exec("./helper --pkgs-extract uploadpkgs ".$_POST['tmp_dir']);
89 }
90 if (!file_exists($_POST["tmp_dir"]."uploadpkgs")) {
91 ?>
93 <hr>
95 <p>You can upload a tazpkg file (.tazpkg) or a tarball of tazpkg files (.tar).
96 These packages will extend the official packages list and will be chosen when
97 the package names are found to be matching. You can find some examples in the
98 <a href="http://hg.slitaz.org/wok-tiny/file/">Tiny SliTaz repository</a>.</p>
100 <div>
101 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
102 Additional packages:
103 <input type="file" name="uploadpkgs" />
104 <input name="mypackages" value="Get packages" type="submit" />
105 <?php post_hidden(); ?>
106 </form>
107 </div>
109 <hr>
110 <?php
111 }
112 ?>
114 <p id="kernel">You can upload a custom Kernel or use an official one. Your
115 Kernel should have an embedded initramfs with busybox like <a
116 href="dist/rootfs.cpio" title="See CONFIG_INITRAMFS_SOURCE">this</a>.</p>
118 <div>
119 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
120 Custom kernel (bzImage file):
121 <input type="file" name="uploadkernel" />
122 <input name="mykernel" value="Get kernel" type="submit" />
123 <?php post_hidden(); ?>
124 </form>
125 </div>
127 <hr>
129 <div>
130 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="kernels">
131 <input type="hidden" name="kernel" value="linux" />
132 <?php post_hidden(); ?>
133 <div align="center">
134 <input name="continue" value="Continue" type="submit" />
135 </div>
136 </form>
137 </div>
138 </div>
140 <?php
141 }
142 ?>