Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install.sh: Simplify syntax and improvements #9223

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

supechicken
Copy link
Member

@supechicken supechicken commented Jan 26, 2024

Changes

  • Check for sudo availability in a more elegant way
  • Group constants in a place
  • Import /etc/lsb-release directly instead of using grep
  • Replace all $(id -u) calls with ${EUID}
  • Align comments
  • Put repository URLs into variables
  • Remove pixz since .pixz should be backward compatible with xz
  • Only extract files specified in git sparse-checkout from the repo tarball
  • Simplify syntax
  • Use array on BOOTSTRAP_PACKAGES instead of string

Not tested yet

@satmandu
Copy link
Member

Please try in containers!

: "${GTIHUB_OWNER:=chromebrew}"
: "${GITHUB_REPO:=chromebrew}"
: "${GITHUB_BRANCH:=master}"
: "${GITLAB_REPO:=26210301}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't know if there's any practical value to changing the gitlab repo, I don't know of any other repos that mirror our package repository or would be otherwise useful to switch to.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to set the PREBUILT_URL variable below to reduce duplicate long assignments. This is actually good because if this value changes in the future, we only have to change in one place...here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be the same if we just had the value set in PREBUILT_URL? I'm not a fan of single-use variables.

@@ -102,15 +109,17 @@ fi

if [[ "$ARCH" == "x86_64" ]]; then
LIB_SUFFIX='64'
else
LIB_SUFFIX=''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is LIB_SUFFIX not already empty by default, since we don't set the variable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to set it explicitly for clarity and in the off chance it's set outside of crew.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce?

LIB_SUFFIX=''
[[ "${ARCH}" == "x86_64" ]] && LIB_SUFFIX='64'

@@ -194,16 +200,16 @@ for package in $BOOTSTRAP_PACKAGES; do
# This is really ugly, FIXME after #7082 is merged.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously this isn't something you have to do, but if you wanted you could change the code to not have two copies of each url based on the tar compression, and instead use the value of binary_compression now that that's a possibility.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, I'll get around to it soon.


# Check if the script is being run as root.
if [ "${EUID}" == "0" ]; then
echo_error "Chromebrew should not be installed or run as root."
echo_info "Please login as 'chronos' and restart the install."
echo_info "Please login as 'chronos' and restart the install."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?

exit 1
fi

# Reject crostini.
if [[ -d /opt/google/cros-containers && "${CREW_FORCE_INSTALL}" != '1' ]]; then
echo_error "Crostini containers are not supported by Chromebrew :/"
echo_info "Run 'CREW_FORCE_INSTALL=1 exec bash --init-file <(curl -Ls git.io/vddgY)' to perform install anyway"
echo_info "Run 'CREW_FORCE_INSTALL=1 exec bash --init-file <(curl -Ls git.io/vddgY)' to perform install anyway"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?

echo_error "Please run the installer in the VT-2 shell."
echo_info "To start the VT-2 session, type Ctrl + Alt + ->"
echo_info "To start the VT-2 session, press Ctrl + Alt + -> and login with user 'chronos'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End sentence with a .?

echo_info "This will delete ALL files in ${CREW_PREFIX}!"
echo_info "Continue?"
echo_info "This will delete ALL files in ${CREW_PREFIX}!"
echo_info "Continue?"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space?

export "$(grep CHROMEOS_RELEASE_CHROME_MILESTONE /etc/lsb-release)"
else
echo_info "Unable to detect system information, installation will continue."
if ! [[ "${CHROMEOS_RELEASE_TRACK}" == 'stable-channel' || "${CREW_FORCE_INSTALL}" == '1' ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [[ -z "${CREW_FORCE_INSTALL}" && "${CHROMEOS_RELEASE_TRACK}" != 'stable-channel' ]]; then?

: "${CREW_CACHE_DIR:=$CREW_PREFIX/tmp/packages}"

BOOTSTRAP_PACKAGES=(zstd crew_mvdir ruby git ca_certificates openssl)
SPARSE_CHECKOUT=(packages manifest/${USER_SPACE_ARCH} lib bin crew tests tools)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER_SPACE_ARCH not defined yet?

echo_info "If this happens, please report them to: https://github.com/chromebrew/chromebrew/issues"
echo_info "If the install fails, try running 'CREW_AMD_INSTALL=1 exec bash --init-file <(curl -Ls git.io/vddgY)'"
echo_info "If this happens, please report them to: ${REPO_URL}/issues"
echo_info "If the install fails, try running 'CREW_AMD_INSTALL=1 exec bash --init-file <(curl -L git.io/vddgY)'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you are starting to think like me. I don't like when ANY command is silenced.

else
urls+=("https://gitlab.com/api/v4/projects/26210301/packages/generic/${name}/${version}_${ARCH}/${name}-${version}-chromeos-${ARCH}.tar.zst")
urls+=("${PREBUILT_URL}/${name}/${version}_${ARCH}/${name}-${version}-chromeos-${ARCH}.tar.zst")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce "${PREBUILT_URL}/${name}/${version}_${ARCH}/${name}-${version}-chromeos-${USER_SPACE_ARCH}.tar.${ARCHIVE_EXTENSION}" to one line and simply assign ARCHIVE_EXTENSION instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we don't need to assign ARCHIVE_EXTENSION, we can just use the binary_compression value in each package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(once this is rebased onto master, this review is no longer relevant)

@@ -3,56 +3,81 @@
# Exit on fail.
set -e

RESET='\e[0m'
# Default chromebrew repo values.
: "${GTIHUB_OWNER:=chromebrew}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GITHUB_OWNER?

@uberhacker
Copy link
Collaborator

@supechicken: Did you want to merge master into this PR branch and resolve merge conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants