{"id":576,"date":"2022-11-12T22:20:02","date_gmt":"2022-11-12T22:20:02","guid":{"rendered":"https:\/\/gentoostudio.org\/?p=576"},"modified":"2022-11-12T22:20:02","modified_gmt":"2022-11-12T22:20:02","slug":"catalyst-automation-v-1","status":"publish","type":"post","link":"https:\/\/dev.decibellinux.org\/?p=576","title":{"rendered":"Catalyst automation v.1"},"content":{"rendered":"\n<p>So this is version 1 of the new script to automate catalyst builds. There is a catalyst-auto from gentoo-releng, but 1. my needs for this purpose are much simpler than what catalyst-auto provides and 2. writing this script is proving to be fun. <\/p>\n\n\n\n<p>As always, suggestions welcome.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n\n### VARS\n\nurl=\"https:\/\/distfiles.gentoo.org\/releases\/amd64\/autobuilds\/\"\ntxtfile=\"latest-stage3-amd64-desktop-systemd.txt\"\nemail=\"webmaster@gentoostudio.org\"\n\n### ERROR MSGS\n\nremote_text_file_missing=\"Remote text file does not exist. Details sent to $email.\"\ncouldnt_get_stage3=\"Could not get stage3 seed. Details sent to $email.\"\n\n### EMAIL MSGS\n# Done this way instead of editing text files directly for conveniece.\n# File output needed for ssmtp.\n# TODO: Convert these to a single mailout function.\n\nmsg_wget_fail_txt=$(cat &lt;&lt; EOF\nSubject: wget failed (txt file)\n\nThe wget command to fetch the text file containing the path to the latest stage3 seed failed.\n\nThe currently set url is: $url$txtfile\nEOF\n)\n\nmsg_emaint_fail=$(cat &lt;&lt; EOF\nSubject: emaint sync failed\n\nemaint failed to sync.\nEOF\n)\n\nmsg_mv_seed=$(cat &lt;&lt; EOF\nSubject: Failed to mv seed\n\nSeed could not be moved to build dir.\nEOF\n)\n\nmsg_catalyst_snapshot_fail=$(cat &lt;&lt; EOF\nSubject: Catalyst snapshot failed\n\nCatalyst failed to create the latest snapshot.\nEOF\n)\n\nmsg_catalyst_stage1_fail=$(cat &lt;&lt; EOF\nSubject: Catalyst stage1 failed\n\nCatalyst failed to build stage1.\nEOF\n)\n\nmsg_catalyst_stage2_fail=$(cat &lt;&lt; EOF\nSubject: Catalyst stage2 failed\n\nCatalyst failed to build stage2.\nEOF\n)\n\nmsg_catalyst_stage3_fail=$(cat &lt;&lt; EOF\nSubject: Catalyst stage3 failed\n\nCatalyst failed to build stage3.\nEOF\n)\n\nmsg_catalyst_stage4_fail=$(cat &lt;&lt; EOF\nSubject: Catalyst stage4 failed\n\nCatalyst failed to build stage4.\nEOF\n)\n\n\n### PART 1: UPDATE SEED\n\n# Get text file describing latest stage3 tarball.\n# -O option circumvents wget creating a new file on every run and gives us a fixed filename to use.\n# The wget -S option is --server-response, which can be grepped.\n# ssmtp.conf has been configured.\nif &#91;&#91; `wget -S --spider $url$txtfile 2>&amp;1 | grep 'HTTP\/1.1 200 OK'` ]];\n\tthen wget -O latest.txt $url$txtfile;\n\telse\n\t\techo -e \"$msg_wget_fail_txt\" > wget_textfile_failmsg\n\t\tssmtp -v $email &lt; wget_textfile_failmsg\n\t\techo $remote_text_file_missing\n\t\texit 1;\nfi\n\n# Parse text file for URL\n# Use tail cmd to read last line of file, which is all we need,\n# then use sed to chop off everything after the space in that line\n# When wget is done, move the file to where its needed\n# (The mv destination is a symlink)\n# Not sure we need an ifelse here. If the above check passes, this wget should work.\nlatest=$(tail -n 1 latest.txt | sed 's#&#91;&#91;:space:]].*##')\nwget -O stage3seed.tar.xz $url$latest\nif &#91; $? != 0 ]; then\n\nmsg_wget_fail_seed=$(cat &lt;&lt; EOF\nSubject: wget failed (stage3 seed)\n\nThe wget command to fetch the latest stage3 seed failed.\n\nThe currently set url is $url$latest\nEOF\n)\n\techo -e \"$msg_wget_fail_seed\" > wget_seed_failmsg\n\tssmtp -v $email &lt; wget_seed_failmsg\n\techo $couldnt_get_stage3\n\texit 1;\nfi\n# Trailing slash prevents mv'ing seed to a new file.\nmv stage3seed.tar.xz builddir\/\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_mv_seed\" > mv_seed_failmsg\n\tssmtp -v $email &lt; mv_seed_failmsg\n\techo \"Failed to mv seed to build dir.\"\n\texit 1;\nfi\n\n### PART 2: SYNC\n\nemaint -a sync\nif &#91;  $? != 0 ]; then\n\techo -e \"$msg_emaint_fail\" > emaint_failmsg\n\tssmtp -v $email &lt; emaint_failmsg\n\techo \"Emaint sync failed. Notification sent to $email.\"\n\texit 1;\nfi\n\nemerge -uDN --keep-going --backtrack=250 @world\n#TODO: Error capture here.\n\ncatalyst -s latest\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_catalyst_snapshot_fail\" > catalyst_snapshot_failmsg\n\tssmtp -v $email &lt; catalyst_snapshot_failmsg\n\techo \"Catalyst could not create a snapshot. Notification sent to $email.\"\n\texit 1;\nfi\n\n### PART 3: STAGES\n\ncatalyst -af stage1.spec\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_catalyst_stage1_fail\" > catalyst_stage1_failmsg\n\tssmtp -v $email &lt; catalyst_stage1_failmsg\n\techo \"Catalyst failed to build stage1. Notification sent to $email.\"\n\texit 1;\nfi\n\ncatalyst -af stage2.spec\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_catalyst_stage2_fail\" > catalyst_stage2_failmsg\n\tssmtp -v $email &lt; catalyst_stage2_failmsg\n\techo \"Catalyst failed to build stage2. Notification sent to $email.\"\n\texit 1;\nfi\n\ncatalyst -af stage3.spec\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_catalyst_stage3_fail\" > catalyst_stage3_failmsg\n\tssmtp -v $email &lt; catalyst_stage3_failmsg\n\techo \"Catalyst failed to build stage3. Notification sent to $email.\"\n\texit 1;\nfi\n\ncatalyst -af stage4.spec\nif &#91; $? != 0 ]; then\n\techo -e \"$msg_catalyst_stage4_fail\" > catalyst_stage4_failmsg\n\tssmtp -v $email &lt; catalyst_stage4_failmsg\n\techo \"Catalyst failed to build stage4. Notification sent to $email.\"\n\texit 1;\nfi\n\ncompletion_time=$(date)\nmsg_catalyst_complete=$(cat &lt;&lt; EOF\nSubject: Catalyst build complete\n\nThe latest catalyst build completed at $completion_time.\nEOF\n)\necho -e \"$msg_catalyst_complete\" > catalyst_complete_msg\nssmtp -v $email &lt; catalyst_complete_msg\n\n### fscript is automatically executed by stage4.\n\n### PART 7: MV TARBALL TO WEB SERVER\n# Catalyst is actually running in a chroot, so this step requires a cron job on the host, as the chroot has no access to the web server.\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So this is version 1 of the new script to automate catalyst builds. There is a catalyst-auto from gentoo-releng, but 1. my needs for this purpose are much simpler than what catalyst-auto provides and 2. writing this script is proving to be fun. As always, suggestions welcome. #!\/bin\/sh ### VARS url=&#8221;https:\/\/distfiles.gentoo.org\/releases\/amd64\/autobuilds\/&#8221; txtfile=&#8221;latest-stage3-amd64-desktop-systemd.txt&#8221; email=&#8221;webmaster@gentoostudio.org&#8221; ### ERROR&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/dev.decibellinux.org\/?p=576\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"class_list":["post-576","post","type-post","status-publish","format-standard","hentry","category-blog","category-blog-catalyst-automation"],"_links":{"self":[{"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/posts\/576"}],"collection":[{"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=576"}],"version-history":[{"count":1,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.decibellinux.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}