Ubuntu software source configuration method

Source: Internet
Author: User
Recently, the company needs to add a feature, that is, automatic version update, using apt-Get. For more information about how to configure apt-Get software sources, see share your resources. The following code is used as part of the upgrade.
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");


There is no problem with the preliminary test.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.