Skip to content

Instantly share code, notes, and snippets.

@syntaxbender
Created April 29, 2025 21:30
Show Gist options
  • Save syntaxbender/39252c2927515db75f047606f4f25244 to your computer and use it in GitHub Desktop.
Save syntaxbender/39252c2927515db75f047606f4f25244 to your computer and use it in GitHub Desktop.
install_cromite.sh
#!/bin/bash
if [[ "$EUID" -ne 0 ]]; then
echo "Please run as root! exiting..."
exit 1
fi
INFO_URL="https://github.com/uazo/cromite/releases/latest/download/updateurl.txt"
DOWNLOAD_URL="https://github.com/uazo/cromite/releases/latest/download/chrome-lin64.tar.gz"
CROMITE_DIR=/opt/cromite-lin64
APP_DIR=$CROMITE_DIR/app
UPDATE_DIR=$CROMITE_DIR/update
APPLICATIONS_PATH=/usr/share/applications
SERVICES_PATH=/etc/systemd/system
PROFILE_PATH=/etc/profile
UPDATE_SCRIPT_PATH=$UPDATE_DIR/update.sh
install(){
[[ -d "$CROMITE_DIR" ]] && \
uninstall
local UPDATE_FLAG=false
[[ "$1" == "--update" ]] && \
UPDATE_FLAG=true
mkdir -p $APP_DIR && \
mkdir -p $UPDATE_DIR || { echo "Failed while creating cromite directory. Check permissions of cromite directory."; exit 1; }
wget -q --show-progress -O $UPDATE_DIR/info_local.env $INFO_URL && \
wget -q --show-progress -O $UPDATE_DIR/cromite.tar.gz $DOWNLOAD_URL || {
echo "Download unsuccessfull! exiting..."
exit 1
}
#source "$UPDATE_DIR/info_local.env" || { echo "info_local.env can't sourced. exiting..."; exit 1; }
tar --strip-components=1 -xzf $UPDATE_DIR/cromite.tar.gz -C $APP_DIR || { echo "Tar extraction failed."; exit 1; }
#grep -Fq "$APP_DIR" ~/.bashrc || echo "export PATH=\"${APP_DIR}:\$PATH\"" >> $PROFILE_PATH
if [[$UPDATE_FLAG == "false"]]; then
create_desktop_file
create_service_file
fi
}
uninstall(){
pkill chrome
local HARD_FLAG=false
[[ "$1" == "--hard" ]] && \
HARD_FLAG=true
rm -rf $CROMITE_DIR
if $HARD_FLAG; then
rm $APPLICATIONS_PATH/cromite-browser.desktop
rm $SERVICES_PATH/cromite-updater.service
#sed -i "/${APP_DIR}/d" $PROFILE_PATH
fi
}
update(){
#source $UPDATE_DIR/info_local.env || { echo "info.env can't sourced. exiting..."; exit 1; }
if ! curl -fsSL "$INFO_URL" | tr ';' '\n' | while IFS='=' read -r key value; do
[[ "$key" == "version" ]] && \
UPDATE_VERSION=$value
done; then
echo "Can't get env file: $INFO_URL"
exit 1
fi
if [[ -r "$UPDATE_DIR/info_local.env" ]]; then
while IFS='=' read -r key value; do
[[ "$key" == "version" ]] && \
LOCAL_VERSION="$value"
done < <(tr ';' '\n' < "$UPDATE_DIR/info_local.env")
else
echo "Local env read failed: $UPDATE_DIR/info_local.env"
exit 1
fi
latest=$(printf "%s\n%s\n" "$UPDATE_VERSION" "$LOCAL_VERSION" | sort -V | tail -n 1)
if [[ "$UPDATE_VERSION" != "$LOCAL_VERSION" ]]; then
install --update
else
echo ""
fi
}
create_service_file(){
if [[ -d "$SERVICES_PATH" ]]; then
cat > "$SERVICES_PATH/cromite-updater.service" <<EOF
[Unit]
Description=Cromite Updater Service
After=network.target
[Service]
Type=oneshot
ExecStart=$UPDATE_SCRIPT_PATH
RemainAfterExit=false
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon reload
else
echo "$SERVICES_PATH does not exists. The service file could not be created."
fi
}
create_desktop_file(){
if [[ -d "$APPLICATIONS_PATH" ]]; then
cat > "$APPLICATIONS_PATH/cromite-browser.desktop" <<EOF
[Desktop Entry]
Version=1.0
Name=Cromite Web Browser
GenericName=Web Browser
# Gnome and KDE 3 uses Comment.
Comment=Access the Internet
Exec=$APP_DIR/chrome %U
StartupWMClass=chromium-browser
StartupNotify=true
Terminal=false
Icon=org.chromium.Chromium
Type=Application
Categories=Network;WebBrowser;
Keywords=chrome;internet;google;
MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;
Actions=new-window;new-private-window;
[Desktop Action new-window]
Name=New Window
Exec=$APP_DIR/chrome
[Desktop Action new-private-window]
Name=New Incognito Window
Exec=$APP_DIR/chrome --incognito
EOF
else
echo "$APPLICATIONS_PATH does not exists. The service file could not be created."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment