commit a6d06e921e56ccacb3400072afcf8593c00a21a6 Author: = <=> Date: Mon Jul 31 21:29:01 2023 +1000 Initial Commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcf9b8e --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# elementaryos-config + +A bunch of scripts and commands that help with setting up elementaryos + +Use the following to run the script + +``` +sudo bash -c "$(wget -O - https://git.tcmeta.net/kurtis/elementaryos-config/raw/branch/main/setup.sh)" +``` + +What this script contains: + +- Install Deb Chromium and open urls for extensions to be added +- Install wireguard and wiregui +- Install wingpanel addons +- Install Appimage Launcher +- Add flathub repo +- Bunch of other stuff as well \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..61b3fbd --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2307312000 \ No newline at end of file diff --git a/elementaryos-config b/elementaryos-config new file mode 100644 index 0000000..83861b1 --- /dev/null +++ b/elementaryos-config @@ -0,0 +1,587 @@ +#!/bin/bash + +# Check for sudo access +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit +fi + +# Ensure we are running under bash +if [ "$BASH_SOURCE" = "" ]; then + /bin/bash "$0" + exit 0 +fi + +# Variables +VER=2307312000 +user_home=$(sudo -u $SUDO_USER sh -c 'echo $HOME') +URL=https://git.tcmeta.net/kurtis/elementaryos-config/raw/branch/main/ + +# Depriv + +depriv() { + if [[ $SUDO_USER ]]; then + sudo -u "$SUDO_USER" -- "$@" + else + "$@" + fi +} + + + + +# Dynamic Menu Library + +# +# Public Functions +# +# menuInit() +# menuLoop() +# +# +# Public Variables to Override +# +# Should these get passed into menuInit() rather than be set as global +# script variables? +# +# menuTop # Top row of menu (defaults to row 2) +# menuLeft # Left offset for menu item text (defaults to column 15) +# menuWidth # Width of menu (defaults to 42 columns) +# menuMargin # Left offset for menu border (defaults to column 4) +# +# menuColour # Colour of menu text (defaults to DRAW_COL_WHITE) +# menuHighlight # Highlight colour for menu (defaults to DRAW_COL_GREEN) +# +# menuTitle # Title of menu +# menuFooter # Footer text of menu +# +# menuItems # Array containing menu item text +# menuActions # Array containing functions to call upon menu item selection +# + + +# Ensure we are running under bash (will not work under sh or dash etc) +if [ "$BASH_SOURCE" = "" ]; then + echo "ERROR: bash-menu requires to be running under bash" + exit 1 +fi + +################################ +# Private Variables +# +# These should not be overridden +################################ +declare -a menuItems +declare -a menuActions + +menuHeaderText="" +menuFooterText="" +menuBorderText="" + + +################################ +# Setup Menu +# +# These are defaults which should +# be overridden as required. +################################ + +# Top of menu (row 2) +menuTop=2 + +# Left offset for menu items (not border) +menuLeft=15 + +# Width of menu +menuWidth=42 + +# Left offset for menu border (not menu items) +menuMargin=4 + +menuItems[0]="Exit" +menuActions[0]="return 0" + +menuItemCount=1 +menuLastItem=0 + +menuColour=$DRAW_COL_WHITE +menuHighlight=$DRAW_COL_GREEN + +menuTitle=" Super Bash Menu System" +menuFooter=" Enter=Select, Up/Down=Prev/Next Option" + + +################################ +# Initialise Menu +################################ +menuInit() { + menuItemCount=${#menuItems[@]} + menuLastItem=$((menuItemCount-1)) + + # Ensure header and footer are padded appropriately + menuHeaderText=`printf "%-${menuWidth}s" "$menuTitle"` + menuFooterText=`printf "%-${menuWidth}s" "$menuFooter"` + + # Menu (side) borders + local marginSpaces=$((menuMargin-1)) + local menuSpaces=$((menuWidth-2)) + local leftGap=`printf "%${marginSpaces}s" ""` + local midGap=`printf "%${menuSpaces}s" ""` + menuBorderText="${leftGap}x${midGap}x" +} + + +################################ +# Show Menu +################################ +menu_Display() { + local menuSize=$((menuItemCount+2)) + local menuEnd=$((menuSize+menuTop+1)) + + drawClear + drawColour $menuColour $menuHighlight + + # Menu header + drawHighlightAt $menuTop $menuMargin "$menuHeaderText" 1 + + # Menu (side) borders + for row in $(seq 1 $menuSize); do + drawSpecial "$menuBorderText" 1 + done + + # Menu footer + drawHighlightAt $menuEnd $menuMargin "$menuFooterText" 1 + + # Menu items + for item in $(seq 0 $menuLastItem); do + menu_ClearItem $item + done +} + + +################################ +# Mark Menu Items +################################ + +# Ensure menu item is not highlighted +menu_ClearItem() { + local item=$1 + local top=$((menuTop+item+2)) + local menuText=${menuItems[$item]} + + drawPlainAt $top $menuLeft "$menuText" +} + +# Highlight menu item +menu_HighlightItem() { + local item=$1 + local top=$((menuTop+item+2)) + local menuText=${menuItems[$item]} + + drawHighlightAt $top $menuLeft "$menuText" +} + + +################################ +# Wait for and process user input +################################ +menu_HandleInput() { + local choice=$1 + + local after=$((choice+1)) + [[ $after -gt $menuLastItem ]] && after=0 + + local before=$((choice-1)) + [[ $before -lt 0 ]] && before=$menuLastItem + + # Clear highlight from prev/next menu items + menu_ClearItem $before + menu_ClearItem $after + + # Highlight current menu item + menu_HighlightItem $choice + + # Get keyboard input + local key="" + local extra="" + + read -s -n1 key 2> /dev/null >&2 + while read -s -n1 -t .05 extra 2> /dev/null >&2 ; do + key="$key$extra" + done + + # Handle known keys + local escKey=`echo -en "\033"` + local upKey=`echo -en "\033[A"` + local downKey=`echo -en "\033[B"` + + if [[ $key = $upKey ]]; then + return $before + elif [[ $key = $downKey ]]; then + return $after + elif [[ $key = $escKey ]]; then + if [[ $choice -eq $menuLastItem ]]; then + # Pressing Esc while on last menu item will trigger action + # This is a helper as we assume the last menu option is exit + key="" + else + # Jumping possibly more than 1 (next/prev) item + menu_ClearItem $choice + return $menuLastItem + fi + elif [[ ${#key} -eq 1 ]]; then + # See if we wanrt to jump to a menu item + # by entering the first character + for index in $(seq 0 $menuLastItem) ; do + local item=${menuItems[$index]} + local startChar=${item:0:1} + if [[ "$key" = "$startChar" ]]; then + # Jumping possibly more than 1 (next/prev) item + menu_ClearItem $choice + return $index + fi + done + fi + + if [[ "$key" = "" ]]; then + # Notify that Enter key was pressed + return 255 + fi + + return $choice +} + + +################################ +# Main Menu Loop +################################ +menuLoop() { + local choice=0 + local running=1 + + menu_Display + + while [[ $running -eq 1 ]]; do + # Enable case insensitive matching + local caseMatch=`shopt -p nocasematch` + shopt -s nocasematch + + menu_HandleInput $choice + local newChoice=$? + + # Revert to previous case matching + $caseMatch + + if [[ $newChoice -eq 255 ]]; then + # Enter pressed - run menu action + drawClear + action=${menuActions[$choice]} + $action + running=$? + + # Back from action + # If we are still running, redraw menu + [[ $running -eq 1 ]] && menu_Display + + elif [[ $newChoice -lt $menuItemCount ]]; then + # Update selected menu item + choice=$newChoice + fi + done + + # Cleanup screen + drawClear +} + +# +# Public Functions: +# +# drawClear() +# drawColour(colour = DRAW_COL_DEF, bgColour = DRAW_COL_DEF) +# +# drawPlain(text, newLine = 0) +# drawSpecial(text, newLine = 0) +# drawHighlight(text, newLine = 0) +# drawPlainAt(left, top, text, newLine = 0) +# drawHighlightAt(left, top, text, newLine = 0) +# +# +# Colours +# +# DRAW_COL_DEF # Default colour +# DRAW_COL_BLACK +# DRAW_COL_WHITE +# DRAW_COL_RED +# DRAW_COL_GREEN +# DRAW_COL_YELLOW +# DRAW_COL_BLUE +# DRAW_COL_GRAY # Light gray (grey?) +# + + +# Ensure we are running under bash (will not work under sh or dash etc) +if [ "$BASH_SOURCE" = "" ]; then + echo "ERROR: bash-draw requires to be running under bash" + exit 1 +fi + + +DRAW_COL_DEF=39 +DRAW_COL_BLACK=30 +DRAW_COL_WHITE=97 +DRAW_COL_RED=31 +DRAW_COL_GREEN=32 +DRAW_COL_YELLOW=33 +DRAW_COL_BLUE=34 +DRAW_COL_GRAY=37 + + +# drawClear() +drawClear() { + $ESC_WRITE "\033c" +} + +# drawColour(colour = DRAW_COL_DEF, bgColour = DRAW_COL_DEF) +drawColour() { + local colour=$DRAW_COL_DEF + local bgColour=$((DRAW_COL_DEF+10)) + + if [[ ! -z "$1" && "$1" != "" ]]; then + colour="$1" + fi + + if [[ ! -z "$2" && "$2" != "" ]]; then + bgColour="$2" + fi + + $ESC_ECHO "\033c\033[H\033[J\033[${colour};${bgColour}m\033[J" +} + +# drawPlain(text, newLine = 0) +drawPlain() { + if [[ -z "$2" || "$2" -eq 0 ]]; then + $ESC_WRITE "$1" + else + $ESC_ECHO "$1" + fi +} + +# drawSpecial(text, newLine = 0) +drawSpecial() { + [[ -z "$2" ]] && newLine=0 || newLine="$2" + + draw_SetDrawMode + drawPlain "$1" "$newLine" + draw_SetWriteMode +} + +# drawHighlight(text, newLine = 0) +drawHighlight() { + [[ -z "$2" ]] && newLine=0 || newLine="$2" + + draw_StartHighlight + drawPlain "$1" "$newLine" + draw_EndHighlight +} + +# drawPlainAt(left, top, text, newLine = 0) +drawPlainAt() { + [[ -z "$4" ]] && newLine=0 || newLine="$4" + + draw_MoveTo $1 $2 + drawPlain "$3" "$newLine" +} + +# drawHighlightAt(left, top, text, newLine = 0) +drawHighlightAt() { + [[ -z "$4" ]] && newLine=0 || newLine="$4" + + draw_StartHighlight + drawPlainAt "$1" "$2" "$3" "$newLine" + draw_EndHighlight +} + + +# Write escape sequence with no newline +ESC_WRITE='echo -en' + +# Write escape sequence adding newline +ESC_ECHO='echo -e' + + +# Move cursor to specified location +draw_MoveTo() { + $ESC_WRITE "\033[${1};${2}H" +} + +draw_StartHighlight() { + $ESC_WRITE "\033[7m" +} + +draw_EndHighlight() { + $ESC_WRITE "\033[27m" +} + +draw_SetDrawMode() { + $ESC_WRITE "\033%@\033(0" +} + +draw_SetWriteMode() { + $ESC_WRITE "\033(B" +} + +# My Functions + +add_flathub() { + echo "Adding flathub to flatpak" + + flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + + echo -n "Done. Press enter to continue ... " + read response + + return 1 +} + +install_fish() { + echo "Installing Fish" + + apt install -y fish + depriv chsh -s /usr/bin/fish + depriv mkdir -p ${user_home}/.local/bin + depriv mkdir -p ${user_home}/.local/fish + depriv echo "SETUVAR fish_user_paths:${user_home}/\x2elocal/bin" > ${user_home}/.local/fish/fish_variables + + install_starship +} + +install_starship() { + echo "Installing Starship" + + echo "Installing NerdFont" + + depriv wget -P /tmp/ https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/DroidSansMono.zip + depriv unzip /tmp/DroidSansMono.zip -d ${user_home}/.fonts + depriv fc-cache -fv + depriv rm /tmp/DroidSansMono.zip + + wget -qO /tmp/starship.sh https://starship.rs/install.sh + sh /tmp/starship.sh + + depriv echo "starship init fish | source" >> ${user_home}/.config/fish/config.fish + + echo -n "Done. Press enter to continue ... " + read response + + return 1 +} + +install_wireguard() { + echo "Installing Wireguard and Wiregui" + + apt install -y wireguard + wget -P /tmp/ https://github.com/Devsfy/wiregui/releases/download/1.8.1/wiregui_1.8.1_amd64.deb + apt install -y /tmp/wiregui_1.8.1_amd64.deb + rm /tmp/wiregui_1.8.1_amd64.deb + + echo -n "Done. Press enter to continue ... " + read response + + return 1 +} + +install_wingpanel_addon() { + echo "Installing wingpanel indicator 2.0.10" + + apt install -y libglib2.0-dev libgranite-dev libindicator3-dev libjson-glib-dev libwingpanel-dev indicator-application gir1.2-appindicator3-0.1 + wget -P /tmp/ https://github.com/MvBonin/wingpanel-community-indicators/releases/download/2.0.10/com.github.mvbonin.wingpanel-community-indicators_2.0.10_amd64.deb + apt install -y /tmp/com.github.mvbonin.wingpanel-community-indicators_2.0.10_amd64.deb + rm /tmp/com.github.mvbonin.wingpanel-community-indicators_2.0.10_amd64.deb + depriv mkdir -p ${user_home}/.config/autostart + depriv cp /etc/xdg/autostart/indicator-application.desktop ${user_home}/.config/autostart/ + + echo -n "Done. Press enter to continue ... " + read response + + return 1 +} + +install_chrome_deb() { + echo "Installing Chromium deb packages" + + apt install -y software-properties-common + add-apt-repository ppa:savoury1/chromium + apt update + apt install -y chromium-browser + + echo -n "Install chromium extensions? [Y/n]" + read -r ans + case $ans in + y) + depriv chromium-browser https://chrome.google.com/webstore/detail/nngceckbapebfimnlniiiahkandclblb >/dev/null 2>/dev/null + depriv chromium-browser https://chrome.google.com/webstore/detail/fnaicdffflnofjppbagibeoednhnbjhg >/dev/null 2>/dev/null + depriv chromium-browser https://chrome.google.com/webstore/detail/cjpalhdlnbpafiamejdnhcphjbkeiagm >/dev/null 2>/dev/null + depriv chromium-browser https://chrome.google.com/webstore/detail/bfhkfdnddlhfippjbflipboognpdpoeh >/dev/null 2>/dev/null + depriv chromium-browser https://chrome.google.com/webstore/detail/bkjdcppkdgccnhjibfhlhmeiafnjfamk >/dev/null 2>/dev/null + ;; + esac + echo -n "Done. Press enter to continue ... " + read response + + return 1 +} + +update_elementaryos_config() { + echo "Checking for updates" + + CURVER=$(wget -q -O - "${URL}VERSION") + if [ "$CURVER" -gt "$VER" ]; then + echo Update available! Downloading. + wget -q -O /usr/local/bin/elementaryos-config "${URL}vargtools" + chmod +x /usr/local/bin/elementaryos-config + echo Done! Restarting! + exec /usr/local/bin/elementaryos-config + else + echo -n "Script up to date. Press enter to continue ... " + read response + + return 1 + fi +} + +## Override some menu defaults +menuTitle=" ElementaryOS Config" +menuFooter=" Enter=Select, Navigate via Up/Down/First number/letter" +menuWidth=82 +menuLeft=25 +menuHighlight=$DRAW_COL_YELLOW + +# Menu Item Text +# NOTE: If these are not all the same width +# the menu highlight will look wonky +menuItems=( + "1. Add Flathub Repo to flatpak " + "2. Install Fish and starship " + "3. Install Wireguard and Wiregui" + "4. Install Wingpanel Addons " + "5. Install Chromium deb " + "U. Update elementaryos-config " + "Q. Exit " +) + +## Menu Item Actions +menuActions=( + add_flathub + install_fish + install_wireguard + install_wingpanel_addon + install_chrome_deb + update_elementaryos_config + quit_menu +) + +# Start First Menu +menuInit +menuLoop + +exit 0 \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..41cd875 --- /dev/null +++ b/setup.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# download script +echo "Downloading elementaryos-config" + +wget -q -O /usr/local/bin/elementaryos-config https://git.tcmeta.net/kurtis/elementaryos-config/raw/branch/main/vargtools +chmod +x /usr/local/bin/elementaryos-config + +echo Done you should now be able to start the script by typing sudo elementaryos-config \ No newline at end of file