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

Allow batch mode installation #5893

Open
wants to merge 6 commits into
base: master
from

Conversation

@loket
Copy link

loket commented Feb 18, 2017

Replacement for #5892.

Installing Oh My Zsh is currently not possible as part of a batch script (see #5873).

This pull request adds a --batch argument to allow installation without launching zsh at the end, allowing the installation script to be combined with other scripts.

Also updated readme with instructions.

Edit: To test the pull request, replace https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh with https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh. Something like this:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh)" -s --batch || {
  echo "Could not install Oh My Zsh" >/dev/stderr
  exit 1
}
@BurningSmile

This comment has been minimized.

Copy link

BurningSmile commented Feb 24, 2017

I would very much appreciate if this was accepted, this would fix my issue with scripting this as well!

I will go about testing this in some scripts in vm envs and let you know how it goes!

EDIT- It worked

--batch: zsh will not be started after installation
Cloning Oh My Zsh...
Cloning into '/home/david/.oh-my-zsh'...
remote: Counting objects: 829, done.
remote: Compressing objects: 100% (699/699), done.
remote: Total 829 (delta 14), reused 739 (delta 9), pack-reused 0
Receiving objects: 100% (829/829), 565.68 KiB | 0 bytes/s, done.
Resolving deltas: 100% (14/14), done.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
Time to change your default shell to zsh!
Changing shell for david.
Password: 
Shell changed.
         __                                     __   
  ____  / /_     ____ ___  __  __   ____  _____/ /_  
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ 
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / 
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  
                        /____/                       ....is now installed!


Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us at https://twitter.com/ohmyzsh.

p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.

it worked

Script in question using the function described by @loket in issue #5873

#install zshell
sudo pacman -S zsh --noconfirm

#install ohmyzsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh)" -s --batch || {
  echo "Could not install Oh My Zsh" >/dev/stderr
  exit 1
}
echo "it worked"

EDIT2 Also just tested with

sh -c "$(curl -fsSL https://raw.githubusercontent.com/loket/oh-my-zsh/feature/batch-mode/tools/install.sh)"

Works as expected and enters zshell as normal behavior of the current install script for ohmyzsh.

Cloning Oh My Zsh...
Cloning into '/home/david/.oh-my-zsh'...
remote: Counting objects: 829, done.
remote: Compressing objects: 100% (699/699), done.
remote: Total 829 (delta 14), reused 739 (delta 9), pack-reused 0
Receiving objects: 100% (829/829), 565.68 KiB | 0 bytes/s, done.
Resolving deltas: 100% (14/14), done.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
Time to change your default shell to zsh!
Changing shell for david.
Password: 
Shell changed.
         __                                     __   
  ____  / /_     ____ ___  __  __   ____  _____/ /_  
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ 
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / 
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  
                        /____/                       ....is now installed!


Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us at https://twitter.com/ohmyzsh.

p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.

➜  ~ 
@BurningSmile
Copy link

BurningSmile left a comment

These work perfectly without flaw!

@loket

This comment has been minimized.

Copy link
Author

loket commented Apr 25, 2017

Should maybe consider renaming from --batch to something like --non-interactive?

@AndrewSB

This comment has been minimized.

Copy link

AndrewSB commented May 6, 2017

+1 can we get someone a contributor to look at this and get it merged in? This worked for me too

@YuMS

This comment has been minimized.

Copy link

YuMS commented May 31, 2017

@loket --no-run-after, ` will help people get the point at first glance.

@loket

This comment has been minimized.

Copy link
Author

loket commented May 31, 2017

@YuMS: Fine by me 😄 Any other suggestions? Otherwise I'll try to update the PR soon.

@Jubijub

This comment has been minimized.

Copy link

Jubijub commented Jul 4, 2017

Really looking forward to this

@zwpaper

This comment has been minimized.

Copy link

zwpaper commented Jul 5, 2017

@robbyrussell
It have use it for a while, seems not problem for me, my use case:

  1. create a docker with software installed
  2. install oh-my-zsh
  3. copy my .zshrc
  4. start sshd

I use the docker as my dev environment, It's my daily used env, and recreated many times.
you can find my script here:
https://github.com/zwpaper/devdocker/blob/master/env.rc#L7

If you need any other help, I can try my best to help.

@FloopCZ
Copy link

FloopCZ left a comment

One small caveat, otherwise it works well, thanks!

case "$arg" in
--batch)
LAUNCH_ZSH_AFTER=0
printf "${BLUE}--batch:${NORMAL} zsh will not be started after installation\n"

This comment has been minimized.

@FloopCZ

FloopCZ Aug 7, 2017

This breaks when ${BLUE} is an empty string (e.g., Docker environment).
In such a case -- is interpreted as argument separator and the command fails.

Please replace it by the following line to avoid the issue, or just don't write the --batch at the beginning of the string:

        printf "%s\n" "${BLUE}--batch:${NORMAL} zsh will not be started after installation"

FloopCZ added some commits Aug 7, 2017

Fix expr statement with unset $SHELL variable
In the official Ubuntu image from dockerhub, the SHELL variable
is unset. This commit makes the installation script handle it.
@ameykusurkar

This comment has been minimized.

Copy link

ameykusurkar commented Sep 13, 2017

Really looking forward to seeing this getting merged! Would finally allow me to call install.sh in my Makefile without blocking execution

Merge pull request #1 from FloopCZ/feature/batch-mode
Make the batch mode work even in Docker environment
@loket

This comment has been minimized.

Copy link
Author

loket commented Oct 31, 2017

Sorry for taking forever to update the PR! Thanks @FloopCZ, I merged your changes 😄

nicolinuxfr added a commit to nicolinuxfr/config-server that referenced this pull request Dec 21, 2017

@GeorgThomassen

This comment has been minimized.

Copy link

GeorgThomassen commented Mar 9, 2018

Any news regarding non-interactive installs?

@mcornella mcornella added this to TO DO in Installer refactoring via automation Jun 12, 2018

@GerkinDev

This comment has been minimized.

Copy link

GerkinDev commented Jul 30, 2018

Hey there! I need this feature too, pretty badly, because I reinstall oh-my-zsh almost every 2 weeks (thanks to WSL wiped out at every Windows update).

May I help you for anything to see this merged?

Cheers!

@leoj3n

This comment has been minimized.

Copy link
Contributor

leoj3n commented Aug 19, 2018

Instead of a dubiously named flag, another solution might be to close stdin of the "batch" call to install.sh:

0>/dev/null sh -c "$(<install.sh)"

OMZ could then be modified so that it runs "non-interactively" when the STDIN file descriptor is not bound to TTY:

if [ ! -t 0 ] && [ ! -p /dev/stdin ]; then

(more info: file tests)

I imagine this approach would also gracefully handle situations like when commands are sent over ssh with no TTY bound.

@mcornella mcornella moved this from TO DO to In progress in Installer refactoring Aug 20, 2018

@mixn

This comment has been minimized.

Copy link

mixn commented Sep 8, 2018

Any update on this? The current behaviour makes oh-my-zsh installs in dotfiles a real drag. 😢 Would be amazing and thanks to all people involved in advance. 👑

@mcornella mcornella added the install label Sep 8, 2018

@GeorgThomassen

This comment has been minimized.

Copy link

GeorgThomassen commented Sep 8, 2018

@mixn It's possible to make it install without user interaction by removing the lines where it changes the environment

curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -o $DOTFILES/omz.sh
sed -i ''  '/echo/d' $DOTFILES/omz.sh
sed -i ''  '/env zsh/d' $DOTFILES/omz.sh
sh $DOTFILES/omz.sh
rm -rf $DOTFILES/omz.sh

this downloads the file removes all the echo lines, and the env zsh line. This is on OS X hence the empty quotes as the first argument for sed

@mixn

This comment has been minimized.

Copy link

mixn commented Sep 11, 2018

@GeorgThomassen I had something like that in mind, too, but first wanted to see what the current situation on this was. 🙂 Thanks a ton nevertheless, I’ll likely stick with that way of doing it for now. 🙏

@lhorace

This comment has been minimized.

Copy link

lhorace commented Dec 22, 2018

I ran into one issue with this PR, either we sudo chsh -s {$SHELL} in cases where unprivileged user has sudo access with NOPASSWD enabled, or abandon using chsh in batch mode? Running this script hangs Ansible on RHEL where chsh is waiting for password input to change own shell.

@respencer

This comment has been minimized.

Copy link

respencer commented Feb 4, 2019

I've read through this thread, but I'm not clear what the holdup is.

What is needed to get an accepted PR?

@leoj3n

This comment has been minimized.

Copy link
Contributor

leoj3n commented Feb 4, 2019

@respencer I've got a PR (#5320) without conflicts that solves this issue by using the file descriptor close method described above (comment).

However, #5320 needs testers, and nobody has stepped up since it was opened in mid-2016.

@respencer

This comment has been minimized.

Copy link

respencer commented Feb 4, 2019

@respencer I've got a PR (#5320) without conflicts that solves this issue by using the file descriptor close method described above (comment).

However, #5320 needs testers, and nobody has stepped up since it was opened in mid-2016.

Okay, I'm new to this project. I don't know how you work. Can I volunteer for that and what do you need me to do if I can?

No the testing part. The pre and post testing steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment