client = Client.new( option[:url], nil, nil )
#client.update()
when "clean" then
- client = Client.new( nil, option[:loc], nil )
+ client = Client.new( nil, option[:loc], nil, false )
client.clean(option[:f])
when "download" then
client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
file_loc = client.download( option[:pkg], option[:os], option[:t] )
when "install" then
client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
client.install( option[:pkg], option[:os], option[:t], option[:f] )
when "install-file" then
- client = Client.new( option[:url], option[:loc], nil )
- client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+ if option[:t] then
+ client = Client.new( option[:url], option[:loc], nil )
+ client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+ else
+ client = Client.new( nil, option[:loc], nil, false )
+ client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+ end
when "uninstall" then
- client = Client.new( nil, option[:loc], nil )
+ client = Client.new( nil, option[:loc], nil, false )
client.uninstall( option[:pkg], option[:t] )
when "upgrade" then
client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
client.upgrade( option[:os], option[:t] )
when "check-upgrade" then
client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
client.check_upgrade( option[:os] )
when "show-rpkg" then
client = Client.new( option[:url], nil, nil )
- #if not option[:url].nil? then
- # client.update()
- #end
puts client.show_pkg_info( option[:pkg], option[:os] )
when "list-rpkg" then
client = Client.new( option[:url], nil, nil )
- #if not option[:url].nil? then
- # client.update()
- #end
result = client.show_pkg_list( option[:os] )
if not result.nil? and not result.empty? then
result.each do |i|
end
end
when "show-lpkg" then
- client = Client.new( nil, option[:loc], nil )
+ client = Client.new( nil, option[:loc], nil, false )
puts client.show_installed_pkg_info( option[:pkg] )
when "list-lpkg" then
- client = Client.new( nil, option[:loc], nil )
+ client = Client.new( nil, option[:loc], nil, false )
result = client.show_installed_pkg_list()
if not result.nil? and not result.empty? then
result.each do |i|
CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
PACKAGE_INFO_DIR = ".info"
DEFAULT_INSTALL_DIR = "#{Utils::HOME}/build_root"
- DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
+ #DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
OS_INFO_FILE = "os_info"
ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"
# create "remote package hash" and "installed package hash"
# @server_addr = server address (can be included distribution, snapshot)
# @location = client location (download and install file to this location)
- def initialize(server_addr, location, logger)
+ def initialize(server_addr, location, logger, access_svr = true)
# set log
if logger.nil? or logger.class.to_s.eql? "String" then
# create directory
if not File.exist? CONFIG_PATH then FileUtils.mkdir_p "#{CONFIG_PATH}" end
-
- # set default server address, location
- if server_addr.nil? then server_addr = get_default_server_addr() end
+ # set location
if location.nil? then location = get_default_inst_dir() end
- # chop server address, if end with "/"
- if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
-
+ @location = location
@snapshot_path = nil
@snapshot_url = false
-
- if is_snapshot_url(server_addr) then
- @snapshot_url = true
- @server_addr, @snapshot_path = split_addr_and_snapshot(server_addr)
- else
- @server_addr = server_addr
- end
-
- @location = location
@pkg_hash_os = {}
@installed_pkg_hash_loc = {}
@archive_pkg_list = []
@all_dep_list = []
- @is_server_remote = Utils.is_url_remote(server_addr)
@support_os_list = []
- @config_dist_path = CONFIG_PATH + "/" + get_flat_serveraddr
- @download_path = @config_dist_path + "/downloads"
- @tmp_path = @config_dist_path + "/tmp"
- @snapshots_path = @config_dist_path + "/snapshots"
+ @server_addr = nil
- # create directory
- if not File.exist? @config_dist_path then FileUtils.mkdir_p "#{@config_dist_path}" end
- if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
- if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
- if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
+
+ # if client should access remote server, set server information
+ if access_svr then
+ # if server address is nil, get a previous server address
+ if server_addr.nil? then
+ server_addr = get_default_server_addr()
+ if not server_addr.nil? then
+ @log.info "Get default server address from config file [#{server_addr}]"
+ end
+ end
+
+ if not server_addr.nil? then
+ # chop server address, if end with "/"
+ if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+
+ if is_snapshot_url(server_addr) then
+ @snapshot_url = true
+ @server_addr, @snapshot_path = split_addr_and_snapshot(server_addr)
+ else
+ @server_addr = server_addr
+ end
+ @is_server_remote = Utils.is_url_remote(server_addr)
+ @config_dist_path = CONFIG_PATH + "/" + get_flat_serveraddr
+ @download_path = @config_dist_path + "/downloads"
+ @tmp_path = @config_dist_path + "/tmp"
+ @snapshots_path = @config_dist_path + "/snapshots"
+
+ # create directory
+ if not File.exist? @config_dist_path then FileUtils.mkdir_p "#{@config_dist_path}" end
+ if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
+ if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
+ if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
+ end
+
+ # read remote pkg list, and hash list
+ @log.info "Update remote package list and supported os list.."
+ if update() then
+ @log.info "Initialize - #{server_addr}, #{location}"
+ else
+ @log.error "Failed to update remote package list."
+ end
+ end
# read installed pkg list, and create hash
if not File.exist? @location then FileUtils.mkdir_p "#{@location}" end
@log.info "Update local package list.. [#{@location}]"
read_installed_pkg_list()
-
- # read remote pkg list, and hash list
- @log.info "Update remote package list and supported os list.."
- update()
- @log.info "Initialize - #{server_addr}, #{location}"
end
public
# update package list from server
def update()
+
+ if @server_addr.nil? then
+ @log.warn "Server address is null"
+ return false
+ end
+
if not @snapshot_url then
$get_snapshot_mutex.synchronize do
@snapshot_path = get_lastest_snapshot(@is_server_remote)
end
@log.info "The lastest snapshot : #{@snapshot_path}"
if @snapshot_path.nil? then
- @log.warn "Failed to get the lastest package list"
+ @log.warn "Failed to get the lastest package list."
@snapshot_path = ""
end
@log.info "Snapshot information is already cached [#{get_pkglist_path()}]"
exists_snapshot = true
else
- @log.info "Snapshot information is not cached"
+ @log.info "Snapshot information is not cached."
end
list_path = get_pkglist_path()
if list_path.nil? then
- @log.error "Failed to get package list path"
+ @log.error "Failed to get package list path."
return false
end
end
$update_mutex.synchronize do
- create_default_config(@server_addr)
+ if not create_default_config(@server_addr) then
+ @log.warn "Config file can not be created."
+ else
+ @log.info "Config file is created."
+ end
@log.info "Update package list from \"#{@server_addr}\".. OK"
end
filepath = "#{CONFIG_PATH}/config"
server_addr = nil
- if not File.exist? filepath then create_default_config(nil) end
- if not File.exist? filepath then
- @log.error "There is no default server address in #{filepath}"
- return nil
- end
+ if not File.exist? filepath then return nil end
+
+ #if not File.exist? filepath then create_default_config(nil) end
+ #if not File.exist? filepath then
+ # @log.error "There is no default server address in #{filepath}"
+ # return nil
+ #end
File.open filepath, "r" do |f|
f.each_line do |l|
end
end
- if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
+ #if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
return server_addr
end
private
# create default config file (Utils::HOME/.build_tools/client/config)
def create_default_config(server_addr)
+ if server_addr.nil? then
+ return false
+ end
+
filepath = "#{CONFIG_PATH}/config"
- if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
+ #if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
if File.exist? filepath then
FileUtils.rm_f(filepath)
File.open(filepath, "a+") do |file|
file.puts "DEFAULT_SERVER_ADDR : #{server_addr}"
end
+
+ return true
end
public