Last active
August 12, 2025 19:47
-
-
Save DennisLfromGA/f0abd21fba3a527b43749040ddd4f5d4 to your computer and use it in GitHub Desktop.
A script to remove rootfs verification and install an openssh server - needs to be run twice with two reboots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ### | |
| APPLICATION="${0##*/}" | |
| ARCHIVE='' | |
| CURRENTROOT="$(rootdev -s)" | |
| GO='' | |
| HOM=$HOME | |
| NUM='0' | |
| REV=4 # Added check for root.*.tgz & ui.mini plus cleanup | |
| SUDO='' | |
| TMOUT='5' | |
| ret=0 | |
| ## Exits the script with exit code $1, spitting out message $@ to stderr | |
| error() { | |
| local ecode="$1" | |
| shift | |
| echo "$*" 1>&2 | |
| exit "$ecode" | |
| } | |
| #### | |
| #### If we're not running as root, restart as root. | |
| if [ ${UID:-$(id -u)} -ne 0 ]; then | |
| echo "Must be superuser to run." | |
| echo "Use 'sudo' or become root first ..." | |
| exit 1 | |
| ## echo "...elevating $USER to superuser..." | |
| ## echo | |
| ## exec sudo /bin/sh -e "$0" "$@" | |
| #### If we're not running as root, use sudo | |
| # echo "...elevating $USER to superuser via 'sudo'..." | |
| # echo | |
| # SUDO='sudo' | |
| fi | |
| ### | |
| ### Check to see if rootfs is read-write | |
| if ${SUDO} mount -i -o remount,rw / 2>/dev/null; then | |
| echo "Your rootfs (${CURRENTROOT}) is mounted read-write ..." | |
| echo "*** $(mount | grep ' / ') ***"; echo | |
| else | |
| # ## Check for bootcache fix ... | |
| # ret=$(grep -iq bootcache /usr/share/vboot/bin/make_dev_ssd.sh; echo $?) | |
| # if [ $ret -gt 0 ]; | |
| # then echo "$ret: No 'bootcache' fix appplied yet. :(" | |
| # error 2 "Not safe to continue, exiting..."/ | |
| # else echo "$ret: The 'bootcache' fix has been appplied - yay. :)" | |
| # echo "You can now run 'rw-rootfs' safely." | |
| # fi | |
| echo "Making your rootfs read-write ..." | |
| /usr/libexec/debugd/helpers/dev_features_rootfs_verification || echo "'rootfs' modification failed ..." | |
| echo "*** Rebooting in $TMOUT seconds to make changes effective ***" 1>&2 | |
| read -t $TMOUT -p "... ENTER 'a' TO ABORT! " GO | |
| if [ -n "${GO}" ]; then error 0 "Okay, ABORTING ..."; fi | |
| reboot && exit | |
| # echo -n "... Press Ctrl-C to ABORT ... " 1>&2 | |
| # sleep 10 && $SUDO reboot && exit $ret | |
| fi | |
| ### Remove search for both crouton & linux partitions | |
| ### | |
| ### Check for crouton functions file ( for mounting custom partitions ) | |
| #crouton_mount='/var/crouton' | |
| #linux_mount='/var/linux' | |
| #if [ -s /usr/local/bin/cros_funcs ]; then | |
| # . /usr/local/bin/cros_funcs | |
| # ## mount Linux partition if it exists | |
| # mountlinux $linux_mount && echo "...a LINUX partition is${PRIOR} mounted on '$MOUNTLINUX'." | |
| ## ${SUDO} mount -B /var/linux/ /mnt/stateful_partition/crouton/shared/linux/ | |
| # ## mount CROUTON partition if it exists | |
| # mountcrouton $crouton_mount && echo "...a CROUTON partition is${PRIOR} mounted on '$MOUNTCROUTON'." | |
| #else | |
| # ROOTDEVICE="`rootdev -d -s`" | |
| # ## mount Linux partition if it exists | |
| # linuxpart="`${SUDO} cgpt find -n -l ROOT-C "$ROOTDEVICE"`" | |
| # if [ "`${SUDO} cgpt show -i "$linuxpart" -s "$ROOTDEVICE"`" -gt 1 ]; then | |
| # [ ! -d $linux_mount ] && ${SUDO} mkdir -p $linux_mount 2>/dev/null | |
| # [ -d $linux_mount ] && ${SUDO} mount ${ROOTDEVICE}/$linuxpart $linux_mount 2>/dev/null | |
| # [ -d ${linux_mount}/crouton ] && ${SUDO} mount -o bind ${linuxpart}/crouton $crouton_mount 2>/dev/null | |
| # fi | |
| # ## mount crouton partition if it exists | |
| # croutonpart="`${SUDO} cgpt find -n -l CROUTON "$ROOTDEVICE"`" | |
| # if [ "`${SUDO} cgpt show -i "$croutonpart" -s "$ROOTDEVICE"`" -gt 1 ]; then | |
| # [ ! -d $crouton_mount ] && ${SUDO} mkdir -p $crouton_mount 2>/dev/null | |
| # [ -d $crouton_mount ] && ${SUDO} mount ${ROOTDEVICE}/$croutonpart $crouton_mount 2>/dev/null | |
| # fi | |
| #fi | |
| # ### | |
| # ### Make chronos/user HOME | |
| # if [ $SUDO_USER=chronos ]; then | |
| # HOM="/home/chronos/user" | |
| # fi | |
| # | |
| ### | |
| ### CHECKING FOR ARCHIVE FOLDER | |
| ARCHIVE=/var/crouton/archive | |
| if [ ! -d $ARCHIVE ]; then | |
| echo "Standard location of folder $ARCHIVE not found..." | |
| if [ -d ${HOM}/Downloads/archive ]; then | |
| echo -n "Found one... " | |
| ARCHIVE="${HOM}/Downloads/archive" | |
| echo "Using $ARCHIVE ..." | |
| elif [ -d /var/linux/archive ]; then | |
| echo -n "Found one... " | |
| ARCHIVE="/var/linux/archive" | |
| echo "Using $ARCHIVE ..." | |
| elif [ -r ./$APPLICATION ]; then | |
| echo -n "Found one... " | |
| ARCHIVE="`pwd`" | |
| echo "Using $ARCHIVE ..." | |
| else | |
| echo "Sorry, an archive folder could not be found..." | |
| echo "Aborting archive file installation..." | |
| # exit 1 | |
| fi | |
| else | |
| echo "Using $ARCHIVE ..." | |
| ### | |
| ### ROUTINE TO INSTALL CONF FILES IF NEEDED | |
| INIT=/etc/init | |
| OPENSSH=0 | |
| cd $ARCHIVE | |
| echo "Checking upstart files in /etc/init." | |
| for CONF in *.conf | |
| do | |
| if [ ! -s ${INIT}/$CONF ]; then | |
| echo "file `cp -v $ARCHIVE/$CONF $INIT` installed..." | |
| NUM=$(($NUM+1)) | |
| elif ! diff ${INIT}/$CONF ${ARCHIVE}/$CONF 2>/dev/null 1>&2; then | |
| echo "file `cp -v ${ARCHIVE}/$CONF $INIT` updated..." | |
| NUM=$(($NUM+1)) | |
| else | |
| echo "file '${INIT}/$CONF' previously installed..." | |
| fi | |
| # if [ "$CONF" = "openssh-server.conf" ]; then | |
| # OPENSSH=1 | |
| # fi | |
| done | |
| fi | |
| # ### | |
| # ### CHANGE chromeos-boot-alert script delay from 30 seconds to 3 seconds | |
| # SBIN=/sbin | |
| # if ! diff ${SBIN}/chromeos-boot-alert ${ARCHIVE}/chromeos-boot-alert 2>/dev/null 1>&2; then | |
| # echo "file `cp -v ${ARCHIVE}/chromeos-boot-alert $SBIN` updated..." | |
| # chmod +x ${SBIN}/chromeos-boot-alert 2>/dev/null | |
| # NUM=$(($NUM+1)) | |
| # else | |
| # echo "file '${SBIN}/chromeos-boot-alert' not present or previously installed..." | |
| # fi | |
| ### | |
| ### Check for openssh server setup | |
| #echo | |
| #if ! /usr/libexec/debugd/helpers/dev_features_ssh --q ; then | |
| # ### | |
| # ### Setup openssh-server | |
| # echo "Setting up new openssh server ..." | |
| # /usr/libexec/debugd/helpers/dev_features_ssh | |
| # NUM=$(($NUM+1)) | |
| # echo "'openssh' server will start in /etc/init ..." | |
| #else | |
| # echo "An openssh server was previously setup ..." | |
| # ls -Ll /etc/init/openssh-server.conf | |
| #fi | |
| ### | |
| ### Check for root files | |
| echo | |
| if [ -f /root/.bash_profile ]; then | |
| echo "root files are alread in place ..." | |
| elif [ -f /usr/local/src/root.*.tgz ]; then | |
| echo "Found root files, installing..." | |
| cd /usr/local/src | |
| tar xvaf root.*.tgz -C / | |
| cd | |
| NUM=$(($NUM+1)) | |
| else | |
| echo "No root.tgz file found ..." | |
| fi | |
| ### | |
| ### Check for ui.mini | |
| echo | |
| if grep -q minioverride.so /etc/init/ui.conf; then | |
| echo "ui.mini changes already applied ..." | |
| elif [ -f /usr/local/src/ui.mini ]; then | |
| echo "Found ui.mini file, adding it to ui.conf next..." | |
| # echo "Editing ui.conf next ..." | |
| # cd /usr/local/src | |
| # nvim +39 /etc/init/ui.conf | |
| sleep 3 | |
| cd /etc/init | |
| sed -i '40i\\n# Add below to bypass sudo restriction for chronos\nenv LD_PRELOAD=/usr/local/src/minioverride.so' ui.conf | |
| cd | |
| NUM=$(($NUM+1)) | |
| else | |
| echo "No ui.mini file found ..." | |
| fi | |
| ### | |
| ### Reboot if needed. | |
| echo | |
| if [ $NUM -gt 0 ]; then | |
| echo "NOTE: Reboot for $NUM changes to be applied." | |
| echo "*** Rebooting in $TMOUT seconds to make changes effective ***" 1>&2 | |
| read -t $TMOUT -p "... ENTER 'a' TO ABORT! " GO | |
| if [ -n "${GO}" ]; then error 0 "Okay, ABORTING ..."; fi | |
| reboot && exit $ret | |
| else | |
| echo "### No changes needed/made." | |
| fi |
Author
Author
Revision 4: Added check for root.*.tgz & ui.mini plus cleanup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revision 3: Minor changes.