Page 3 of 7 FirstFirst 12345 ... LastLast
Results 21 to 30 of 65

Thread: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

  1. #21
    Join Date
    Mar 2007
    Location
    Caprica
    Beans
    2,002
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Quote Originally Posted by lisati View Post
    Maybe the pedantic part to my makeup is making a nuisance of itself, but I think what we're talking about here are commands that are useful for recovery, not necessarily codes or other stuff that uses sudo.

    Doesn't have to be a big deal......

    /me wanders off to find something other than terminology to fuss over
    Yes, you're completely right. For me, what I do in large scripts is shell code. Normally I use a structured code, cmd-line args (getopts), functions, arithmetics, local and global variables, loops, if-then-else conditions, etc. Sometimes I call it Bash code, cause I work with Bash specifics, like (("C-like" for loops)), that sometimes are not properly run on Dash, but that's another story. It may require suid or not.

    What Ventrical wants me to do is to cut scripts into smaller command pipes with punctual purposes. It is totally doable. It takes out the logic for <check-if-needed-before-applying> processes and replaces it for a brute-force fix, which also works, in exchange for the possibility to have them in cut&past-able one-liners.

    But, at any rate, the best definition for what will come out of it (if we were to be definition purists) would be something like:

    - CLI-based workaround for system recovery (people seem like the term CLI, to define something that is not GUI - I personally don't.)
    - Shell-based solutions for system recovery (may contain commands and/or script - So it's a "solution")
    - Smashing the Bash for fun and profit
    - Etc.

  2. #22
    Join Date
    Sep 2010
    Location
    Beta Testing in Canada
    Beans
    6,038
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Quote Originally Posted by lisati View Post
    Maybe the pedantic part to my makeup is making a nuisance of itself, but I think what we're talking about here are commands that are useful for recovery, not necessarily codes or other stuff that uses sudo.

    Doesn't have to be a big deal......

    /me wanders off to find something other than terminology to fuss over

    I think that keeping it simple is a good theme and then there are times for more comprehensive code which should be welcomed.

    For example here is a simpler idea:

    ---------------------------------------

    Ubuntu (Precise) has a built it recovery mode at the Grub Bootloader. If you have just installed PP side by side with another system , have no screen or terminal, but have grub then you can choose the Recovery Option from the Grub Bootloader. You will see a lot of top down , verbose code scrolling past and then come up to a Recovery GUI. Here you will be presented with 4 options but the most commonly used for quick recovery (and to get a desktop) is to Resume Normal Boot. These simple tools and commands already built into Ubuntu have worked on several occasions and twice with crashed Precise Installs with systems that I have worked on.
    Attached Images Attached Images
    Last edited by ventrical; November 29th, 2011 at 08:06 PM.

  3. #23
    Join Date
    Sep 2010
    Location
    Beta Testing in Canada
    Beans
    6,038
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Quote Originally Posted by effenberg0x0 View Post
    Yes, you're completely right. For me, what I do in large scripts is shell code. Normally I use a structured code, cmd-line args (getopts), functions, arithmetics, local and global variables, loops, if-then-else conditions, etc. Sometimes I call it Bash code, cause I work with Bash specifics, like (("C-like" for loops)), that sometimes are not properly run on Dash, but that's another story. It may require suid or not.

    What Ventrical wants me to do is to cut scripts into smaller command pipes with punctual purposes. It is totally doable. It takes out the logic for <check-if-needed-before-applying> processes and replaces it for a brute-force fix, which also works, in exchange for the possibility to have them in cut&past-able one-liners.

    But, at any rate, the best definition for what will come out of it (if we were to be definition purists) would be something like:

    - CLI-based workaround for system recovery (people seem like the term CLI, to define something that is not GUI - I personally don't.)
    - Shell-based solutions for system recovery (may contain commands and/or script - So it's a "solution")
    - Smashing the Bash for fun and profit
    - Etc.
    Defintive and comprehensive code is good because it is 'precise' - or it deals precisely with a complex matter. Perhaps most of us with a year or two are still in Linux immersion. We get the drift but are still trying to develop new PC habits that require a different venacular than required by VAXUNIX, Turing, C or BASIC, and yes, even DOS .bat files I mean I can only speak for myself. 25 years as data entry using UNIX and DOS based systems has made it a little tough at times to appreciate the terminal commands presented in Ubuntu/Linux .. but I'm getting there Once a consultant told me over 2 decades ago that I had to learn how to make my computer walk before I could make it dance. This really peeved me off.. but he was right ya know .

  4. #24
    Join Date
    Mar 2007
    Location
    Caprica
    Beans
    2,002
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    An example: This is one of the things I used a lot in General Help and feel like I'm gonna use 10x more now. It allows to:

    - Not rely on any inaccurate information from the user as to whether he has (or not) added PPAs to his install. We just get the PPAs and read them.
    - Than we parse the PPAs (from ppa-file-name.list to PPA:ppaname/package format - which is the format required by the command ppa-purge)

    (this need no suid)
    for PPA_FILE in $(ls /etc/apt/sources.list.d/*); do cat $PPA_FILE | grep "deb http" | sed -e 's|deb http://||' | sed -e 's|.launchpad.net/|\:|' | sed -e 's|/ubuntu||' | sed -e 's|natty||' | sed -e 's|maverick||' | sed -e 's|oneiric||' | sed -e 's|main||' | tee -a /$HOME/ppa-sources.list; done

    (just run the above in a terminal. It won't change anything, I swear :P. It will output your current PPAs, parsed in a more useful form. )

    Now, normally, the rest of the code would present the user with the list of his PPAs on screen and ask him "Remove PPA:Somewhere/Something?" [Y/N], one by one. If I add such a logic in the above code, the thing will become too big and unreadable, not copy&paste friendly. So the alternative would be to drop proper logic and scripting and just go for the bulk-fix tactic, using only a loop to remove everything that is a PPA (non-standard anyway). Ok, then that can be added to the above lines, not increasing the "one-liner" too much...

    (this need suid, because of ppa-purge - don't run this)
    for PPA in $(cat /$HOME/ppa-sources.list); do /usr/sbin/ppa-purge $PPA; done

    What I meant is that it's just a matter of strategy. We can go with bigger shell code, that has more logic, checks and conditions, but will GENERALLY BE MORE COMPLETE AND present friendly options on screen, do backups, allow to revert the changes made, etc, or go for command-pipes that simply do the thing. Either one is valid.


    Food for thought:
    It's PP release week. General Help is on fire.
    You stop, look at the threads, think what you are gonna do.
    IMHO, there's a clear difference between:

    A) Someone whining that Unity doesn't work and that he will migrate to Mint, etc (needs a quick working fix, incapable or learning anything, won't even look at what I tell him to run). They rarely run things you ask them too in a proper order, exactly the way they should, etc. This is like 95% (JUST GUESSING, DON'T ASK ME FOR STATISTICS)
    B) Someone that wants to learn: Will read, Google, browse the forum, probably fix basic things on his own and come with higher-level questions and real problems. These are rare, say 5%.

    This is how I look at it:

    - Individuals of the 'A' type are the majority. We can easily take like 4 or 5 of them simultaneously (selecting opened threads that relate to the same problem) and close them in up to 10 minutes. None of them will ask what sed|awk etc does.

    - Individuals of the 'B' type come with interesting, fun to help issues. This is where I learn and find out interesting things, new bugs, etc. These ones I work on PM, because their threads get destroyed quickly by people that post unrelated issues.

    When we're out of the release-week fever, percentages of A's and B's change to 85%/15%, respectively. So, for any strategy to develop a cut&paste workarounds reference, I would consider this two very different audiences, with an emphasis on A's.

    EDIT: A totally different strategy, for example, would be if we gather our knowledge of current bugs and workarounds and add it to a larger script. This is something that we can do together here as a group over the next months and the final results will be of use to many users when PP is released (the "A's") becoming also a valuable tool to support General Help helpers. Anyone who wants to learn, will have a better chance of doing so by looking at each of the code's functions, seeing our discussion and improvements, etc. We could make it very modular, like 'one function=one bug'. One could copy paste that specific function and apply if he wants to... E.g. funtion fix_ppas {...}. We'd just have to avoid globals and code-reutilization (nested functions). Maybe we could go for a GUI interface (basic stuff, like zenity, etc). It'd be fun to work together with the guys here on that anyway.
    Last edited by effenberg0x0; November 28th, 2011 at 03:26 PM.

  5. #25
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Thank you effenberg0x0 for interesting posts, last but not least the post above mine

  6. #26
    Join Date
    Sep 2010
    Location
    Beta Testing in Canada
    Beans
    6,038
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Here are some common codes of interest to help with Precise recovery in the event of a crash.

    How to find your souces.list- this list is used to set repositories and can be done manually. It is also informative to have on hand if you decide to do a transitional upgrade from Oneiric Ocelot to Precise Pangolin.
    Code:
    /etc/apt/sources.list

    Precise Pangolin will not install: From initial boot screen from LiveCD or LiveUSB you may receive verbose characters or only purple or black screen:
    - check here:
    http://ubuntuforums.org/showpost.php...47&postcount=5

    Your beta version of Firefox is Broken- here are two possible fixes:
    http://ubuntuforums.org/showpost.php...9&postcount=18
    http://ubuntuforums.org/showpost.php...0&postcount=19

    Here is a list of commonly used Ubuntu/Linux terminal Codes (not neccessarily in order and open to interperetation) of PP Crash Recovery Codes -To be updated:

    1. This command is used to auto edit the sources.list file on an install of Oneiric Ocelot and could be considered as a first step to converting to Precise Pangolin. However this and other commands may be moot after Alpha .iso are released. You can still play it safe and test the kernels but breakage may occur nonetheless.
    Code:
    sudo sed -i 's/oneiric/precise/g' /etc/apt/sources.list
    2. This command will update your repositories to PP.
    Code:
    sudo apt-get update && sudo apt-get dist-upgrade
    3.This command is inclusive in #2. but is always good to run after removing or purging stuff.
    Code:
    sudo apt-get update
    4.This command is also included in #2. and upgrades any new files that are set in the repositories.
    Code:
    sudo apt-get upgrade
    4.(a)Update-manager is a fairly important component of the Ubuntu distribution. As we are supposed to be testing during the development phase, this application would be helped by testing and bug reporting as well.You can always make a judgement call as to whether the changes proposed by update-manager seem safe or not. If in doubt I think the best way to proceed is with aptitude:
    Code:
    aptitude update && aptitude safe-upgrade
    This alleviates the concern when packages/dependencies may not be fully synced in the repos. They will be held back until dependencies are satisfied.

    5.This command is an essential command if you are a elementary beta tester as it will upgrade the GRUB bootloader after changes to the system using other commands, are made (like upgrading a kernel). If you have tried to carry out a proceedure and wonder why it had not taken effect on the next boot, it is likely that you did not sudo update-grub.
    Code:
    sudo update-grub
    6.This command will give you simple information about your system, most commonly used to discover your video adapter.
    Code:
    lspci
    7.This command will display version information of the kernel you are using.
    Code:
    uname -a
    8.This command will tell you what Version of Ubuntu you are using. It will help validate and document that the prior commands have worked properly.
    Code:
    lsb_release -a
    9.This command will continue to install packages that may have been broken during download or if your download unexpectedly terminated or if you have had a power-failure.
    Code:
    sudo dpkg -i --configure -a
    10.These two commands can be used separately if you are at the terminal prompt from startup. You can get to the terminal (if you have no desktop) by pressing the keys <Crtl+Alt+F1> It makes booting and restarting quicker and more efficient than if you were in a desktop shell.
    Code:
    sudo reboot -sudo poweroff
    11.One that I have found helpful for fixing broken packages is .
    Code:
    sudo apt-get -f install
    12.Will install any packages necessary to fix the broken package if they are available . If some necessary packages are not available you can use this to remove the broken one .
    Code:
    sudo apt-get -f remove
    13.Do not rely on any inaccurate information from the user as to whether he has (or not) added PPAs to his install. We just get the PPAs and read them. Then we parse the PPAs (from ppa-file-name.list to PPApaname/package format - which is the format required by the command ppa-purge)
    Code:
    if [[ -d /etc/apt/sources.list.d && $(ls -l  /etc/apt/sources.list.d/* | wc -l) -gt 0 ]]; then echo -e "\n\nPPA dir  exists and is not empty\n\n"; for PPA_FILE in $(ls  /etc/apt/sources.list.d/*); do cat ${PPA_FILE} | grep "deb http" | sed  -e 's|deb http:\/\/||' | sed -e 's|.launchpad.net/||' | sed -e  's|/ubuntu||' | sed -e 's|natty||' | sed -e 's|maverick||' | sed -e  's|oneiric||' | sed -e 's|main||' | tee -a $HOME/ppa-sources.list; done;  echo "PPA list saved at $HOME/ppa-sources.list"; else echo -e "\n\nEmpty or inexistent PPA directory\n\n"; fi
    14.Attempts to fix a broken OO Install for NVidia 173 users # Effenberg0x0@Launchpad.net
    Code:
    #!/bin/bash
    ################################################## 
    # fix_oneiric.sh 
    # Attempts to fix a broken OO Install for NVidia 173 users 
    # Effenberg0x0@Launchpad.net 
    # 
    ################################################## 
    # 
    # Save this file to a known location, such as your Home Folder # Execute it with sudo chmod +x fix-oneiric.sh && sudo bash ./fix-oneiric.sh 
    # 
    ################################################## 
    # Assume the env vars we need may be wrong and get them 
    # from safer sources 
    ROOT_PARTITION=$(mount | grep -i "on / type" | awk '{ print $1}') 
    ROOT_FS=$(mount | grep -i "on / type" | awk '{ print $5}') 
    ROOT_WRITE=$(mount | grep -i "on / type" | awk '{ print $6 }') 
    FIX_USER=$(cat /etc/passwd | grep 1000 | awk 'BEGIN { FS=":" }; {print $1}') ################################################## 
    # Checks for a rw filesystem and remounts if needed 
    if [ $ROOT_WRITE == "(ro)" ]; then     
      mount -f -o remount,rw -t $ROOT_FS $ROOT_PARTITION / 
    fi 
    ################################################## 
    # Make sure GUI sessions are stopped 
    service stop lightdm 
    service kill -s KILL $(pidof lightdm) 
    service stop gdm 
    service kill -s KILL $(pidof gdm) 
    killall -s KILL /usr/bin/X  
    ################################################## 
    # Fixes user home permissions and ownership 
    chown $FIX_USER:$FIX_USER /home/$FIX_USER -R && sudo chmod 750 /home/$FIX_USER -R  
    ################################################## 
    # Fixes Xauthority bug 
    mv /home/$FIX_USER/.Xauthority /home/$FIX_USER/.Xauthority.backup
     
    ################################################## 
    # Removes all nvidia remains 
    cd /home/$FIX_USER mkdir nvidia_driver cd nvidia_driver apt-get remove --purge gdm nvidia-173 nvidia-96 nvidia-cg-toolkit nvidia-current-updates nvidia-173-dev nvidia-96-dev nvidia-common nvidia-current-updates-dev nvidia-173-updates nvidia-96-updates nvidia-current nvidia-settings nvidia-173-updates-dev nvidia-96-updates-dev nvidia-current-dev nvidia-settings-updates  
    ################################################## 
    # Downloads nvidia 173 driver  
    wget http://us.download.nvidia.com/XFree86/Linux-x86/173.14.31/NVIDIA-Linux-x86-173.14.31-pkg1.run  
    ################################################## 
    # Exports needed and correct environment variables
    export DISPLAY=:0.0 export XDG_CURRENT_DESKTOP=Unity export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/ export COMPIZ_CONFIG_PROFILE=ubuntu export GDMSESSION=ubuntu export DESKTOP_SESSION=ubuntu export PATH=/home/$USER:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games export XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0 export XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 export DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path ################################################## 
    # Run nvidia installer 
    chmod +x NV* 
    ./NV* 
    ################################################## 
    # Reinstalls all critical DM/DE packages
    apt-get install --reinstall --fix-broken --allow-unauthenticated lightdm lightdm-gtk-greeter unity unity-2d unity-2d-launcher unity-2d-panel unity unity-2d-places unity-greeter unity-lens-music unity-services unity-2d unity-2d-spread unity-lens-applications unity-place-applications unity-2d-launcher unity-asset-pool unity-lens-files unity-place-files unity-2d-panel unity-common unity-lens-gwibber unity-scope-musicstores compiz compiz-dev compiz-kde compiz-plugins-main-default compizconfig-backend-gconf compiz-fusion-bcop compiz-plugins compiz-plugins-main-dev compizconfig-backend-kconfig compiz-fusion-plugins-extra compiz-plugins-default compizconfig-settings-manager compiz-fusion-plugins-main compiz-plugins-extra compiz-core compiz-gnome compiz-plugins-main ################################################## 
    # Makes sure lightdm was not started 
    service lightdm stop 
    ################################################## 
    # Fixes lightm config bug (if needed) 
    if [ ! -f /etc/lightdm/lightdm.conf ]; then sudo touch /etc/lightdm/lightdm.conf echo -e "[SeatDefaults]\r\nuser-session=ubuntu\r\ngreeter-session=unity-greeter" | tee /etc/lightdm/lightdm.conf  
    ################################################## 
    # Fixes default-display-manager bug (if needed) 
    if [ ! -f /etc/X11/default-display-manager ]; then touch /etc/X11/default-display-manager echo -e "/usr/sbin/lightdm" | tee /etc/X11/default-display-manager   ################################################## 
    # Makes sure compiz/compiz-config settings are resetted
    gconftool-2 --recursive-unset /apps/compiz-1 gconftool-2 --recursive-unset /apps/compizconfig-1  
    ################################################## 
    # Backup of compiz/configconfig settings 
    mv $FIX_USER/.config/compiz-1/compizconfig $FIX_USER/.config/compiz-1/compizconfig.old mv $FIX_USER/.config/compiz-1 $FIX_USER/.config/compiz.old mv $FIX_USER/.compiz-1 $FIX_USER/.compiz-1.old mv $FIX_USER/.cache/compizconfig-1 $FIX_USER/.cache/compizconfig-1.old  
    ################################################## 
    # Update/upgrade the system and reboot 
    apt-get update && apt-get upgrade reboot now
    15.Unsolvable weird crash messages at most init procedures, ending in a "black screen" (or a console screen), no DM/DE after many attempts to fix a user setup (video driver, env vars, packages, etc).
    A: Check for missing /run, or lack of permissions to write to it. Happens when users upgrade from old releases (that used /var/run and /var/lock instead of /run and /run/lock). Somehow the new install misses the creation of /run and /run/lock.
    Check/Fix:
    Code:
    if [ ! -d /run -a -d /var ]; then sudo ln -s /var/run /run && sudo mkdir -p /run/lock; fi
    16.Unable to run apt-get. "Archive directory /var/cache/apt/archives/partial is missing"
    Check/Fix:
    Code:
    if [ ! -d /var/cache/apt/archives/partial ]; then sudo mkdir -p /var/cache/apt/archives/partial && sudo touch /var/cache/apt/archives/partial/lock && sudo chmod 640 /var/apt/cache/archives/lock && sudo apt-get clean; fi
    17.System mounted in "Read Only" mode. User is unable to edit config files or install any package, so no one can help him. All requested procedures will fail until it is set rw again. Happens when user has errors=remount-ro in fstab.
    Check/Fix:
    Code:
    if [ $(sudo mount | grep -i "on / type" | awk '{ print $6 }') == "(ro)" ]; then sudo mount -f -o remount,rw -t $(sudo mount | grep -i "on / type" | awk '{ print $5}') $(sudo mount | grep -i "on / type" | awk '{ print $1}') /; fi
    18.Just tried installing Precise for the first time today, using Alpha 1. I have an nvidia gs7600 card.
    Installation went fine but on reboot the system repeatedly hung without booting to the Desktop. The 'nomodeset' option did not help.
    Updating the packages from the recovery mode terminal didn't work either, nor did trying to start lightdm after a terminal log in.
    What finally allowed booting to the Desktop was removing all nvidia packages and then reinstalling nvidia-current (which also installed nvidia-settings).
    Code:
    sudo apt-get purge nvidia*
     sudo apt-get install nvidia-current
    Last edited by ventrical; December 13th, 2011 at 10:56 PM. Reason: correction

  7. #27
    Join Date
    Oct 2005
    Location
    INDY
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Could you Please put these code snippets into code tags!
    They would be much easier to read, cut/paste etc.
    It would separate the explanation and make the presentation much nicer.
    That list just looks awful as it is now...
    Castles Made of Sand,
    Fall in the Sea,
    Eventually!

  8. #28
    Join Date
    Mar 2006
    Location
    Williams Lake
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Quote Originally Posted by arpanaut View Post
    Could you Please put these code snippets into code tags!
    They would be much easier to read, cut/paste etc.
    It would separate the explanation and make the presentation much nicer.
    That list just looks awful as it is now...
    You should have seen it before I removed all the bolding.

  9. #29
    Join Date
    Oct 2005
    Location
    INDY
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    LOL I did, hence my comments.
    Your edit works better, I just prefer code tags for clarity and separation.
    Castles Made of Sand,
    Fall in the Sea,
    Eventually!

  10. #30
    Join Date
    Sep 2010
    Location
    Beta Testing in Canada
    Beans
    6,038
    Distro
    Ubuntu Development Release

    Re: Commonly Used Sudo Code for (*)Ubuntu/Unity Crash Recovery

    Quote Originally Posted by cariboo907 View Post
    You should have seen it before I removed all the bolding.

    You're right .. it is ugly.

    I'll try a different set.

    apologies.

Page 3 of 7 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •