author | andyq <andyq> | 2002-10-16 18:54:05 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-10-16 18:54:05 (UTC) |
commit | 63d3299669d5147e16c56b016b0ee3cca2127a75 (patch) (unidiff) | |
tree | 7663e1822b6898791ae97a18b0355cf84bda4d36 | |
parent | 3cb6b6fab8d06b1be8f8c39560db9d3d88ce3921 (diff) | |
download | opie-63d3299669d5147e16c56b016b0ee3cca2127a75.zip opie-63d3299669d5147e16c56b016b0ee3cca2127a75.tar.gz opie-63d3299669d5147e16c56b016b0ee3cca2127a75.tar.bz2 |
Added ability to upgrade all packages
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index d5157eb..f8513e4 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -4,181 +4,185 @@ | |||
4 | begin : Sat Aug 31 2002 | 4 | begin : Sat Aug 31 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include <fstream> | 18 | #include <fstream> |
19 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | 23 | ||
24 | #ifdef QWS | 24 | #ifdef QWS |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #else | 26 | #else |
27 | #include <qapplication.h> | 27 | #include <qapplication.h> |
28 | #endif | 28 | #endif |
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #include "utils.h" | 32 | #include "utils.h" |
33 | #include "ipkg.h" | 33 | #include "ipkg.h" |
34 | #include "global.h" | 34 | #include "global.h" |
35 | 35 | ||
36 | Ipkg :: Ipkg() | 36 | Ipkg :: Ipkg() |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | Ipkg :: ~Ipkg() | 40 | Ipkg :: ~Ipkg() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | // Option is what we are going to do - install, upgrade, download | 44 | // Option is what we are going to do - install, upgrade, download |
45 | // package is the package name to install - either a fully qualified path and ipk | 45 | // package is the package name to install - either a fully qualified path and ipk |
46 | // file (if stored locally) or just the name of the package (for a network package) | 46 | // file (if stored locally) or just the name of the package (for a network package) |
47 | // packageName is the package name - (for a network package this will be the same as | 47 | // packageName is the package name - (for a network package this will be the same as |
48 | // package parameter) | 48 | // package parameter) |
49 | // dest is the destination alias (from ipk.conf) | 49 | // dest is the destination alias (from ipk.conf) |
50 | // destDir is the dir that the destination alias points to (used to link to root) | 50 | // destDir is the dir that the destination alias points to (used to link to root) |
51 | // flags is the ipkg options flags | 51 | // flags is the ipkg options flags |
52 | // dir is the directory to run ipkg in (defaults to "") | 52 | // dir is the directory to run ipkg in (defaults to "") |
53 | bool Ipkg :: runIpkg( ) | 53 | bool Ipkg :: runIpkg( ) |
54 | { | 54 | { |
55 | bool ret = false; | 55 | bool ret = false; |
56 | 56 | ||
57 | QDir::setCurrent( "/tmp" ); | 57 | QDir::setCurrent( "/tmp" ); |
58 | QString cmd = ""; | 58 | QString cmd = ""; |
59 | 59 | ||
60 | if ( runtimeDir != "" ) | 60 | if ( runtimeDir != "" ) |
61 | { | 61 | { |
62 | cmd += "cd "; | 62 | cmd += "cd "; |
63 | cmd += runtimeDir; | 63 | cmd += runtimeDir; |
64 | cmd += " ; "; | 64 | cmd += " ; "; |
65 | } | 65 | } |
66 | cmd += "ipkg"; | 66 | cmd += "ipkg"; |
67 | 67 | ||
68 | if ( option != "update" && option != "download" ) | 68 | if ( option != "update" && option != "download" && option != "upgrade" ) |
69 | { | 69 | { |
70 | cmd += " -dest "+ destination; | 70 | cmd += " -dest "+ destination; |
71 | cmd += " -force-defaults"; | 71 | cmd += " -force-defaults"; |
72 | 72 | ||
73 | if ( flags & FORCE_DEPENDS ) | 73 | if ( flags & FORCE_DEPENDS ) |
74 | cmd += " -force-depends"; | 74 | cmd += " -force-depends"; |
75 | if ( flags & FORCE_REINSTALL ) | 75 | if ( flags & FORCE_REINSTALL ) |
76 | cmd += " -force-reinstall"; | 76 | cmd += " -force-reinstall"; |
77 | if ( flags & FORCE_REMOVE ) | 77 | if ( flags & FORCE_REMOVE ) |
78 | cmd += " -force-removal-of-essential-packages"; | 78 | cmd += " -force-removal-of-essential-packages"; |
79 | if ( flags & FORCE_OVERWRITE ) | 79 | if ( flags & FORCE_OVERWRITE ) |
80 | cmd += " -force-overwrite"; | 80 | cmd += " -force-overwrite"; |
81 | 81 | ||
82 | // Handle make links | 82 | // Handle make links |
83 | // Rules - If make links is switched on, create links to root | 83 | // Rules - If make links is switched on, create links to root |
84 | // if destDir is NOT / | 84 | // if destDir is NOT / |
85 | if ( flags & MAKE_LINKS ) | 85 | if ( flags & MAKE_LINKS ) |
86 | { | 86 | { |
87 | // If destDir == / turn off make links as package is being insalled | 87 | // If destDir == / turn off make links as package is being insalled |
88 | // to root already. | 88 | // to root already. |
89 | if ( destDir == "/" ) | 89 | if ( destDir == "/" ) |
90 | flags ^= MAKE_LINKS; | 90 | flags ^= MAKE_LINKS; |
91 | } | 91 | } |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | #ifdef X86 | 95 | #ifdef X86 |
96 | cmd += " -f "; | 96 | cmd += " -f "; |
97 | cmd += IPKG_CONF; | 97 | cmd += IPKG_CONF; |
98 | #endif | 98 | #endif |
99 | 99 | ||
100 | cmd += " " + option + " " + package + " 2>&1"; | 100 | cmd += " " + option; |
101 | if ( option != "upgrade" ) | ||
102 | cmd += " " + package; | ||
103 | cmd += " 2>&1"; | ||
101 | 104 | ||
102 | qApp->processEvents(); | 105 | qApp->processEvents(); |
103 | 106 | ||
104 | // If we are removing packages and make links option is selected | 107 | // If we are removing packages and make links option is selected |
105 | // create the links | 108 | // create the links |
106 | if ( option == "remove" ) | 109 | if ( option == "remove" ) |
107 | { | 110 | { |
108 | createLinks = false; | 111 | createLinks = false; |
109 | if ( flags & MAKE_LINKS ) | 112 | if ( flags & MAKE_LINKS ) |
110 | { | 113 | { |
111 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 114 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
112 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 115 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
113 | } | 116 | } |
114 | } | 117 | } |
115 | 118 | ||
116 | emit outputText( cmd ); | 119 | emit outputText( cmd ); |
117 | 120 | ||
118 | // Execute command | 121 | // Execute command |
119 | dependantPackages = new QList<QString>; | 122 | dependantPackages = new QList<QString>; |
120 | dependantPackages->setAutoDelete( true ); | 123 | dependantPackages->setAutoDelete( true ); |
124 | |||
121 | ret = executeIpkgCommand( cmd, option ); | 125 | ret = executeIpkgCommand( cmd, option ); |
122 | 126 | ||
123 | if ( option == "install" ) | 127 | if ( option == "install" ) |
124 | { | 128 | { |
125 | // If we are not removing packages and make links option is selected | 129 | // If we are not removing packages and make links option is selected |
126 | // create the links | 130 | // create the links |
127 | createLinks = true; | 131 | createLinks = true; |
128 | if ( flags & MAKE_LINKS ) | 132 | if ( flags & MAKE_LINKS ) |
129 | { | 133 | { |
130 | emit outputText( " " ); | 134 | emit outputText( " " ); |
131 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 135 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
132 | 136 | ||
133 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 137 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
134 | 138 | ||
135 | // link dependant packages that were installed with this release | 139 | // link dependant packages that were installed with this release |
136 | QString *pkg; | 140 | QString *pkg; |
137 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 141 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
138 | { | 142 | { |
139 | emit outputText( " " ); | 143 | emit outputText( " " ); |
140 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 144 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
141 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 145 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
142 | } | 146 | } |
143 | } | 147 | } |
144 | } | 148 | } |
145 | 149 | ||
146 | delete dependantPackages; | 150 | delete dependantPackages; |
147 | 151 | ||
148 | emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); | 152 | emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); |
149 | return ret; | 153 | return ret; |
150 | } | 154 | } |
151 | 155 | ||
152 | 156 | ||
153 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 157 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
154 | { | 158 | { |
155 | FILE *fp = NULL; | 159 | FILE *fp = NULL; |
156 | char line[130]; | 160 | char line[130]; |
157 | QString lineStr, lineStrOld; | 161 | QString lineStr, lineStrOld; |
158 | int ret = false; | 162 | int ret = false; |
159 | 163 | ||
160 | fp = popen( (const char *) cmd, "r"); | 164 | fp = popen( (const char *) cmd, "r"); |
161 | if ( fp == NULL ) | 165 | if ( fp == NULL ) |
162 | { | 166 | { |
163 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 167 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
164 | QString text; | 168 | QString text; |
165 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 169 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
166 | emit outputText( text ); | 170 | emit outputText( text ); |
167 | } | 171 | } |
168 | else | 172 | else |
169 | { | 173 | { |
170 | while ( fgets( line, sizeof line, fp) != NULL ) | 174 | while ( fgets( line, sizeof line, fp) != NULL ) |
171 | { | 175 | { |
172 | lineStr = line; | 176 | lineStr = line; |
173 | lineStr=lineStr.left( lineStr.length()-1 ); | 177 | lineStr=lineStr.left( lineStr.length()-1 ); |
174 | 178 | ||
175 | if ( lineStr != lineStrOld ) | 179 | if ( lineStr != lineStrOld ) |
176 | { | 180 | { |
177 | //See if we're finished | 181 | //See if we're finished |
178 | if ( option == "install" ) | 182 | if ( option == "install" ) |
179 | { | 183 | { |
180 | // Need to keep track of any dependant packages that get installed | 184 | // Need to keep track of any dependant packages that get installed |
181 | // so that we can create links to them as necessary | 185 | // so that we can create links to them as necessary |
182 | if ( lineStr.startsWith( "Installing " ) ) | 186 | if ( lineStr.startsWith( "Installing " ) ) |
183 | { | 187 | { |
184 | cout << "LineStr = " << lineStr << endl; | 188 | cout << "LineStr = " << lineStr << endl; |