UBUntu 軟體 源配置方法

來源:互聯網
上載者:User

標籤:ubuntu 下實現產品自動更新功能

    最近公司產品需要增加一個功能,就是版本自動更新,使用apt-get 實現。apt-get 軟體源配置的方法,參見本人資源裡的共用。下面是代碼中作為升級的一部分。 
FILE *fp;char buffer[256];char source_ok[] = "Reading package lists...";if(0 > system("mv -f /etc/apt/sources.list /etc/apt/sources.list.upgrade"))printf("cldUp backup old source list error!\n");fp=fopen("/etc/apt/sources.list","w+");if(0 == fp)goto update_done;fprintf(fp,"deb http://%s/apt %s %s", source_addr, source_dir, source_ver);printf("\ndeb http://%s/apt %s %s\n", source_addr, source_dir, source_ver);fclose(fp);fp=popen("apt-get update 2>&1","r");while(!feof(fp)){if(0 == fgets(buffer,sizeof(buffer),fp))break;printf("%s",buffer);                fflush(stdout);if(strstr(buffer,"Failed")){trace_log(buffer);                        printf("scan failed and exit\n");        goto update_done;}if(strstr(buffer,source_ok)){trace_log(buffer);                                                printf("scan sourceok  and exit\n");break;}}pclose(fp);fp=popen("apt-get -y --force-yes install ssh 2>&1","r");while(!feof(fp)){if(0 == fgets(buffer,sizeof(buffer),fp))break;printf("%s",buffer);                if(strstr(buffer,"1 upgraded")){                //save the upgrade info                 b_upgrade_success = true;trace_log(buffer);                       }        }pclose(fp);        if(b_upgrade_success)        {               b_upgrade_success = 0;                       }update_done:if(0 > system("mv -f /etc/apt/sources.list.upgrade /etc/apt/sources.list"))printf("restore source list error!\n");


初步測試沒有什麼問題。


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.