tiny-slitaz view step1.php @ rev 19

100 uers max
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 12 12:16:10 2017 +0100 (2017-02-12)
parents af73cc7ea672
children 694b6eb6f4f9
line source
1 <?php
3 shell_exec("sudo ./helper --chkdist");
4 $usedvars = array( "kernel", "modules", "packages", "toconfigure",
5 "continue", "configuring", "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 ($i++ > 100) {
14 echo "<h1>Too may users, retry later</h1>";
15 exit;
16 }
17 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
18 shell_exec("sudo ./helper --remove /tmp/$name");
19 $i--;
20 }
21 closedir($dir);
22 if (isset($_POST["tmp_dir"])) return;
23 $_POST["tmp_dir"] = tempnam('','tiny_webgen');
24 if (file_exists($_POST["tmp_dir"])) unlink($_POST["tmp_dir"]);
25 mkdir($_POST["tmp_dir"]);
26 $_POST["tmp_dir"] .= '/';
27 }
29 set_tmp_dir();
31 function post_hidden()
32 {
33 global $usedvars;
34 foreach ($usedvars as $var) {
35 if (isset($_POST[$var]) && $var != "continue" &&
36 $var != "configuring") {
37 ?>
38 <input name="<?php echo $var; ?>" value="<?php echo $_POST[$var]; ?>" type="hidden" />
39 <?php
40 }
41 }
42 }
44 function upload($var, $file = "")
45 {
46 if ($file == "") $file = $var;
47 if (isset($_FILES[$var])) {
48 $tmp_name = $_FILES[$var]['tmp_name'];
49 if (is_uploaded_file($tmp_name)) {
50 move_uploaded_file($tmp_name, $_POST["tmp_dir"].$file);
51 }
52 }
53 }
55 if (isset($_POST['mykernel']) && !isset($_POST['packages'])) {
56 $_POST['kernel'] = "custom";
57 upload("uploadkernel","kernel");
58 }
60 if (!isset($_POST['kernel'])) {
61 shell_exec("sudo ./helper --init");
62 if (isset($_POST['config'])) {
63 upload("uploadconf");
64 }
65 if (!file_exists($_POST["tmp_dir"]."uploadconf")) {
66 ?>
68 <div class="box">
69 <h3>[Step 1/5] Packages and Kernel</h3>
71 <p>The file <tt>/etc/packages.conf</tt> in the initramfs holds all information
72 to rebuild your Tiny SliTaz system. You should upload your
73 <tt>/etc/packages.conf</tt> first if you only want to upgrade your system.</p>
75 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
76 Packages configuration:
77 <input type="file" name="uploadconf" />
78 <input name="config" value="Get config" type="submit" />
79 <?php post_hidden(); ?>
80 </form>
81 <?php
82 }
83 if (isset($_POST['mypackages'])) {
84 upload("uploadpkgs");
85 shell_exec("./helper --pkgs-extract uploadpkgs ".$_POST['tmp_dir']);
86 }
87 if (!file_exists($_POST["tmp_dir"]."uploadpkgs")) {
88 ?>
90 <hr>
92 <p>You can upload a tazpkg file (.tazpkg) or a tarball of tazpkg files (.tar).
93 These packages will extend the official packages list and will be chosen when
94 the package names are found to be matching. You can find some examples in the
95 <a href="http://hg.slitaz.org/wok-tiny/file/">Tiny SliTaz repository</a>.</p>
97 <div>
98 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
99 Additional packages:
100 <input type="file" name="uploadpkgs" />
101 <input name="mypackages" value="Get packages" type="submit" />
102 <?php post_hidden(); ?>
103 </form>
104 </div>
106 <hr>
107 <?php
108 }
109 ?>
111 <p id="kernel">You can upload a custom Kernel or use an official one. Your
112 Kernel should have an embedded initramfs with busybox like <a
113 href="dist/rootfs.cpio" title="See CONFIG_INITRAMFS_SOURCE">this</a>.</p>
115 <div>
116 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
117 Custom kernel (bzImage file):
118 <input type="file" name="uploadkernel" />
119 <input name="mykernel" value="Get kernel" type="submit" />
120 <?php post_hidden(); ?>
121 </form>
122 </div>
124 <hr>
126 <div>
127 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="kernels">
128 <input type="hidden" name="kernel" value="linux" />
129 <?php post_hidden(); ?>
130 <div align="center">
131 <input name="continue" value="Continue" type="submit" />
132 </div>
133 </form>
134 </div>
135 </div>
137 <?php
138 }
139 ?>